bfd/ 2008-12-22 H.J. Lu PR ld/9676 * elflink.c (elf_link_add_object_symbols): Update def_dynamic, ref_dynamic and dynamic_def fields when setting def_regular to 1. ld/testsuite/ 2008-12-22 H.J. Lu PR ld/9676 * ld-elf/pr9676-1.c: New. * ld-elf/pr9676-2.c: Likewiswe. * ld-elf/pr9676-3.c: Likewiswe. * ld-elf/pr9676-4.c: Likewiswe. * ld-elf/shared.exp (build_tests): Add tests for libpr9676-1.a, libpr9676-2.a, libpr9676-3.so, libpr9676-4.so and libpr9676-4a.so. * lib/ld-lib.exp (ar_simple_create): New. (run_ld_link_tests): Support archive. (run_cc_link_tests): Likewiswe. --- binutils/bfd/elflink.c.hidden 2008-12-22 15:15:00.000000000 -0800 +++ binutils/bfd/elflink.c 2008-12-22 16:05:20.000000000 -0800 @@ -4346,7 +4346,15 @@ elf_link_add_object_symbols (bfd *abfd, h->ref_regular_nonweak = 1; } else - h->def_regular = 1; + { + h->def_regular = 1; + if (h->def_dynamic) + { + h->def_dynamic = 0; + h->ref_dynamic = 1; + h->dynamic_def = 1; + } + } /* If the indirect symbol has been forced local, don't make the real symbol dynamic. */ --- binutils/ld/testsuite/ld-elf/pr9676-1.c.hidden 2008-12-22 16:05:44.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/pr9676-1.c 2008-12-22 15:42:28.000000000 -0800 @@ -0,0 +1,15 @@ +extern int foo (void) __attribute__((section (".gnu.linkonce.t.1"), weak)); + +int +foo (void) +{ + return 1; +} + +extern int foo2 (void); + +int +bar (void) +{ + return foo2 (); +} --- binutils/ld/testsuite/ld-elf/pr9676-2.c.hidden 2008-12-22 16:05:48.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/pr9676-2.c 2008-12-22 15:53:44.000000000 -0800 @@ -0,0 +1,14 @@ +extern int foo (void) __attribute__((section (".gnu.linkonce.t.1"), weak, + __visibility__ ("hidden"))); + +int +foo (void) +{ + return 1; +} + +int +foo2 (void) +{ + return 1; +} --- binutils/ld/testsuite/ld-elf/pr9676-3.c.hidden 2008-12-22 16:05:50.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/pr9676-3.c 2008-12-22 15:54:23.000000000 -0800 @@ -0,0 +1,7 @@ +extern int foo (void) __attribute__((section (".gnu.linkonce.t.1"), weak)); + +int +foo (void) +{ + return 1; +} --- binutils/ld/testsuite/ld-elf/pr9676-4.c.hidden 2008-12-22 16:05:53.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/pr9676-4.c 2008-12-22 15:55:27.000000000 -0800 @@ -0,0 +1,9 @@ +extern int bar (void); +extern int foo (void); + +int +x (void) +{ + foo (); + return bar (); +} --- binutils/ld/testsuite/ld-elf/shared.exp.hidden 2008-09-16 09:16:36.000000000 -0700 +++ binutils/ld/testsuite/ld-elf/shared.exp 2008-12-22 16:03:59.000000000 -0800 @@ -129,6 +129,22 @@ set build_tests { {"Build libfunc1.so" "-shared" "-fPIC" {func1.c} {} "libfunc1.so"} + {"Build libpr9676-1.a" + "" "-fPIC" + {pr9676-1.c} {} "libpr9676-1.a"} + {"Build libpr9676-2.a" + "" "-fPIC" + {pr9676-2.c} {} "libpr9676-2.a"} + {"Build libpr9676-3.so" + "-shared" "-fPIC" + {pr9676-3.c} {} "libpr9676-3.so"} + {"Build libpr9676-4.so" + "-shared" "-fPIC" + {pr9676-4.c} {} "libpr9676-4.so"} + {"Build libpr9676-4a.so" + "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group" + "-fPIC" + {dummy.c} {} "libpr9676-4a.so"} } set run_tests { --- binutils/ld/testsuite/lib/ld-lib.exp.hidden 2008-09-29 09:44:11.000000000 -0700 +++ binutils/ld/testsuite/lib/ld-lib.exp 2008-12-22 15:53:19.000000000 -0800 @@ -1089,6 +1089,22 @@ proc file_contents { filename } { return $contents } +# Create an archive using ar +# +proc ar_simple_create { ar target objects } { + remote_file host delete $target + + set exec_output [run_host_cmd "$ar" "rc $target $objects"] + set exec_output [prune_warnings $exec_output] + + if [string match "" $exec_output] then { + send_log "$exec_output\n" + return 1 + } else { + return 0 + } +} + # List contains test-items with 3 items followed by 2 lists, one item and # one optional item: # 0:name 1:ld options 2:assembler options @@ -1104,6 +1120,7 @@ proc run_ld_link_tests { ldtests } { global ld global as global nm + global ar global objdump global READELF global srcdir @@ -1157,10 +1174,21 @@ proc run_ld_link_tests { ldtests } { continue } - if ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] { + if [regexp ".*a$" $binfile] then { + if ![ar_simple_create $ar $binfile "$objfiles"] { + fail $testname + set failed 1 + } else { + set failed 0 + } + } elseif ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] { fail $testname + set failed 1 } else { set failed 0 + } + + if { $failed == 0 } { foreach actionlist $actions { set action [lindex $actionlist 0] set progopts [lindex $actionlist 1] @@ -1425,6 +1453,7 @@ proc run_cc_link_tests { ldtests } { global CXX global CFLAGS global CXXFLAGS + global ar foreach testitem $ldtests { set testname [lindex $testitem 0] @@ -1462,10 +1491,21 @@ proc run_cc_link_tests { ldtests } { set cc_cmd $CC } - if ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] { + if [regexp ".*a$" $binfile] then { + if ![ar_simple_create $ar $binfile "$objfiles"] { + fail $testname + set failed 1 + } else { + set failed 0 + } + } elseif ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] { fail $testname + set failed 1 } else { set failed 0 + } + + if { $failed == 0 } { foreach actionlist $actions { set action [lindex $actionlist 0] set progopts [lindex $actionlist 1]