| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #include <stdbool.h> |
| 8 | #include "b.h" |
| 9 | #include "tap.h" |
| 10 | |
| 11 | #define NUM_TESTS 2 |
| 12 | |
| 13 | int testint __attribute__((weak, visibility("hidden"))); |
| 14 | void *testptr __attribute__((weak, visibility("hidden"))); |
| 15 | struct { |
| 16 | char a[24]; |
| 17 | } testsym_24_bytes __attribute__((weak, visibility("hidden"))); |
| 18 | |
| 19 | void *testfct_int(void); |
| 20 | void *testfct_ptr(void); |
| 21 | void *testfct_24_bytes(void); |
| 22 | |
| 23 | void *testlibfct1_int(void); |
| 24 | void *testlibfct1_ptr(void); |
| 25 | void *testlibfct1_24_bytes(void); |
| 26 | |
| 27 | void *testlibfct2_int(void); |
| 28 | void *testlibfct2_ptr(void); |
| 29 | void *testlibfct2_24_bytes(void); |
| 30 | |
| 31 | enum { |
| 32 | MATCH_PROGRAM_INT, |
| 33 | MATCH_PROGRAM_PTR, |
| 34 | MATCH_PROGRAM_24_BYTES, |
| 35 | MATCH_LIB_INT, |
| 36 | MATCH_LIB_PTR, |
| 37 | MATCH_LIB_24_BYTES, |
| 38 | NR_MATCH, |
| 39 | }; |
| 40 | |
| 41 | static bool match_matrix[NR_MATCH]; |
| 42 | |
| 43 | int main(void) |
| 44 | { |
| 45 | plan_tests(NUM_TESTS); |
| 46 | |
| 47 | if (testfct_int() == &testint) |
| 48 | match_matrix[MATCH_PROGRAM_INT] = true; |
| 49 | if (testfct_ptr() == &testptr) |
| 50 | match_matrix[MATCH_PROGRAM_PTR] = true; |
| 51 | if (testfct_24_bytes() == &testsym_24_bytes) |
| 52 | match_matrix[MATCH_PROGRAM_24_BYTES] = true; |
| 53 | |
| 54 | if (testlibfct1_int() == testlibfct2_int()) |
| 55 | match_matrix[MATCH_LIB_INT] = true; |
| 56 | if (testlibfct1_ptr() == testlibfct2_ptr()) |
| 57 | match_matrix[MATCH_LIB_PTR] = true; |
| 58 | if (testlibfct1_24_bytes() == testlibfct2_24_bytes()) |
| 59 | match_matrix[MATCH_LIB_24_BYTES] = true; |
| 60 | |
| 61 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (4 bytes integer object)", |
| 62 | match_matrix[MATCH_PROGRAM_INT] ? "match" : "MISMATCH"); |
| 63 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (pointer object)", |
| 64 | match_matrix[MATCH_PROGRAM_PTR] ? "match" : "MISMATCH"); |
| 65 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (24 bytes structure object)", |
| 66 | match_matrix[MATCH_PROGRAM_24_BYTES] ? "match" : "MISMATCH"); |
| 67 | |
| 68 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (4 bytes integer object)", |
| 69 | match_matrix[MATCH_LIB_INT] ? "match" : "MISMATCH"); |
| 70 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (pointer object)", |
| 71 | match_matrix[MATCH_LIB_PTR] ? "match" : "MISMATCH"); |
| 72 | diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (24 bytes structure object)", |
| 73 | match_matrix[MATCH_LIB_24_BYTES] ? "match" : "MISMATCH"); |
| 74 | |
| 75 | ok(match_matrix[MATCH_PROGRAM_INT] == match_matrix[MATCH_PROGRAM_PTR], |
| 76 | "Weak-hidden behavior is the same for 4 bytes integer and pointer objects within main program"); |
| 77 | ok(match_matrix[MATCH_LIB_INT] == match_matrix[MATCH_LIB_PTR], |
| 78 | "Weak-hidden behavior is the same for 4 bytes integer and pointer objects within shared library"); |
| 79 | |
| 80 | return exit_status(); |
| 81 | } |