This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Test for ODR-detector with mixed weak and strong symbols


I was gearing up to change gold to ignore mixed weak and strong
definitions of C symbols, when I discovered that it already does that.
Here's the test anyway.

2010-07-22  Jeffrey Yasskin  <jyasskin@google.com>

	* testsuite/debug_msg.sh: Test mixed weak/strong symbol behavior.
? odr_mixed_weak_test.patch
? sample_object_for_odr.patch
Index: gold/testsuite/debug_msg.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/debug_msg.cc,v
retrieving revision 1.3
diff -u -r1.3 debug_msg.cc
--- gold/testsuite/debug_msg.cc	13 Mar 2008 21:04:21 -0000	1.3
+++ gold/testsuite/debug_msg.cc	22 Jul 2010 22:21:04 -0000
@@ -59,6 +59,13 @@
 void SortAscending(int array[], int size);   // in odr_violation1.cc
 void SortDescending(int array[], int size);  // in odr_violation2.cc
 
+extern "C" int OverriddenCFunction(int i);  // in odr_violation*.cc
+
+inline int SometimesInlineFunction(int i) {  // strong in odr_violation2.cc.
+  return i;
+}
+
+
 int main()
 {
   testfn(5);
@@ -75,5 +82,8 @@
   int kSize2 = sizeof(kInput2) / sizeof(int);
   SortDescending(kInput2, kSize2);
 
+  OverriddenCFunction(3);
+  SometimesInlineFunction(3);
+
   return 0;
 }
Index: gold/testsuite/debug_msg.sh
===================================================================
RCS file: /cvs/src/src/gold/testsuite/debug_msg.sh,v
retrieving revision 1.9
diff -u -r1.9 debug_msg.sh
--- gold/testsuite/debug_msg.sh	27 Feb 2010 00:46:00 -0000	1.9
+++ gold/testsuite/debug_msg.sh	22 Jul 2010 22:21:04 -0000
@@ -75,6 +75,16 @@
 check debug_msg.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
 check debug_msg.err "odr_violation1.cc:5"
 check debug_msg.err "odr_violation2.cc:5"
+# We block ODR detection for combinations of C weak and strong
+# symbols, to allow people to use the linker to override things.  We
+# still flag it for C++ symbols since those are more likely to be
+# unintentional.
+check_missing debug_msg.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
+check_missing debug_msg.err "odr_violation1.cc:15"
+check_missing debug_msg.err "odr_violation2.cc:17"
+check debug_msg.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
+check debug_msg.err "debug_msg.cc:64"
+check debug_msg.err "odr_violation2.cc:21"
 
 # When linking together .so's, we don't catch the line numbers, but we
 # still find all the undefined variables, and the ODR violation.
@@ -84,6 +94,12 @@
 check debug_msg_so.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
 check debug_msg_so.err "odr_violation1.cc:5"
 check debug_msg_so.err "odr_violation2.cc:5"
+check_missing debug_msg.err ": symbol 'OverriddenCFunction' defined in multiple places (possible ODR violation):"
+check_missing debug_msg.err "odr_violation1.cc:15"
+check_missing debug_msg.err "odr_violation2.cc:17"
+check debug_msg.err ": symbol 'SometimesInlineFunction(int)' defined in multiple places (possible ODR violation):"
+check debug_msg.err "debug_msg.cc:64"
+check debug_msg.err "odr_violation2.cc:21"
 
 # These messages shouldn't need any debug info to detect:
 check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_fn1()'"
Index: gold/testsuite/odr_violation1.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/odr_violation1.cc,v
retrieving revision 1.1
diff -u -r1.1 odr_violation1.cc
--- gold/testsuite/odr_violation1.cc	14 Nov 2007 01:03:01 -0000	1.1
+++ gold/testsuite/odr_violation1.cc	22 Jul 2010 22:21:04 -0000
@@ -10,3 +10,8 @@
 void SortAscending(int array[], int size) {
   std::sort(array, array + size, Ordering());
 }
+
+extern "C" int OverriddenCFunction(int i) __attribute__ ((weak));
+extern "C" int OverriddenCFunction(int i) {
+  return i;
+}
Index: gold/testsuite/odr_violation2.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/odr_violation2.cc,v
retrieving revision 1.1
diff -u -r1.1 odr_violation2.cc
--- gold/testsuite/odr_violation2.cc	14 Nov 2007 01:03:01 -0000	1.1
+++ gold/testsuite/odr_violation2.cc	22 Jul 2010 22:21:04 -0000
@@ -12,3 +12,12 @@
 void SortDescending(int array[], int size) {
   std::sort(array, array + size, Ordering());
 }
+
+// This is weak in odr_violation1.cc.
+extern "C" int OverriddenCFunction(int i) {
+  return i * i;
+}
+// This is inline in debug_msg.cc, which makes it a weak symbol too.
+int SometimesInlineFunction(int i) {
+  return i * i;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]