| 1 | /* |
| 2 | * Copyright (C) 2016 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 3 | * |
| 4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
| 5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
| 6 | * |
| 7 | * Permission is hereby granted to use or copy this program for any |
| 8 | * purpose, provided the above notices are retained on all copies. |
| 9 | * Permission to modify the code and to distribute modified code is |
| 10 | * granted, provided the above notices are retained, and a notice that |
| 11 | * the code was modified is included with the above copyright notice. |
| 12 | */ |
| 13 | |
| 14 | #include <stdbool.h> |
| 15 | #include "tap.h" |
| 16 | |
| 17 | #define NUM_TESTS 2 |
| 18 | |
| 19 | int testint __attribute__((weak, visibility("hidden"))); |
| 20 | void *testptr __attribute__((weak, visibility("hidden"))); |
| 21 | struct { |
| 22 | char a[24]; |
| 23 | } testsym_24_bytes __attribute__((weak, visibility("hidden"))); |
| 24 | |
| 25 | void *testfct_int(void); |
| 26 | void *testfct_ptr(void); |
| 27 | void *testfct_24_bytes(void); |
| 28 | |
| 29 | void *testlibfct1_int(void); |
| 30 | void *testlibfct1_ptr(void); |
| 31 | void *testlibfct1_24_bytes(void); |
| 32 | |
| 33 | void *testlibfct2_int(void); |
| 34 | void *testlibfct2_ptr(void); |
| 35 | void *testlibfct2_24_bytes(void); |
| 36 | |
| 37 | enum { |
| 38 | MATCH_PROGRAM_INT, |
| 39 | MATCH_PROGRAM_PTR, |
| 40 | MATCH_PROGRAM_24_BYTES, |
| 41 | MATCH_LIB_INT, |
| 42 | MATCH_LIB_PTR, |
| 43 | MATCH_LIB_24_BYTES, |
| 44 | NR_MATCH, |
| 45 | }; |
| 46 | |
| 47 | static bool match_matrix[NR_MATCH]; |
| 48 | |
| 49 | int main() |
| 50 | { |
| 51 | plan_tests(NUM_TESTS); |
| 52 | |
| 53 | if (testfct_int() == &testint) |
| 54 | match_matrix[MATCH_PROGRAM_INT] = true; |
| 55 | if (testfct_ptr() == &testptr) |
| 56 | match_matrix[MATCH_PROGRAM_PTR] = true; |
| 57 | if (testfct_24_bytes() == &testsym_24_bytes) |
| 58 | match_matrix[MATCH_PROGRAM_24_BYTES] = true; |
| 59 | |
| 60 | if (testlibfct1_int() == testlibfct2_int()) |
| 61 | match_matrix[MATCH_LIB_INT] = true; |
| 62 | if (testlibfct1_ptr() == testlibfct2_ptr()) |
| 63 | match_matrix[MATCH_LIB_PTR] = true; |
| 64 | if (testlibfct1_24_bytes() == testlibfct2_24_bytes()) |
| 65 | match_matrix[MATCH_LIB_24_BYTES] = true; |
| 66 | |
| 67 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (4 bytes integer object)", |
| 68 | match_matrix[MATCH_PROGRAM_INT] ? "match" : "MISMATCH"); |
| 69 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (pointer object)", |
| 70 | match_matrix[MATCH_PROGRAM_PTR] ? "match" : "MISMATCH"); |
| 71 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (24 bytes structure object)", |
| 72 | match_matrix[MATCH_PROGRAM_24_BYTES] ? "match" : "MISMATCH"); |
| 73 | |
| 74 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (4 bytes integer object)", |
| 75 | match_matrix[MATCH_LIB_INT] ? "match" : "MISMATCH"); |
| 76 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (pointer object)", |
| 77 | match_matrix[MATCH_LIB_PTR] ? "match" : "MISMATCH"); |
| 78 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (24 bytes structure object)", |
| 79 | match_matrix[MATCH_LIB_24_BYTES] ? "match" : "MISMATCH"); |
| 80 | |
| 81 | ok(match_matrix[MATCH_PROGRAM_INT] == match_matrix[MATCH_PROGRAM_PTR], |
| 82 | "Weak-hidden behavior is the same for 4 bytes integer and pointer objects within main program"); |
| 83 | ok(match_matrix[MATCH_LIB_INT] == match_matrix[MATCH_LIB_PTR], |
| 84 | "Weak-hidden behavior is the same for 4 bytes integer and pointer objects within shared library"); |
| 85 | return 0; |
| 86 | } |