diff options
author | Ian Lance Taylor <ian@airs.com> | 2011-03-10 01:31:33 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2011-03-10 01:31:33 +0000 |
commit | 71ff89863ff23a581a1578755785e6b39dd209f2 (patch) | |
tree | b5aab2587b661dc64d6117602ecb030274857c93 /gold/testsuite | |
parent | a19fefdc57f5eafcb682175f2b2bcd8f6f366c90 (diff) | |
download | gdb-71ff89863ff23a581a1578755785e6b39dd209f2.zip gdb-71ff89863ff23a581a1578755785e6b39dd209f2.tar.gz gdb-71ff89863ff23a581a1578755785e6b39dd209f2.tar.bz2 |
* dwarf_reader.cc (Sized_dwarf_line_info): Include all lines,
but mark earlier ones as non-canonical
(offset_to_iterator): Update search target and example
(do_addr2line): Return extra lines in a vector*
(format_file_lineno): Extract from do_addr2line
(one_addr2line): Add vector* out-param
* dwarf_reader.h (Offset_to_lineno_entry): New field recording
when a lineno entry appeared last for its instruction
(Dwarf_line_info): Add vector* out-param
* object.cc (Relocate_info): Pass NULL for the vector* out-param
* symtab.cc (Odr_violation_compare): Include the lineno in the
comparison again.
(linenos_from_loc): New. Combine the canonical line for an
address with its other lines.
(True_if_intersect): New. Helper functor to make
std::set_intersection a query.
(detect_odr_violations): Compare sets of lines instead of just
one line for each function. This became less deterministic, but
has fewer false positives.
* symtab.h: Declarations.
* testsuite/Makefile.am (odr_violation2.o): Compile with -O2 to
mix an optimized and non-optimized object in the same binary
(odr_violation2.so): Same.
* testsuite/Makefile.in: Regenerate from Makefile.am.
* testsuite/debug_msg.cc (main): Make OdrDerived classes.
* testsuite/debug_msg.sh: Update line numbers and add
assertions.
* testsuite/odr_violation1.cc: Use OdrDerived, in a
non-optimized context.
* testsuite/odr_violation2.cc: Make sure Ordering::operator()
isn't inlined, and use OdrDerived in an optimized context.
* testsuite/odr_header1.h: Defines OdrDerived, where
optimization will change the
first-instruction-in-the-destructor's file and line number.
* testsuite/odr_header2.h: Defines OdrBase.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 8 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 8 | ||||
-rw-r--r-- | gold/testsuite/debug_msg.cc | 7 | ||||
-rwxr-xr-x | gold/testsuite/debug_msg.sh | 30 | ||||
-rw-r--r-- | gold/testsuite/odr_header1.h | 6 | ||||
-rw-r--r-- | gold/testsuite/odr_header2.h | 4 | ||||
-rw-r--r-- | gold/testsuite/odr_violation1.cc | 6 | ||||
-rw-r--r-- | gold/testsuite/odr_violation2.cc | 16 |
8 files changed, 63 insertions, 22 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 53e6660..5ccd397 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -849,8 +849,10 @@ debug_msg.o: debug_msg.cc $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/debug_msg.cc odr_violation1.o: odr_violation1.cc $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation1.cc +# Compile with different optimization flags to check that rearranged +# instructions don't cause a false positive. odr_violation2.o: odr_violation2.cc - $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation2.cc + $(CXXCOMPILE) -O2 -g -c -w -o $@ $(srcdir)/odr_violation2.cc debug_msg.err: debug_msg.o odr_violation1.o odr_violation2.o gcctestdir/ld @echo $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg debug_msg.o odr_violation1.o odr_violation2.o "2>$@" @if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg debug_msg.o odr_violation1.o odr_violation2.o 2>$@; \ @@ -868,7 +870,7 @@ debug_msg.so: debug_msg.cc gcctestdir/ld odr_violation1.so: odr_violation1.cc gcctestdir/ld $(CXXCOMPILE) -Bgcctestdir/ -O0 -g -shared -fPIC -w -o $@ $(srcdir)/odr_violation1.cc odr_violation2.so: odr_violation2.cc gcctestdir/ld - $(CXXCOMPILE) -Bgcctestdir/ -O0 -g -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc + $(CXXCOMPILE) -Bgcctestdir/ -O2 -g -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc debug_msg_so.err: debug_msg.so odr_violation1.so odr_violation2.so gcctestdir/ld @echo $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_so debug_msg.so odr_violation1.so odr_violation2.so "2>$@" @if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_so debug_msg.so odr_violation1.so odr_violation2.so 2>$@; \ @@ -887,7 +889,7 @@ debug_msg_ndebug.so: debug_msg.cc gcctestdir/ld odr_violation1_ndebug.so: odr_violation1.cc gcctestdir/ld $(CXXCOMPILE) -Bgcctestdir/ -O0 -g0 -shared -fPIC -w -o $@ $(srcdir)/odr_violation1.cc odr_violation2_ndebug.so: odr_violation2.cc gcctestdir/ld - $(CXXCOMPILE) -Bgcctestdir/ -O0 -g0 -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc + $(CXXCOMPILE) -Bgcctestdir/ -O2 -g0 -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc debug_msg_ndebug.err: debug_msg_ndebug.so odr_violation1_ndebug.so odr_violation2_ndebug.so gcctestdir/ld @echo $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_ndebug debug_msg_ndebug.so odr_violation1_ndebug.so odr_violation2_ndebug.so "2>$@" @if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_ndebug debug_msg_ndebug.so odr_violation1_ndebug.so odr_violation2_ndebug.so 2>$@; \ diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 6d9bb7a..f7489ea 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -4017,8 +4017,10 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/debug_msg.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@odr_violation1.o: odr_violation1.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation1.cc +# Compile with different optimization flags to check that rearranged +# instructions don't cause a false positive. @GCC_TRUE@@NATIVE_LINKER_TRUE@odr_violation2.o: odr_violation2.cc -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -g -c -w -o $@ $(srcdir)/odr_violation2.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O2 -g -c -w -o $@ $(srcdir)/odr_violation2.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@debug_msg.err: debug_msg.o odr_violation1.o odr_violation2.o gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@ @echo $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg debug_msg.o odr_violation1.o odr_violation2.o "2>$@" @GCC_TRUE@@NATIVE_LINKER_TRUE@ @if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg debug_msg.o odr_violation1.o odr_violation2.o 2>$@; \ @@ -4032,7 +4034,7 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@odr_violation1.so: odr_violation1.cc gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -Bgcctestdir/ -O0 -g -shared -fPIC -w -o $@ $(srcdir)/odr_violation1.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@odr_violation2.so: odr_violation2.cc gcctestdir/ld -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -Bgcctestdir/ -O0 -g -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -Bgcctestdir/ -O2 -g -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@debug_msg_so.err: debug_msg.so odr_violation1.so odr_violation2.so gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@ @echo $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_so debug_msg.so odr_violation1.so odr_violation2.so "2>$@" @GCC_TRUE@@NATIVE_LINKER_TRUE@ @if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_so debug_msg.so odr_violation1.so odr_violation2.so 2>$@; \ @@ -4046,7 +4048,7 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@odr_violation1_ndebug.so: odr_violation1.cc gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -Bgcctestdir/ -O0 -g0 -shared -fPIC -w -o $@ $(srcdir)/odr_violation1.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@odr_violation2_ndebug.so: odr_violation2.cc gcctestdir/ld -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -Bgcctestdir/ -O0 -g0 -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -Bgcctestdir/ -O2 -g0 -shared -fPIC -w -o $@ $(srcdir)/odr_violation2.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@debug_msg_ndebug.err: debug_msg_ndebug.so odr_violation1_ndebug.so odr_violation2_ndebug.so gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@ @echo $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_ndebug debug_msg_ndebug.so odr_violation1_ndebug.so odr_violation2_ndebug.so "2>$@" @GCC_TRUE@@NATIVE_LINKER_TRUE@ @if $(CXXLINK) -Bgcctestdir/ -Wl,--detect-odr-violations -o debug_msg_ndebug debug_msg_ndebug.so odr_violation1_ndebug.so odr_violation2_ndebug.so 2>$@; \ diff --git a/gold/testsuite/debug_msg.cc b/gold/testsuite/debug_msg.cc index 1d77bc9..0912002 100644 --- a/gold/testsuite/debug_msg.cc +++ b/gold/testsuite/debug_msg.cc @@ -58,6 +58,10 @@ class Derived : public Base // This tests One Definition Rule (ODR) violations. void SortAscending(int array[], int size); // in odr_violation1.cc void SortDescending(int array[], int size); // in odr_violation2.cc +// This tests One Definition Rule (ODR) non-violations. +#include "odr_header2.h" +OdrBase* CreateOdrDerived1(); // in odr_violation1.cc +OdrBase* CreateOdrDerived2(); // in odr_violation2.cc extern "C" int OverriddenCFunction(int i); // in odr_violation*.cc @@ -85,5 +89,8 @@ int main() OverriddenCFunction(3); SometimesInlineFunction(3); + delete CreateOdrDerived1(); + delete CreateOdrDerived2(); + return 0; } diff --git a/gold/testsuite/debug_msg.sh b/gold/testsuite/debug_msg.sh index 74b4b05..b8624e7 100755 --- a/gold/testsuite/debug_msg.sh +++ b/gold/testsuite/debug_msg.sh @@ -73,18 +73,22 @@ check debug_msg.err "debug_msg.o: in function int testfn<double>(double):.*/debu # Check we detected the ODR (One Definition Rule) violation. 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" +check debug_msg.err "odr_violation1.cc:6" +check debug_msg.err "odr_violation2.cc:9" + +# Check we don't have ODR false positives: +check_missing debug_msg.err "OdrDerived::~OdrDerived()" +check_missing debug_msg.err "__adjust_heap" # 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_missing debug_msg.err "odr_violation1.cc:16" +check_missing debug_msg.err "odr_violation2.cc:20" 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" +check debug_msg.err "debug_msg.cc:68" +check debug_msg.err "odr_violation2.cc:24" # When linking together .so's, we don't catch the line numbers, but we # still find all the undefined variables, and the ODR violation. @@ -92,14 +96,16 @@ check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn1() check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn2()'" check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_int'" 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 debug_msg_so.err "odr_violation1.cc:6" +check debug_msg_so.err "odr_violation2.cc:9" +check_missing debug_msg.err "OdrDerived::~OdrDerived()" +check_missing debug_msg.err "__adjust_heap" 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_missing debug_msg.err "odr_violation1.cc:16" +check_missing debug_msg.err "odr_violation2.cc:20" 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" +check debug_msg.err "debug_msg.cc:68" +check debug_msg.err "odr_violation2.cc:24" # 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()'" diff --git a/gold/testsuite/odr_header1.h b/gold/testsuite/odr_header1.h new file mode 100644 index 0000000..3d9c488 --- /dev/null +++ b/gold/testsuite/odr_header1.h @@ -0,0 +1,6 @@ +#include "odr_header2.h" + +struct OdrDerived : OdrBase { + ~OdrDerived() { + } +}; diff --git a/gold/testsuite/odr_header2.h b/gold/testsuite/odr_header2.h new file mode 100644 index 0000000..0fb9449 --- /dev/null +++ b/gold/testsuite/odr_header2.h @@ -0,0 +1,4 @@ +struct OdrBase { + virtual ~OdrBase() { + } +}; diff --git a/gold/testsuite/odr_violation1.cc b/gold/testsuite/odr_violation1.cc index 6c40496..8b37cea 100644 --- a/gold/testsuite/odr_violation1.cc +++ b/gold/testsuite/odr_violation1.cc @@ -1,4 +1,5 @@ #include <algorithm> +#include "odr_header1.h" class Ordering { public: @@ -15,3 +16,8 @@ extern "C" int OverriddenCFunction(int i) __attribute__ ((weak)); extern "C" int OverriddenCFunction(int i) { return i; } + +// Instantiate the Derived vtable, without optimization. +OdrBase* CreateOdrDerived1() { + return new OdrDerived; +} diff --git a/gold/testsuite/odr_violation2.cc b/gold/testsuite/odr_violation2.cc index 09940d4..6c57b6f 100644 --- a/gold/testsuite/odr_violation2.cc +++ b/gold/testsuite/odr_violation2.cc @@ -1,13 +1,16 @@ #include <algorithm> +#include "odr_header1.h" class Ordering { public: - bool operator()(int a, int b) { - // We need the "+ 1" here to force this operator() to be a - // different size than the one in odr_violation1.cc. + bool operator()(int a, int b) __attribute__((never_inline)); +}; + +bool Ordering::operator()(int a, int b) { + // Optimization makes this operator() a different size than the one + // in odr_violation1.cc. return a + 1 > b + 1; } -}; void SortDescending(int array[], int size) { std::sort(array, array + size, Ordering()); @@ -21,3 +24,8 @@ extern "C" int OverriddenCFunction(int i) { int SometimesInlineFunction(int i) { return i * i; } + +// Instantiate the Derived vtable, with optimization (see Makefile.am). +OdrBase* CreateOdrDerived2() { + return new OdrDerived; +} |