1 ## DP: Description: http://sourceware.org/ml/binutils/2010-09/msg00216.html
3 2010-09-15 Maciej W. Rozycki <macro@codesourcery.com>
8 * elfxx-mips.c (_bfd_mips_elf_check_relocs)
9 [R_MIPS_32, R_MIPS_REL32, R_MIPS_64]: Ignore relocs from
10 SEC_DEBUGGING sections.
13 * lib/ld-lib.exp (run_ld_link_tests): Handle sources from other
15 (run_ld_link_exec_tests): Likewise.
16 (run_cc_link_tests): Likewise.
17 * ld-elf/comm-data1.sd: New test.
18 * ld-elf/comm-data1.s: Source for the new test.
19 * ld-elf/comm-data2.sd: New test.
20 * ld-elf/comm-data2.rd: Likewise.
21 * ld-elf/comm-data2.xd: Likewise.
22 * ld-elf/comm-data2.s: Source for the new tests.
23 * ld-elf/comm-data.exp: Run the new tests.
24 * ld-mips-elf/comm-data.exp: Likewise.
27 +++ b/ld/testsuite/ld-elf/comm-data1.s
29 + .section .rodata,"a",%progbits
36 +++ b/ld/testsuite/ld-elf/comm-data2.xd
38 +Hex dump of section '\.debug_foo':
39 + +0x0+ +00000000 00000000 00000000 00000000 +\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
41 +++ b/ld/testsuite/ld-elf/comm-data2.s
49 + .section .debug_foo,"",%progbits
58 +++ b/ld/testsuite/ld-elf/comm-data.exp
60 +# Expect script for common symbol override.
62 +# Copyright 2010 Free Software Foundation, Inc.
64 +# This file is part of the GNU Binutils.
66 +# This program is free software; you can redistribute it and/or modify
67 +# it under the terms of the GNU General Public License as published by
68 +# the Free Software Foundation; either version 3 of the License, or
69 +# (at your option) any later version.
71 +# This program is distributed in the hope that it will be useful,
72 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
73 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74 +# GNU General Public License for more details.
76 +# You should have received a copy of the GNU General Public License
77 +# along with this program; if not, write to the Free Software
78 +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
79 +# MA 02110-1301, USA.
83 +# Written by Maciej W. Rozycki <macro@codesourcery.com>
86 +# Exclude non-ELF targets.
87 +if ![is_elf_format] {
91 +# Exclude non-Linux targets; feel free to include your favourite one
93 +if ![istarget *-*-linux*] {
97 +set testname "Common symbol override test"
99 +# Define a global symbol.
100 +run_ld_link_tests [list \
102 + "$testname (auxiliary shared object build)" \
107 + { readelf -s comm-data1.sd } \
109 + "libcomm-data.so" \
113 +# Set the pointer size according to the ELF flavour.
115 +if [is_elf64 "tmpdir/libcomm-data.so"] {
116 + append AFLAGS " --defsym ELF64=1"
119 +# Verify that a common symbol has been converted to an undefined
120 +# reference to the global symbol of the same name defined above
121 +# and that the debug reference has been dropped.
122 +run_ld_link_tests [list \
125 + "-Ltmpdir -lcomm-data" \
129 + { readelf -s comm-data2.sd } \
130 + { readelf -r comm-data2.rd } \
131 + { readelf "-x .debug_foo" comm-data2.xd } \
137 +++ b/ld/testsuite/ld-elf/comm-data1.sd
139 +Symbol table '\.dynsym' contains [0-9]+ entries:
140 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
142 + +[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +foo
144 +Symbol table '\.symtab' contains [0-9]+ entries:
145 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
147 + +[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +foo
150 +++ b/ld/testsuite/ld-elf/comm-data2.rd
152 +There are no relocations in this file\.
154 +++ b/ld/testsuite/ld-elf/comm-data2.sd
156 +Symbol table '\.dynsym' contains [0-9]+ entries:
157 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
159 + +[0-9]+: +0+ +0 +OBJECT +GLOBAL +DEFAULT +UND +foo
161 +Symbol table '\.symtab' contains [0-9]+ entries:
162 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
164 + +[0-9]+: +0+ +0 +OBJECT +GLOBAL +DEFAULT +UND +foo
166 --- a/ld/testsuite/lib/ld-lib.exp
167 +++ b/ld/testsuite/lib/ld-lib.exp
168 @@ -1252,11 +1252,12 @@
170 # Assemble each file in the test.
171 foreach src_file $src_files {
172 - set objfile "tmpdir/[file rootname $src_file].o"
173 + set fileroot "[file rootname [file tail $src_file]]"
174 + set objfile "tmpdir/$fileroot.o"
175 lappend objfiles $objfile
177 if { [file extension $src_file] == ".c" } {
178 - set as_file "tmpdir/[file rootname $src_file].s"
179 + set as_file "tmpdir/$fileroot.s"
180 if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] {
183 @@ -1446,7 +1447,8 @@
185 # Assemble each file in the test.
186 foreach src_file $src_files {
187 - set objfile "tmpdir/[file rootname $src_file].o"
188 + set fileroot "[file rootname [file tail $src_file]]"
189 + set objfile "tmpdir/$fileroot.o"
190 lappend objfiles $objfile
192 # We ignore warnings since some compilers may generate
193 @@ -1565,7 +1567,8 @@
195 # Compile each file in the test.
196 foreach src_file $src_files {
197 - set objfile "tmpdir/[file rootname $src_file].o"
198 + set fileroot "[file rootname [file tail $src_file]]"
199 + set objfile "tmpdir/$fileroot.o"
200 lappend objfiles $objfile
202 # We ignore warnings since some compilers may generate
204 +++ b/ld/testsuite/ld-mips-elf/comm-data.exp
206 +# Expect script for common symbol override, MIPS variation.
208 +# Copyright 2010 Free Software Foundation, Inc.
210 +# This file is part of the GNU Binutils.
212 +# This program is free software; you can redistribute it and/or modify
213 +# it under the terms of the GNU General Public License as published by
214 +# the Free Software Foundation; either version 3 of the License, or
215 +# (at your option) any later version.
217 +# This program is distributed in the hope that it will be useful,
218 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
219 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
220 +# GNU General Public License for more details.
222 +# You should have received a copy of the GNU General Public License
223 +# along with this program; if not, write to the Free Software
224 +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
225 +# MA 02110-1301, USA.
229 +# Written by Maciej W. Rozycki <macro@codesourcery.com>
232 +# Exclude non-ELF targets.
233 +if ![is_elf_format] {
237 +# Exclude non-Linux targets; feel free to include your favourite one
239 +if ![istarget mips*-*-linux*] {
243 +proc mips_comm_data_test { abi flag emul reloc } {
245 + set testname "MIPS $abi/$reloc common symbol override test"
246 + set AFLAGS "$flag -EB"
247 + set LDFLAGS "-m$emul"
249 + # Define a global symbol.
250 + run_ld_link_tests [list \
252 + "$testname (auxiliary shared object build)" \
253 + "$LDFLAGS -shared" \
254 + "$AFLAGS -call_shared" \
255 + { ../ld-elf/comm-data1.s } \
257 + { readelf -s ../ld-elf/comm-data1.sd } \
259 + "libmips-$abi-$reloc-comm-data.so" \
263 + # Set the pointer size according to the ABI.
264 + if { $abi == "n64" } {
265 + append AFLAGS " --defsym ELF64=1"
268 + # Verify that a common symbol has been converted to an undefined
269 + # reference to the global symbol of the same name defined above
270 + # and that the debug reference has been dropped.
271 + run_ld_link_tests [list \
274 + "$LDFLAGS -z $reloc -Ltmpdir -lmips-$abi-$reloc-comm-data" \
275 + "$AFLAGS -call_nonpic" \
276 + { ../ld-elf/comm-data2.s } \
278 + { readelf -s ../ld-elf/comm-data2.sd } \
279 + { readelf -r ../ld-elf/comm-data2.rd } \
280 + { readelf "-x .debug_foo" ../ld-elf/comm-data2.xd } \
282 + "mips-$abi-$reloc-comm-data" \
287 +set abis { o32 -32 elf32btsmip n32 -n32 elf32btsmipn32 n64 -64 elf64btsmip }
288 +set relocs { copyreloc nocopyreloc }
289 +foreach { abi flag emul } $abis {
290 + foreach reloc $relocs {
291 + mips_comm_data_test $abi $flag $emul $reloc
294 --- a/bfd/elfxx-mips.c
295 +++ b/bfd/elfxx-mips.c
296 @@ -7583,6 +7583,19 @@
297 elf_hash_table (info)->dynobj = dynobj = abfd;
300 + /* Ignore relocs from SEC_DEBUGGING sections because such
301 + sections are not SEC_ALLOC and thus ld.so will not process
302 + them. Don't set has_static_relocs for the corresponding
305 + This is needed in cases such as a global symbol definition
306 + in a shared library causing a common symbol from an object
307 + file to be converted to an undefined reference. If that
308 + happens, then all the relocations against this symbol from
309 + SEC_DEBUGGING sections in the object file will resolve to
311 + if ((sec->flags & SEC_DEBUGGING) != 0)