Fix: test weak-hidden symbols
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 22 May 2016 15:26:00 +0000 (11:26 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 22 May 2016 15:30:17 +0000 (11:30 -0400)
On many architectures (arm32, arm64, powerpc64) gcc chooses to assign
different addresses to weak-hidden symbols from different compile units
within the same module.

This is unfortunate, but still OK with respect to tracepoints.

The real issue is on 32-bit powerpc, where gcc (in O1 or more) assigns
different addresses only for objects larger than 8 bytes, but same
addresses for objects of 8 bytes or less (int and pointers).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/gcc-weak-hidden/b.c
tests/gcc-weak-hidden/c.c
tests/gcc-weak-hidden/d.c
tests/gcc-weak-hidden/main.c

index 2419ed9f01d6025884e8ba1e46c4ca2750c8a1e4..218a154537a3e4b60b65bee3ac20787ae05909b4 100644 (file)
@@ -1,6 +1,20 @@
-char testsym[9] __attribute__((weak, visibility("hidden")));
+int testint __attribute__((weak, visibility("hidden")));
+void *testptr __attribute__((weak, visibility("hidden")));
+struct {
+       char a[24];
+} testsym_24_bytes __attribute__((weak, visibility("hidden")));
 
-void *fct1(void)
+void *testfct_int(void)
 {
-       return testsym;
+       return &testint;
+}
+
+void *testfct_ptr(void)
+{
+       return &testptr;
+}
+
+void *testfct_24_bytes(void)
+{
+       return &testsym_24_bytes;
 }
index 59f9046d9295f1b493393f57c98bde228a72be37..1a744e29feda691995db3ad64808064d53fb1486 100644 (file)
@@ -1,6 +1,20 @@
-char testsym[9] __attribute__((weak, visibility("hidden")));
+int testint __attribute__((weak, visibility("hidden")));
+void *testptr __attribute__((weak, visibility("hidden")));
+struct {
+       char a[24];
+} testsym_24_bytes __attribute__((weak, visibility("hidden")));
 
-void *fctlib1(void)
+void *testlibfct1_int(void)
 {
-       return testsym;
+       return &testint;
+}
+
+void *testlibfct1_ptr(void)
+{
+       return &testptr;
+}
+
+void *testlibfct1_24_bytes(void)
+{
+       return &testsym_24_bytes;
 }
index bb16bdb3cad8ed4e6e503a1deb15a6b17dbd7d0f..05e10b4e11f607fc15bf46068ed32c1624738d82 100644 (file)
@@ -1,6 +1,20 @@
-char testsym[9] __attribute__((weak, visibility("hidden")));
+int testint __attribute__((weak, visibility("hidden")));
+void *testptr __attribute__((weak, visibility("hidden")));
+struct {
+       char a[24];
+} testsym_24_bytes __attribute__((weak, visibility("hidden")));
 
-void *fctlib2(void)
+void *testlibfct2_int(void)
 {
-       return testsym;
+       return &testint;
+}
+
+void *testlibfct2_ptr(void)
+{
+       return &testptr;
+}
+
+void *testlibfct2_24_bytes(void)
+{
+       return &testsym_24_bytes;
 }
index a2f31756f41560db3d1783ffdb5c94586252ed67..b4542f79a67e4cb5f23668d9e540eb7abe337454 100644 (file)
  * granted, provided the above notices are retained, and a notice that
  * the code was modified is included with the above copyright notice.
  */
+
+#include <stdbool.h>
 #include "tap.h"
 
 #define NUM_TESTS 2
 
-char testsym[9] __attribute__((weak, visibility("hidden")));
+int testint __attribute__((weak, visibility("hidden")));
+void *testptr __attribute__((weak, visibility("hidden")));
+struct {
+       char a[24];
+} testsym_24_bytes __attribute__((weak, visibility("hidden")));
+
+void *testfct_int(void);
+void *testfct_ptr(void);
+void *testfct_24_bytes(void);
+
+void *testlibfct1_int(void);
+void *testlibfct1_ptr(void);
+void *testlibfct1_24_bytes(void);
+
+void *testlibfct2_int(void);
+void *testlibfct2_ptr(void);
+void *testlibfct2_24_bytes(void);
+
+enum {
+       MATCH_PROGRAM_INT,
+       MATCH_PROGRAM_PTR,
+       MATCH_PROGRAM_24_BYTES,
+       MATCH_LIB_INT,
+       MATCH_LIB_PTR,
+       MATCH_LIB_24_BYTES,
+       NR_MATCH,
+};
 
-void *fct1(void);
-void *fctlib1(void);
-void *fctlib2(void);
+static bool match_matrix[NR_MATCH];
 
 int main()
 {
        plan_tests(NUM_TESTS);
-       ok(fct1() == testsym,
-               "Address of weak symbol with hidden visibility match between compile units within same module for main program");
-       ok(fctlib1() == fctlib2(),
-               "Address of weak symbol with hidden visibility match between compile units within same module for shared library");
+
+       if (testfct_int() == &testint)
+               match_matrix[MATCH_PROGRAM_INT] = true;
+       if (testfct_ptr() == &testptr)
+               match_matrix[MATCH_PROGRAM_PTR] = true;
+       if (testfct_24_bytes() == &testsym_24_bytes)
+               match_matrix[MATCH_PROGRAM_24_BYTES] = true;
+
+       if (testlibfct1_int() == testlibfct2_int())
+               match_matrix[MATCH_LIB_INT] = true;
+       if (testlibfct1_ptr() == testlibfct2_ptr())
+               match_matrix[MATCH_LIB_PTR] = true;
+       if (testlibfct1_24_bytes() == testlibfct2_24_bytes())
+               match_matrix[MATCH_LIB_24_BYTES] = true;
+
+       diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (4 bytes integer object)",
+               match_matrix[MATCH_PROGRAM_INT] ? "match" : "MISMATCH");
+       diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (pointer object)",
+               match_matrix[MATCH_PROGRAM_PTR] ? "match" : "MISMATCH");
+       diag("Address of weak symbol with hidden visibility %s between compile units within same module for main program (24 bytes structure object)",
+               match_matrix[MATCH_PROGRAM_24_BYTES] ? "match" : "MISMATCH");
+
+       diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (4 bytes integer object)",
+               match_matrix[MATCH_LIB_INT] ? "match" : "MISMATCH");
+       diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (pointer object)",
+               match_matrix[MATCH_LIB_PTR] ? "match" : "MISMATCH");
+       diag("Address of weak symbol with hidden visibility %s between compile units within same module for shared library (24 bytes structure object)",
+               match_matrix[MATCH_LIB_24_BYTES] ? "match" : "MISMATCH");
+
+       ok(match_matrix[MATCH_PROGRAM_INT] == match_matrix[MATCH_PROGRAM_PTR]
+                       && match_matrix[MATCH_PROGRAM_INT] == match_matrix[MATCH_PROGRAM_24_BYTES],
+               "Weak-hidden behavior is the same for 4 bytes integer, pointer, and 24 bytes structure objects for within main program");
+       ok(match_matrix[MATCH_LIB_INT] == match_matrix[MATCH_LIB_PTR]
+                       && match_matrix[MATCH_LIB_INT] == match_matrix[MATCH_LIB_24_BYTES],
+               "Weak-hidden behavior is the same for 4 bytes integer, pointer, and 24 bytes structure objects for within shared library");
        return 0;
 }
This page took 0.027603 seconds and 4 git commands to generate.