1 2008-03-16 H.J. Lu <hongjiu.lu@intel.com>
5 * elf32-i386.c (elf_i386_relocate_section): Issue an error
6 for R_386_GOTOFF relocaton against undefined hidden/internal
7 symbols when building a shared object.
9 * elf64-x86-64.c (elf64_x86_64_relocate_section): Issue an
10 error for R_X86_64_PC8/R_X86_64_PC16/R_X86_64_PC32
11 relocaton against undefined hidden/internal symbols when
12 building a shared object.
13 (elf64_x86_64_finish_dynamic_symbol): Return FALSE when symbol
14 is referenced locally, but isn't defined in a regular file.
18 2008-03-16 H.J. Lu <hongjiu.lu@intel.com>
22 * ld-i386/hidden1.d: New.
23 * ld-i386/hidden1.s: Likewise.
24 * ld-i386/hidden2.d: Likewise.
25 * ld-i386/hidden2.s: Likewise.
26 * ld-i386/hidden3.d: Likewise.
27 * ld-i386/hidden4.s: Likewise.
28 * ld-i386/protected1.d: Likewise.
29 * ld-i386/protected1.s: Likewise.
30 * ld-i386/protected2.d: Likewise.
31 * ld-i386/protected2.s: Likewise.
32 * ld-i386/protected3.d: Likewise.
33 * ld-i386/protected3.s: Likewise.
34 * ld-x86-64/hidden1.d: Likewise.
35 * ld-x86-64/hidden1.s: Likewise.
36 * ld-x86-64/hidden2.d: Likewise.
37 * ld-x86-64/hidden2.s: Likewise.
38 * ld-x86-64/hidden3.d: Likewise.
39 * ld-x86-64/hidden3.s: Likewise.
40 * ld-x86-64/protected1.d: Likewise.
41 * ld-x86-64/protected1.s: Likewise.
42 * ld-x86-64/protected2.d: Likewise.
43 * ld-x86-64/protected2.s: Likewise.
44 * ld-x86-64/protected3.d: Likewise.
45 * ld-x86-64/protected3.s: Likewise.
47 * ld-i386/i386.exp: Run hidden1, hidden2, hidden3, protected1,
48 protected2 and protected3.
49 * ld-x86-64/x86-64.exp: Likewise.
51 --- binutils/bfd/elf32-i386.c.bad 2008-03-15 07:28:10.000000000 -0700
52 +++ binutils/bfd/elf32-i386.c 2008-03-16 09:54:26.000000000 -0700
53 @@ -2773,19 +2773,46 @@ elf_i386_relocate_section (bfd *output_b
55 /* Check to make sure it isn't a protected function symbol
56 for shared library since it may not be local when used
57 - as function address. */
59 - && !info->executable
62 - && h->type == STT_FUNC
63 - && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
64 + as function address. We also need to make sure that a
65 + symbol is defined locally. */
66 + if (info->shared && h)
68 - (*_bfd_error_handler)
69 - (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
70 - input_bfd, h->root.root.string);
71 - bfd_set_error (bfd_error_bad_value);
73 + if (!h->def_regular)
77 + switch (ELF_ST_VISIBILITY (h->other))
80 + v = _("hidden symbol");
83 + v = _("internal symbol");
86 + v = _("protected symbol");
93 + (*_bfd_error_handler)
94 + (_("%B: relocation R_386_GOTOFF against undefined %s `%s' can not be used when making a shared object"),
95 + input_bfd, v, h->root.root.string);
96 + bfd_set_error (bfd_error_bad_value);
99 + else if (!info->executable
100 + && h->type == STT_FUNC
101 + && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
103 + (*_bfd_error_handler)
104 + (_("%B: relocation R_386_GOTOFF against protected function `%s' can not be used when making a shared object"),
105 + input_bfd, h->root.root.string);
106 + bfd_set_error (bfd_error_bad_value);
111 /* Note that sgot is not involved in this
112 --- binutils/bfd/elf64-x86-64.c.bad 2008-03-15 07:28:10.000000000 -0700
113 +++ binutils/bfd/elf64-x86-64.c 2008-03-16 09:53:21.000000000 -0700
114 @@ -2615,30 +2615,63 @@ elf64_x86_64_relocate_section (bfd *outp
118 - && !SYMBOL_REFERENCES_LOCAL (info, h)
119 && (input_section->flags & SEC_ALLOC) != 0
120 && (input_section->flags & SEC_READONLY) != 0
121 - && (!h->def_regular
122 - || r_type != R_X86_64_PC32
123 - || h->type != STT_FUNC
124 - || ELF_ST_VISIBILITY (h->other) != STV_PROTECTED
125 - || !is_32bit_relative_branch (contents,
130 - && r_type == R_X86_64_PC32
131 - && h->type == STT_FUNC
132 - && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
133 - (*_bfd_error_handler)
134 - (_("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object"),
135 - input_bfd, h->root.root.string);
136 + bfd_boolean fail = FALSE;
138 + = (r_type == R_X86_64_PC32
139 + && is_32bit_relative_branch (contents, rel->r_offset));
141 + if (SYMBOL_REFERENCES_LOCAL (info, h))
143 + /* Symbol is referenced locally. Make sure it is
144 + defined locally or for a branch. */
145 + fail = !h->def_regular && !branch;
148 - (*_bfd_error_handler)
149 - (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
150 - input_bfd, x86_64_elf_howto_table[r_type].name,
151 - h->root.root.string);
152 - bfd_set_error (bfd_error_bad_value);
155 + /* Symbol isn't referenced locally. We only allow
156 + branch to symbol with non-default visibility. */
158 + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
165 + const char *pic = "";
167 + switch (ELF_ST_VISIBILITY (h->other))
170 + v = _("hidden symbol");
173 + v = _("internal symbol");
175 + case STV_PROTECTED:
176 + v = _("protected symbol");
180 + pic = _("; recompile with -fPIC");
184 + if (h->def_regular)
185 + fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
187 + fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
189 + (*_bfd_error_handler) (fmt, input_bfd,
190 + x86_64_elf_howto_table[r_type].name,
191 + v, h->root.root.string, pic);
192 + bfd_set_error (bfd_error_bad_value);
198 @@ -3363,6 +3396,8 @@ elf64_x86_64_finish_dynamic_symbol (bfd
200 && SYMBOL_REFERENCES_LOCAL (info, h))
202 + if (!h->def_regular)
204 BFD_ASSERT((h->got.offset & 1) != 0);
205 rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
206 rela.r_addend = (h->root.u.def.value
207 --- binutils/ld/testsuite/ld-i386/hidden1.d.bad 2008-03-16 09:29:54.000000000 -0700
208 +++ binutils/ld/testsuite/ld-i386/hidden1.d 2008-03-16 09:21:52.000000000 -0700
211 +#ld: -shared -melf_i386
212 +#error: .*relocation R_386_GOTOFF against undefined hidden symbol `foo' can not be used when making a shared object
213 --- binutils/ld/testsuite/ld-i386/hidden1.s.bad 2008-03-16 09:29:54.000000000 -0700
214 +++ binutils/ld/testsuite/ld-i386/hidden1.s 2008-03-16 09:15:16.000000000 -0700
218 + .type bar, @function
220 + leal foo@GOTOFF(%ecx), %eax
225 --- binutils/ld/testsuite/ld-i386/hidden2.d.bad 2008-03-16 09:29:54.000000000 -0700
226 +++ binutils/ld/testsuite/ld-i386/hidden2.d 2008-03-16 09:24:45.000000000 -0700
229 +#ld: -shared -melf_i386
235 +Disassembly of section .text:
238 +[ ]*[a-f0-9]+: e8 cf fe ff ff call 0 <bar-0x[a-f0-9]+>
239 +[ ]*[a-f0-9]+: c3 ret
241 --- binutils/ld/testsuite/ld-i386/hidden2.s.bad 2008-03-16 09:29:54.000000000 -0700
242 +++ binutils/ld/testsuite/ld-i386/hidden2.s 2008-03-16 09:15:28.000000000 -0700
246 + .type bar, @function
253 --- binutils/ld/testsuite/ld-i386/hidden3.d.bad 2008-03-16 09:29:54.000000000 -0700
254 +++ binutils/ld/testsuite/ld-i386/hidden3.d 2008-03-16 09:22:31.000000000 -0700
257 +#ld: -shared -melf_i386
258 +#error: .*relocation R_386_GOTOFF against undefined hidden symbol `foo' can not be used when making a shared object
259 --- binutils/ld/testsuite/ld-i386/hidden3.s.bad 2008-03-16 09:29:54.000000000 -0700
260 +++ binutils/ld/testsuite/ld-i386/hidden3.s 2008-03-16 09:15:44.000000000 -0700
264 + .type bar, @function
266 + leal foo@GOTOFF(%ecx), %eax
270 --- binutils/ld/testsuite/ld-i386/i386.exp.bad 2007-08-25 07:35:38.000000000 -0700
271 +++ binutils/ld/testsuite/ld-i386/i386.exp 2008-03-16 09:29:49.000000000 -0700
272 @@ -132,3 +132,9 @@ run_dump_test "tlsie2"
273 run_dump_test "tlsie3"
274 run_dump_test "tlsie4"
275 run_dump_test "tlsie5"
276 +run_dump_test "hidden1"
277 +run_dump_test "hidden2"
278 +run_dump_test "hidden3"
279 +run_dump_test "protected1"
280 +run_dump_test "protected2"
281 +run_dump_test "protected3"
282 --- binutils/ld/testsuite/ld-i386/protected1.d.bad 2008-03-16 09:29:54.000000000 -0700
283 +++ binutils/ld/testsuite/ld-i386/protected1.d 2008-03-16 09:25:29.000000000 -0700
286 +#ld: -shared -melf_i386
287 +#error: .*relocation R_386_GOTOFF against protected function `foo' can not be used when making a shared object
288 --- binutils/ld/testsuite/ld-i386/protected1.s.bad 2008-03-16 09:29:54.000000000 -0700
289 +++ binutils/ld/testsuite/ld-i386/protected1.s 2008-03-16 09:16:13.000000000 -0700
294 + .type foo, @function
299 + .type bar, @function
301 + leal foo@GOTOFF(%ecx), %eax
304 --- binutils/ld/testsuite/ld-i386/protected2.d.bad 2008-03-16 09:29:54.000000000 -0700
305 +++ binutils/ld/testsuite/ld-i386/protected2.d 2008-03-16 09:25:50.000000000 -0700
308 +#ld: -shared -melf_i386
314 +Disassembly of section .text:
317 +[ ]*[a-f0-9]+: c3 ret
320 +[ ]*[a-f0-9]+: e8 fa ff ff ff call [a-f0-9]+ <foo>
321 +[ ]*[a-f0-9]+: c3 ret
323 --- binutils/ld/testsuite/ld-i386/protected2.s.bad 2008-03-16 09:29:54.000000000 -0700
324 +++ binutils/ld/testsuite/ld-i386/protected2.s 2008-03-16 09:16:23.000000000 -0700
329 + .type foo, @function
334 + .type bar, @function
339 --- binutils/ld/testsuite/ld-i386/protected3.d.bad 2008-03-16 09:29:54.000000000 -0700
340 +++ binutils/ld/testsuite/ld-i386/protected3.d 2008-03-16 09:27:44.000000000 -0700
343 +#ld: -shared -melf_i386
349 +Disassembly of section .text:
352 +[ ]*[a-f0-9]+: 8b 81 0c 00 00 00 mov 0x[a-f0-9]+\(%ecx\),%eax
353 +[ ]*[a-f0-9]+: c3 ret
355 --- binutils/ld/testsuite/ld-i386/protected3.s.bad 2008-03-16 09:29:54.000000000 -0700
356 +++ binutils/ld/testsuite/ld-i386/protected3.s 2008-03-16 09:23:40.000000000 -0700
368 + .type bar, @function
370 + movl foo@GOTOFF(%ecx), %eax
373 --- binutils/ld/testsuite/ld-x86-64/hidden1.d.bad 2008-03-16 08:42:41.000000000 -0700
374 +++ binutils/ld/testsuite/ld-x86-64/hidden1.d 2008-03-16 08:30:02.000000000 -0700
377 +#ld: -shared -melf_x86_64
378 +#error: .*relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object
379 --- binutils/ld/testsuite/ld-x86-64/hidden1.s.bad 2008-03-16 08:42:41.000000000 -0700
380 +++ binutils/ld/testsuite/ld-x86-64/hidden1.s 2008-03-16 08:26:19.000000000 -0700
384 + .type bar, @function
386 + leaq foo(%rip), %rax
391 --- binutils/ld/testsuite/ld-x86-64/hidden2.d.bad 2008-03-16 08:42:41.000000000 -0700
392 +++ binutils/ld/testsuite/ld-x86-64/hidden2.d 2008-03-16 08:37:01.000000000 -0700
395 +#ld: -shared -melf_x86_64
401 +Disassembly of section .text:
404 +[ ]*[a-f0-9]+: e8 33 fe ff ff callq 0 <bar-0x[a-f0-9]+>
405 +[ ]*[a-f0-9]+: c3 retq
407 --- binutils/ld/testsuite/ld-x86-64/hidden2.s.bad 2008-03-16 08:42:41.000000000 -0700
408 +++ binutils/ld/testsuite/ld-x86-64/hidden2.s 2008-03-16 08:26:28.000000000 -0700
412 + .type bar, @function
419 --- binutils/ld/testsuite/ld-x86-64/hidden3.d.bad 2008-03-16 08:42:41.000000000 -0700
420 +++ binutils/ld/testsuite/ld-x86-64/hidden3.d 2008-03-16 08:30:14.000000000 -0700
423 +#ld: -shared -melf_x86_64
424 +#error: .*relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object
425 --- binutils/ld/testsuite/ld-x86-64/hidden3.s.bad 2008-03-16 08:42:41.000000000 -0700
426 +++ binutils/ld/testsuite/ld-x86-64/hidden3.s 2008-03-16 08:26:37.000000000 -0700
430 + .type bar, @function
432 + leaq foo(%rip), %rax
436 --- binutils/ld/testsuite/ld-x86-64/protected1.d.bad 2008-03-16 08:42:41.000000000 -0700
437 +++ binutils/ld/testsuite/ld-x86-64/protected1.d 2008-03-16 08:38:21.000000000 -0700
440 +#ld: -shared -melf_x86_64
441 +#error: .*relocation R_X86_64_PC32 against protected symbol `foo' can not be used when making a shared object
442 --- binutils/ld/testsuite/ld-x86-64/protected1.s.bad 2008-03-16 08:42:41.000000000 -0700
443 +++ binutils/ld/testsuite/ld-x86-64/protected1.s 2008-03-16 08:27:04.000000000 -0700
448 + .type foo, @function
453 + .type bar, @function
455 + leaq foo(%rip), %rax
458 --- binutils/ld/testsuite/ld-x86-64/protected2.d.bad 2008-03-16 08:42:41.000000000 -0700
459 +++ binutils/ld/testsuite/ld-x86-64/protected2.d 2008-03-16 08:40:09.000000000 -0700
462 +#ld: -shared -melf_x86_64
468 +Disassembly of section .text:
471 +[ ]*[a-f0-9]+: c3 retq
474 +[ ]*[a-f0-9]+: e8 fa ff ff ff callq [a-f0-9]+ <foo>
475 +[ ]*[a-f0-9]+: c3 retq
477 --- binutils/ld/testsuite/ld-x86-64/protected2.s.bad 2008-03-16 08:42:41.000000000 -0700
478 +++ binutils/ld/testsuite/ld-x86-64/protected2.s 2008-03-16 08:27:15.000000000 -0700
483 + .type foo, @function
488 + .type bar, @function
493 --- binutils/ld/testsuite/ld-x86-64/protected3.d.bad 2008-03-16 08:42:41.000000000 -0700
494 +++ binutils/ld/testsuite/ld-x86-64/protected3.d 2008-03-16 08:42:03.000000000 -0700
497 +#ld: -shared -melf_x86_64
503 +Disassembly of section .text:
506 +[ ]*[a-f0-9]+: 8b 05 ce 00 20 00 mov 0x[a-f0-9]+\(%rip\),%eax # [a-f0-9]+ <foo>
507 +[ ]*[a-f0-9]+: c3 retq
509 --- binutils/ld/testsuite/ld-x86-64/protected3.s.bad 2008-03-16 08:42:41.000000000 -0700
510 +++ binutils/ld/testsuite/ld-x86-64/protected3.s 2008-03-16 08:27:29.000000000 -0700
522 + .type bar, @function
524 + movl foo(%rip), %eax
527 --- binutils/ld/testsuite/ld-x86-64/x86-64.exp.bad 2007-08-25 07:35:38.000000000 -0700
528 +++ binutils/ld/testsuite/ld-x86-64/x86-64.exp 2008-03-16 09:30:07.000000000 -0700
529 @@ -86,3 +86,9 @@ run_dump_test "tlsgd2"
530 run_dump_test "tlsgd3"
531 run_dump_test "tlsie2"
532 run_dump_test "tlsie3"
533 +run_dump_test "hidden1"
534 +run_dump_test "hidden2"
535 +run_dump_test "hidden3"
536 +run_dump_test "protected1"
537 +run_dump_test "protected2"
538 +run_dump_test "protected3"