• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


コミットメタ情報

リビジョン9e9821ddd80c0d0b3dda54d34cc8867f256d4583 (tree)
日時2017-04-25 06:37:12
作者H.J. Lu <hjl.tools@gmai...>
コミッターH.J. Lu

ログメッセージ

x86-64: Force symbol dynamic if it isn't undefined weak

Force symbol dynamic if it isn't undefined weak. Generate relative
relocation for GOT reference against non-dynamic symbol in PIC to
avoid unnecessary dynamic symbols.

bfd/

* elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
no_finish_dynamic_symbol.
(elf_x86_64_link_hash_newfunc): Set no_finish_dynamic_symbol to
0.
(elf_x86_64_allocate_dynrelocs): If a symbol isn't undefined
weak symbol, don't make it dynamic.
(elf_x86_64_relocate_section): If a symbol isn't dynamic in PIC,
set no_finish_dynamic_symbol and generate R_X86_64_RELATIVE
relocation for GOT reference.
(elf_x86_64_finish_dynamic_symbol): Abort if
no_finish_dynamic_symbol isn't 0.

ld/

* testsuite/ld-x86-64/no-plt.exp: Also check no-plt-1e.nd.
* testsuite/ld-x86-64/no-plt-1e.nd: New file.

変更サマリ

差分

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,19 @@
11 2017-04-24 H.J. Lu <hongjiu.lu@intel.com>
22
3+ * elf64-x86-64.c (elf_x86_64_link_hash_entry): Add
4+ no_finish_dynamic_symbol.
5+ (elf_x86_64_link_hash_newfunc): Set no_finish_dynamic_symbol to
6+ 0.
7+ (elf_x86_64_allocate_dynrelocs): If a symbol isn't undefined
8+ weak symbol, don't make it dynamic.
9+ (elf_x86_64_relocate_section): If a symbol isn't dynamic in PIC,
10+ set no_finish_dynamic_symbol and generate R_X86_64_RELATIVE
11+ relocation for GOT reference.
12+ (elf_x86_64_finish_dynamic_symbol): Abort if
13+ no_finish_dynamic_symbol isn't 0.
14+
15+2017-04-24 H.J. Lu <hongjiu.lu@intel.com>
16+
317 PR ld/21402
418 * elf32-i386.c (elf_i386_allocate_dynrelocs): If a symbol isn't
519 undefined weak symbol, don't make it dynamic.
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -867,6 +867,9 @@ struct elf_x86_64_link_hash_entry
867867 /* TRUE if symbol has non-GOT/non-PLT relocations in text sections. */
868868 unsigned int has_non_got_reloc : 1;
869869
870+ /* Don't call finish_dynamic_symbol on this symbol. */
871+ unsigned int no_finish_dynamic_symbol : 1;
872+
870873 /* 0: symbol isn't __tls_get_addr.
871874 1: symbol is __tls_get_addr.
872875 2: symbol is unknown. */
@@ -1022,6 +1025,7 @@ elf_x86_64_link_hash_newfunc (struct bfd_hash_entry *entry,
10221025 eh->has_bnd_reloc = 0;
10231026 eh->has_got_reloc = 0;
10241027 eh->has_non_got_reloc = 0;
1028+ eh->no_finish_dynamic_symbol = 0;
10251029 eh->tls_get_addr = 2;
10261030 eh->func_pointer_refcount = 0;
10271031 eh->plt_bnd.offset = (bfd_vma) -1;
@@ -3218,7 +3222,8 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
32183222 Undefined weak syms won't yet be marked as dynamic. */
32193223 if (h->dynindx == -1
32203224 && !h->forced_local
3221- && !resolved_to_zero)
3225+ && !resolved_to_zero
3226+ && h->root.type == bfd_link_hash_undefweak)
32223227 {
32233228 if (! bfd_elf_link_record_dynamic_symbol (info, h))
32243229 return FALSE;
@@ -3338,7 +3343,8 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
33383343 Undefined weak syms won't yet be marked as dynamic. */
33393344 if (h->dynindx == -1
33403345 && !h->forced_local
3341- && !resolved_to_zero)
3346+ && !resolved_to_zero
3347+ && h->root.type == bfd_link_hash_undefweak)
33423348 {
33433349 if (! bfd_elf_link_record_dynamic_symbol (info, h))
33443350 return FALSE;
@@ -3475,6 +3481,7 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
34753481 if (h->dynindx == -1
34763482 && ! h->forced_local
34773483 && ! resolved_to_zero
3484+ && h->root.type == bfd_link_hash_undefweak
34783485 && ! bfd_elf_link_record_dynamic_symbol (info, h))
34793486 return FALSE;
34803487
@@ -4270,6 +4277,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
42704277 asection *base_got, *resolved_plt;
42714278 bfd_vma st_size;
42724279 bfd_boolean resolved_to_zero;
4280+ bfd_boolean relative_reloc;
42734281
42744282 r_type = ELF32_R_TYPE (rel->r_info);
42754283 if (r_type == (int) R_X86_64_GNU_VTINHERIT
@@ -4637,6 +4645,7 @@ do_ifunc_pointer:
46374645 if (htab->elf.sgot == NULL)
46384646 abort ();
46394647
4648+ relative_reloc = FALSE;
46404649 if (h != NULL)
46414650 {
46424651 bfd_boolean dyn;
@@ -4683,6 +4692,17 @@ do_ifunc_pointer:
46834692 /* Note that this is harmless for the GOTPLT64 case,
46844693 as -1 | 1 still is -1. */
46854694 h->got.offset |= 1;
4695+
4696+ if (h->dynindx == -1
4697+ && !h->forced_local
4698+ && h->root.type != bfd_link_hash_undefweak
4699+ && bfd_link_pic (info))
4700+ {
4701+ /* If this symbol isn't dynamic in PIC,
4702+ generate R_X86_64_RELATIVE here. */
4703+ eh->no_finish_dynamic_symbol = 1;
4704+ relative_reloc = TRUE;
4705+ }
46864706 }
46874707 }
46884708 else
@@ -4704,30 +4724,32 @@ do_ifunc_pointer:
47044724 {
47054725 bfd_put_64 (output_bfd, relocation,
47064726 base_got->contents + off);
4727+ local_got_offsets[r_symndx] |= 1;
47074728
47084729 if (bfd_link_pic (info))
4709- {
4710- asection *s;
4711- Elf_Internal_Rela outrel;
4712-
4713- /* We need to generate a R_X86_64_RELATIVE reloc
4714- for the dynamic linker. */
4715- s = htab->elf.srelgot;
4716- if (s == NULL)
4717- abort ();
4718-
4719- outrel.r_offset = (base_got->output_section->vma
4720- + base_got->output_offset
4721- + off);
4722- outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4723- outrel.r_addend = relocation;
4724- elf_append_rela (output_bfd, s, &outrel);
4725- }
4726-
4727- local_got_offsets[r_symndx] |= 1;
4730+ relative_reloc = TRUE;
47284731 }
47294732 }
47304733
4734+ if (relative_reloc)
4735+ {
4736+ asection *s;
4737+ Elf_Internal_Rela outrel;
4738+
4739+ /* We need to generate a R_X86_64_RELATIVE reloc
4740+ for the dynamic linker. */
4741+ s = htab->elf.srelgot;
4742+ if (s == NULL)
4743+ abort ();
4744+
4745+ outrel.r_offset = (base_got->output_section->vma
4746+ + base_got->output_offset
4747+ + off);
4748+ outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
4749+ outrel.r_addend = relocation;
4750+ elf_append_rela (output_bfd, s, &outrel);
4751+ }
4752+
47314753 if (off >= (bfd_vma) -2)
47324754 abort ();
47334755
@@ -5797,6 +5819,8 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
57975819 : get_elf_x86_64_backend_data (output_bfd));
57985820
57995821 eh = (struct elf_x86_64_link_hash_entry *) h;
5822+ if (eh->no_finish_dynamic_symbol)
5823+ abort ();
58005824
58015825 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
58025826 resolved undefined weak symbols in executable so that their
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,10 @@
11 2017-04-24 H.J. Lu <hongjiu.lu@intel.com>
22
3+ * testsuite/ld-x86-64/no-plt.exp: Also check no-plt-1e.nd.
4+ * testsuite/ld-x86-64/no-plt-1e.nd: New file.
5+
6+2017-04-24 H.J. Lu <hongjiu.lu@intel.com>
7+
38 * testsuite/ld-i386/pr12570a.d: Skip for nacl targets.
49 * testsuite/ld-i386/pr12570b.d: Likewise.
510
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/no-plt-1e.nd
@@ -0,0 +1,7 @@
1+#nm: -g -D
2+#target: x86_64-*-*
3+
4+#failif
5+#...
6+[0-9]+ +T +func
7+#...
--- a/ld/testsuite/ld-x86-64/no-plt.exp
+++ b/ld/testsuite/ld-x86-64/no-plt.exp
@@ -111,7 +111,7 @@ run_cc_link_tests [list \
111111 tmpdir/no-plt-func1.o tmpdir/no-plt-extern1.o" \
112112 "" \
113113 {dummy.s} \
114- {{readelf -Wr no-plt-1e.rd} {objdump -dwrj.text no-plt-1e.dd}} \
114+ {{readelf -Wr no-plt-1e.rd} {nm -gD no-plt-1e.nd} {objdump -dwrj.text no-plt-1e.dd}} \
115115 "no-plt-1e" \
116116 ] \
117117 [list \