From c5d37467b152fe98f02ac1ff8188e32ecd0def95 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 17 Apr 2017 18:33:52 +0930 Subject: Undo dynamic symbol state after regular object sym type mismatch We already handle the case of an object file first defining a symbol that a later shared library also defines where the symbol types are incompatible. This patch handles the reverse, when a later object file defines an incompatible symbol defined by an earlier shared library. bfd/ * elflink.c (_bfd_elf_merge_symbol): Undo dynamic linking state when a regular object file defines a symbol with incompatible type to that defined by an earlier shared lib. ld/ * testsuite/ld-elf/indirect5a.c, * testsuite/ld-elf/indirect5b.c, * testsuite/ld-elf/indirect5.map, * testsuite/ld-elf/indirect5.out: New test. * testsuite/ld-elf/indirect6a.c: Likewise. * testsuite/ld-elf/indirect.exp (check_dynamic_syms): New proc. Run new tests and check dynsyms. --- ld/testsuite/ld-elf/indirect.exp | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'ld/testsuite/ld-elf/indirect.exp') diff --git a/ld/testsuite/ld-elf/indirect.exp b/ld/testsuite/ld-elf/indirect.exp index 5c5382ccd2b..128d4a788fd 100644 --- a/ld/testsuite/ld-elf/indirect.exp +++ b/ld/testsuite/ld-elf/indirect.exp @@ -85,6 +85,9 @@ set build_tests { {"Build libindirect4c.so" "-shared" "-fPIC" {indirect4c.c} {} "libindirect4c.so"} + {"Build libindirect5.so" + "-shared -Wl,--version-script=indirect5.map" "-fPIC" + {indirect5b.c} {} "libindirect5.so"} {"Build libpr18720c.so" "-shared" "-fPIC" {pr18720c.c} {} "libpr18720c.so"} @@ -151,6 +154,18 @@ set run_tests { {"Run with libindirect4c.so 4" "-Wl,--no-as-needed tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" "" {dummy.c} "indirect4d" "indirect4.out"} + {"Run indirect5 1" + "-Wl,--no-as-needed tmpdir/libindirect5.so" "" + {indirect5a.c} "indirect5a" "indirect5.out"} + {"Run indirect5 2" + "-Wl,--no-as-needed tmpdir/indirect5a.o tmpdir/libindirect5.so" "" + {dummy.c} "indirect5b" "indirect5.out"} + {"Run indirect6 1" + "-Wl,--no-as-needed tmpdir/libindirect5.so" "" + {indirect6a.c} "indirect6a" "indirect5.out"} + {"Run indirect6 2" + "-Wl,--no-as-needed tmpdir/indirect6a.o tmpdir/libindirect5.so" "" + {dummy.c} "indirect6b" "indirect5.out"} {"Run with libpr18720c.so 1" "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" "" {check-ptr-eq.c} "pr18720a" "pr18720.out"} @@ -178,3 +193,62 @@ set run_tests { } run_ld_link_exec_tests $run_tests + +# Check that "bar" is not dynamic in the executable +proc check_dynamic_syms { test } { + global nm + set cmd "$nm -D $test > dump.out" + send_log "$cmd\n" + catch "exec $cmd" comp_output + if ![string match "" $comp_output] then { + send_log "$comp_output\n" + return 0 + } + if { [string match "* bar\n*" [file_contents "dump.out"]] } then { + verbose "output is [file_contents "dump.out"]" + return 0 + } + return 1 +} + +foreach t [list indirect5a indirect5b indirect6a indirect6b] { + set testname [concat $t "dynsym"] + if { [check_dynamic_syms tmpdir/$t] } { + pass $testname + } else { + fail $testname + } +} + +send_log "$CC -fPIE -pie $srcdir/$subdir/main.c -o tmpdir/pie" +catch "exec $CC -fPIE -pie $srcdir/$subdir/main.c -o tmpdir/pie" exec_output +send_log "$exec_output" +if { ! [string match "" $exec_output] } { + return +} + +set pie_tests { + {"Run indirect5 3" + "-pie -Wl,--no-as-needed tmpdir/libindirect5.so" "" + {indirect5a.c} "indirect5c" "indirect5.out" "-fPIE"} + {"Run indirect5 4" + "-pie -Wl,--no-as-needed tmpdir/indirect5a.o tmpdir/libindirect5.so" "" + {dummy.c} "indirect5d" "indirect5.out" "-fPIE"} + {"Run indirect6 3" + "-pie -Wl,--no-as-needed tmpdir/libindirect5.so" "" + {indirect6a.c} "indirect6c" "indirect5.out" "-fPIE"} + {"Run indirect6 4" + "-pie -Wl,--no-as-needed tmpdir/indirect6a.o tmpdir/libindirect5.so" "-fPIE" + {dummy.c} "indirect6d" "indirect5.out" "-fPIE"} +} + +run_ld_link_exec_tests $pie_tests + +foreach t [list indirect5c indirect5d indirect6c indirect6d] { + set testname [concat $t "dynsym"] + if { [check_dynamic_syms tmpdir/$t] } { + pass $testname + } else { + fail $testname + } +} -- cgit v1.2.1