Upload Tizen:Base source
[external/binutils.git] / packaging / 156_pr10144.patch
1 ## DP: Description: http://sourceware.org/ml/binutils/2010-09/msg00216.html 
2
3 2010-09-15  Maciej W. Rozycki  <macro@codesourcery.com>
4
5         PR ld/10144
6
7         bfd/
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.
11
12         ld/testsuite/
13         * lib/ld-lib.exp (run_ld_link_tests): Handle sources from other
14         directories.
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.
25
26 --- /dev/null
27 +++ b/ld/testsuite/ld-elf/comm-data1.s
28 @@ -0,0 +1,6 @@
29 +       .section .rodata,"a",%progbits
30 +       .balign 8
31 +       .globl  foo
32 +       .type   foo,%object
33 +foo:
34 +       .skip   4, 0
35 --- /dev/null
36 +++ b/ld/testsuite/ld-elf/comm-data2.xd
37 @@ -0,0 +1,2 @@
38 +Hex dump of section '\.debug_foo':
39 + +0x0+ +00000000 00000000 00000000 00000000 +\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
40 --- /dev/null
41 +++ b/ld/testsuite/ld-elf/comm-data2.s
42 @@ -0,0 +1,14 @@
43 +       .text
44 +       .globl  _start
45 +       .globl  __start
46 +_start:
47 +__start:
48 +       .comm   foo, 4, 4
49 +       .section .debug_foo,"",%progbits
50 +       .balign 16
51 +       .ifdef  ELF64
52 +       .8byte  foo
53 +       .else
54 +       .4byte  foo
55 +       .endif
56 +       .balign 16
57 --- /dev/null
58 +++ b/ld/testsuite/ld-elf/comm-data.exp
59 @@ -0,0 +1,76 @@
60 +# Expect script for common symbol override.
61 +#
62 +#   Copyright 2010  Free Software Foundation, Inc.
63 +#
64 +# This file is part of the GNU Binutils.
65 +#
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.
70 +#
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.
75 +#
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.
80 +#
81 +
82 +#
83 +# Written by Maciej W. Rozycki <macro@codesourcery.com>
84 +#
85 +
86 +# Exclude non-ELF targets.
87 +if ![is_elf_format] {
88 +    return
89 +}
90 +
91 +# Exclude non-Linux targets; feel free to include your favourite one
92 +# if you like.
93 +if ![istarget *-*-linux*] {
94 +    return
95 +}
96 +
97 +set testname "Common symbol override test"
98 +
99 +# Define a global symbol.
100 +run_ld_link_tests [list \
101 +    [list \
102 +       "$testname (auxiliary shared object build)" \
103 +       "-shared" \
104 +       "" \
105 +       { comm-data1.s } \
106 +       { \
107 +           { readelf -s comm-data1.sd } \
108 +       } \
109 +       "libcomm-data.so" \
110 +    ] \
111 +]
112 +
113 +# Set the pointer size according to the ELF flavour.
114 +set AFLAGS ""
115 +if [is_elf64 "tmpdir/libcomm-data.so"] {
116 +    append AFLAGS " --defsym ELF64=1"
117 +}
118 +
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 \
123 +    [list \
124 +       "$testname" \
125 +       "-Ltmpdir -lcomm-data" \
126 +       "$AFLAGS" \
127 +       { comm-data2.s } \
128 +       { \
129 +           { readelf -s comm-data2.sd } \
130 +           { readelf -r comm-data2.rd } \
131 +           { readelf "-x .debug_foo" comm-data2.xd } \
132 +       } \
133 +       "comm-data" \
134 +    ] \
135 +]
136 --- /dev/null
137 +++ b/ld/testsuite/ld-elf/comm-data1.sd
138 @@ -0,0 +1,10 @@
139 +Symbol table '\.dynsym' contains [0-9]+ entries:
140 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
141 +#...
142 + +[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +foo
143 +#...
144 +Symbol table '\.symtab' contains [0-9]+ entries:
145 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
146 +#...
147 + +[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +foo
148 +#pass
149 --- /dev/null
150 +++ b/ld/testsuite/ld-elf/comm-data2.rd
151 @@ -0,0 +1 @@
152 +There are no relocations in this file\.
153 --- /dev/null
154 +++ b/ld/testsuite/ld-elf/comm-data2.sd
155 @@ -0,0 +1,10 @@
156 +Symbol table '\.dynsym' contains [0-9]+ entries:
157 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
158 +#...
159 + +[0-9]+: +0+ +0 +OBJECT +GLOBAL +DEFAULT +UND +foo
160 +#...
161 +Symbol table '\.symtab' contains [0-9]+ entries:
162 + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
163 +#...
164 + +[0-9]+: +0+ +0 +OBJECT +GLOBAL +DEFAULT +UND +foo
165 +#pass
166 --- a/ld/testsuite/lib/ld-lib.exp
167 +++ b/ld/testsuite/lib/ld-lib.exp
168 @@ -1252,11 +1252,12 @@
169  
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
176  
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] {
181                     set is_unresolved 1
182                     break
183 @@ -1446,7 +1447,8 @@
184  
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
191  
192             # We ignore warnings since some compilers may generate
193 @@ -1565,7 +1567,8 @@
194  
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
201  
202             # We ignore warnings since some compilers may generate
203 --- /dev/null
204 +++ b/ld/testsuite/ld-mips-elf/comm-data.exp
205 @@ -0,0 +1,88 @@
206 +# Expect script for common symbol override, MIPS variation.
207 +#
208 +#   Copyright 2010  Free Software Foundation, Inc.
209 +#
210 +# This file is part of the GNU Binutils.
211 +#
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.
216 +#
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.
221 +#
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.
226 +#
227 +
228 +#
229 +# Written by Maciej W. Rozycki <macro@codesourcery.com>
230 +#
231 +
232 +# Exclude non-ELF targets.
233 +if ![is_elf_format] {
234 +    return
235 +}
236 +
237 +# Exclude non-Linux targets; feel free to include your favourite one
238 +# if you like.
239 +if ![istarget mips*-*-linux*] {
240 +    return
241 +}
242 +
243 +proc mips_comm_data_test { abi flag emul reloc } {
244 +
245 +    set testname "MIPS $abi/$reloc common symbol override test"
246 +    set AFLAGS "$flag -EB"
247 +    set LDFLAGS "-m$emul"
248 +
249 +    # Define a global symbol.
250 +    run_ld_link_tests [list \
251 +       [list \
252 +           "$testname (auxiliary shared object build)" \
253 +           "$LDFLAGS -shared" \
254 +           "$AFLAGS -call_shared" \
255 +           { ../ld-elf/comm-data1.s } \
256 +           { \
257 +               { readelf -s ../ld-elf/comm-data1.sd } \
258 +           } \
259 +         "libmips-$abi-$reloc-comm-data.so" \
260 +       ] \
261 +    ]
262 +
263 +    # Set the pointer size according to the ABI.
264 +    if { $abi == "n64" } {
265 +       append AFLAGS " --defsym ELF64=1"
266 +    }
267 +
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 \
272 +       [list \
273 +           "$testname" \
274 +           "$LDFLAGS -z $reloc -Ltmpdir -lmips-$abi-$reloc-comm-data" \
275 +           "$AFLAGS -call_nonpic" \
276 +           { ../ld-elf/comm-data2.s } \
277 +           { \
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 } \
281 +           } \
282 +           "mips-$abi-$reloc-comm-data" \
283 +       ] \
284 +    ]
285 +}
286 +
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
292 +    }
293 +}
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;
298               break;
299             }
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
303 +            symbol.
304 +
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
310 +            nil.  */
311 +         if ((sec->flags & SEC_DEBUGGING) != 0)
312 +           break;
313           /* Fall through.  */
314  
315         default: