mirror of
https://github.com/devkitPro/buildscripts.git
synced 2026-04-23 10:57:23 -05:00
343 lines
13 KiB
Diff
343 lines
13 KiB
Diff
diff -Nbaur binutils-2.29.1-orig/bfd/elfnn-aarch64.c binutils-2.29.1-dka64/bfd/elfnn-aarch64.c
|
|
--- binutils-2.29.1-orig/bfd/elfnn-aarch64.c 2017-09-05 14:12:46.000000000 +0100
|
|
+++ binutils-2.29.1-dka64/bfd/elfnn-aarch64.c 2017-10-22 06:58:57.711591457 +0100
|
|
@@ -2097,6 +2097,12 @@
|
|
aarch64_stub_erratum_843419_veneer,
|
|
};
|
|
|
|
+/* Is an undefined weak symbol resolved to 0 ? */
|
|
+#define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \
|
|
+ ((EH)->root.root.type == bfd_link_hash_undefweak \
|
|
+ && bfd_link_executable (INFO) \
|
|
+ && !(INFO)->dynamic_undefined_weak)
|
|
+
|
|
struct elf_aarch64_stub_hash_entry
|
|
{
|
|
/* Base hash table entry structure. */
|
|
@@ -6081,11 +6087,13 @@
|
|
Elf_Internal_Sym *sym;
|
|
asection *sec;
|
|
struct elf_link_hash_entry *h;
|
|
+ struct elf_aarch64_link_hash_entry *eh;
|
|
bfd_vma relocation;
|
|
bfd_reloc_status_type r;
|
|
arelent bfd_reloc;
|
|
char sym_type;
|
|
bfd_boolean unresolved_reloc = FALSE;
|
|
+ bfd_boolean resolved_to_zero = FALSE;
|
|
char *error_message = NULL;
|
|
|
|
r_symndx = ELFNN_R_SYM (rel->r_info);
|
|
@@ -6225,6 +6233,10 @@
|
|
h, &unresolved_reloc,
|
|
save_addend, &addend, sym);
|
|
|
|
+ eh = (struct elf_aarch64_link_hash_entry *) h;
|
|
+ resolved_to_zero = (eh != NULL
|
|
+ && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh));
|
|
+
|
|
switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
|
|
{
|
|
case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
|
|
@@ -6248,7 +6260,7 @@
|
|
need_relocs =
|
|
(bfd_link_pic (info) || indx != 0) &&
|
|
(h == NULL
|
|
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|
|
+ || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT && !resolved_to_zero)
|
|
|| h->root.type != bfd_link_hash_undefweak);
|
|
|
|
BFD_ASSERT (globals->root.srelgot != NULL);
|
|
@@ -6343,7 +6355,7 @@
|
|
need_relocs =
|
|
(bfd_link_pic (info) || indx != 0) &&
|
|
(h == NULL
|
|
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|
|
+ || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT && !resolved_to_zero)
|
|
|| h->root.type != bfd_link_hash_undefweak);
|
|
|
|
BFD_ASSERT (globals->root.srelgot != NULL);
|
|
@@ -6392,7 +6404,7 @@
|
|
bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
|
|
|
|
need_relocs = (h == NULL
|
|
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|
|
+ || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT && !resolved_to_zero)
|
|
|| h->root.type != bfd_link_hash_undefweak);
|
|
|
|
BFD_ASSERT (globals->root.srelgot != NULL);
|
|
@@ -6891,6 +6903,26 @@
|
|
return FALSE;
|
|
}
|
|
|
|
+/* Remove undefined weak symbol from the dynamic symbol table if it
|
|
+ is resolved to 0. */
|
|
+
|
|
+extern bfd_boolean
|
|
+elfNN_aarch64_elf_fixup_symbol (struct bfd_link_info *, struct elf_link_hash_entry *);
|
|
+
|
|
+bfd_boolean
|
|
+elfNN_aarch64_elf_fixup_symbol (struct bfd_link_info *info,
|
|
+ struct elf_link_hash_entry *h)
|
|
+{
|
|
+ if (h->dynindx != -1
|
|
+ && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, elf_aarch64_hash_entry (h)))
|
|
+ {
|
|
+ h->dynindx = -1;
|
|
+ _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
|
|
+ h->dynstr_index);
|
|
+ }
|
|
+ return TRUE;
|
|
+}
|
|
+
|
|
/* Adjust a symbol defined by a dynamic object and referenced by a
|
|
regular object. The current definition is in some section of the
|
|
dynamic object, but we're not including those sections. We have to
|
|
@@ -8068,6 +8100,7 @@
|
|
struct elf_aarch64_link_hash_table *htab;
|
|
struct elf_aarch64_link_hash_entry *eh;
|
|
struct elf_dyn_relocs *p;
|
|
+ bfd_boolean resolved_to_zero;
|
|
|
|
/* An example of a bfd_link_hash_indirect symbol is versioned
|
|
symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
|
|
@@ -8087,6 +8120,10 @@
|
|
info = (struct bfd_link_info *) inf;
|
|
htab = elf_aarch64_hash_table (info);
|
|
|
|
+ eh = (struct elf_aarch64_link_hash_entry *) h;
|
|
+ eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
|
|
+ resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
|
|
+
|
|
/* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
|
|
here if it is defined and referenced in a non-shared object. */
|
|
if (h->type == STT_GNU_IFUNC
|
|
@@ -8096,7 +8133,7 @@
|
|
{
|
|
/* Make sure this symbol is output as a dynamic symbol.
|
|
Undefined weak syms won't yet be marked as dynamic. */
|
|
- if (h->dynindx == -1 && !h->forced_local
|
|
+ if (h->dynindx == -1 && !h->forced_local && !resolved_to_zero
|
|
&& h->root.type == bfd_link_hash_undefweak)
|
|
{
|
|
if (!bfd_elf_link_record_dynamic_symbol (info, h))
|
|
@@ -8130,6 +8167,11 @@
|
|
of relaxing into these from the large model PLT entries. */
|
|
s->size += PLT_SMALL_ENTRY_SIZE;
|
|
|
|
+ /* There should be no PLT relocations against resolved undefined
|
|
+ weak symbols in the executable. */
|
|
+ if (!resolved_to_zero)
|
|
+ {
|
|
+
|
|
/* We also need to make an entry in the .got.plt section, which
|
|
will be placed in the .got section by the linker script. */
|
|
htab->root.sgotplt->size += GOT_ENTRY_SIZE;
|
|
@@ -8152,6 +8194,7 @@
|
|
|
|
htab->root.srelplt->reloc_count++;
|
|
}
|
|
+ }
|
|
else
|
|
{
|
|
h->plt.offset = (bfd_vma) - 1;
|
|
@@ -8164,9 +8207,6 @@
|
|
h->needs_plt = 0;
|
|
}
|
|
|
|
- eh = (struct elf_aarch64_link_hash_entry *) h;
|
|
- eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
|
|
-
|
|
if (h->got.refcount > 0)
|
|
{
|
|
bfd_boolean dyn;
|
|
@@ -8178,7 +8218,7 @@
|
|
|
|
/* Make sure this symbol is output as a dynamic symbol.
|
|
Undefined weak syms won't yet be marked as dynamic. */
|
|
- if (dyn && h->dynindx == -1 && !h->forced_local
|
|
+ if (dyn && h->dynindx == -1 && !h->forced_local && !resolved_to_zero
|
|
&& h->root.type == bfd_link_hash_undefweak)
|
|
{
|
|
if (!bfd_elf_link_record_dynamic_symbol (info, h))
|
|
@@ -8192,7 +8232,7 @@
|
|
{
|
|
h->got.offset = htab->root.sgot->size;
|
|
htab->root.sgot->size += GOT_ENTRY_SIZE;
|
|
- if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|
|
+ if (((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT && !resolved_to_zero)
|
|
|| h->root.type != bfd_link_hash_undefweak)
|
|
&& (bfd_link_pic (info)
|
|
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
|
|
@@ -8225,7 +8265,7 @@
|
|
}
|
|
|
|
indx = h && h->dynindx != -1 ? h->dynindx : 0;
|
|
- if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|
|
+ if (((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT && !resolved_to_zero)
|
|
|| h->root.type != bfd_link_hash_undefweak)
|
|
&& (bfd_link_pic (info)
|
|
|| indx != 0
|
|
@@ -8291,7 +8331,7 @@
|
|
visibility. */
|
|
if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
|
|
{
|
|
- if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
|
|
+ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT || resolved_to_zero)
|
|
eh->dyn_relocs = NULL;
|
|
|
|
/* Make sure undefined weak symbols are output as a dynamic
|
|
@@ -8310,7 +8350,9 @@
|
|
symbols which turn out to need copy relocs or are not
|
|
dynamic. */
|
|
|
|
- if (!h->non_got_ref
|
|
+ if (!(h->non_got_ref
|
|
+ || (h->root.type == bfd_link_hash_undefweak
|
|
+ && !resolved_to_zero))
|
|
&& ((h->def_dynamic
|
|
&& !h->def_regular)
|
|
|| (htab->root.dynamic_sections_created
|
|
@@ -8321,6 +8363,7 @@
|
|
Undefined weak syms won't yet be marked as dynamic. */
|
|
if (h->dynindx == -1
|
|
&& !h->forced_local
|
|
+ && !resolved_to_zero
|
|
&& h->root.type == bfd_link_hash_undefweak
|
|
&& !bfd_elf_link_record_dynamic_symbol (info, h))
|
|
return FALSE;
|
|
@@ -8940,8 +8983,17 @@
|
|
Elf_Internal_Sym *sym)
|
|
{
|
|
struct elf_aarch64_link_hash_table *htab;
|
|
+ struct elf_aarch64_link_hash_entry *eh;
|
|
+ bfd_boolean local_undefweak;
|
|
htab = elf_aarch64_hash_table (info);
|
|
|
|
+ eh = (struct elf_aarch64_link_hash_entry *) h;
|
|
+
|
|
+ /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
|
|
+ resolved undefined weak symbols in executable so that their
|
|
+ references have value 0 at run-time. */
|
|
+ local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
|
|
+
|
|
if (h->plt.offset != (bfd_vma) - 1)
|
|
{
|
|
asection *plt, *gotplt, *relplt;
|
|
@@ -8976,7 +9028,7 @@
|
|
return FALSE;
|
|
|
|
elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
|
|
- if (!h->def_regular)
|
|
+ if (!local_undefweak && !h->def_regular)
|
|
{
|
|
/* Mark the symbol as undefined, rather than as defined in
|
|
the .plt section. */
|
|
@@ -8995,7 +9047,8 @@
|
|
}
|
|
|
|
if (h->got.offset != (bfd_vma) - 1
|
|
- && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
|
|
+ && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL
|
|
+ && !local_undefweak)
|
|
{
|
|
Elf_Internal_Rela rela;
|
|
bfd_byte *loc;
|
|
@@ -9489,6 +9542,9 @@
|
|
#define elf_backend_init_index_section \
|
|
_bfd_elf_init_2_index_sections
|
|
|
|
+#define elf_backend_fixup_symbol \
|
|
+ elfNN_aarch64_elf_fixup_symbol
|
|
+
|
|
#define elf_backend_finish_dynamic_sections \
|
|
elfNN_aarch64_finish_dynamic_sections
|
|
|
|
diff -Nbaur binutils-2.29.1-orig/ld/emulparams/aarch64elf32.sh binutils-2.29.1-dka64/ld/emulparams/aarch64elf32.sh
|
|
--- binutils-2.29.1-orig/ld/emulparams/aarch64elf32.sh 2017-07-10 10:54:42.000000000 +0100
|
|
+++ binutils-2.29.1-dka64/ld/emulparams/aarch64elf32.sh 2017-10-22 06:58:57.719591510 +0100
|
|
@@ -1,3 +1,5 @@
|
|
+. ${srcdir}/emulparams/dynamic_undefined_weak.sh
|
|
+
|
|
ARCH="aarch64:ilp32"
|
|
MACHINE=
|
|
NOP=0
|
|
diff -Nbaur binutils-2.29.1-orig/ld/emulparams/aarch64elf.sh binutils-2.29.1-dka64/ld/emulparams/aarch64elf.sh
|
|
--- binutils-2.29.1-orig/ld/emulparams/aarch64elf.sh 2017-07-10 10:54:42.000000000 +0100
|
|
+++ binutils-2.29.1-dka64/ld/emulparams/aarch64elf.sh 2017-10-22 06:58:57.719591510 +0100
|
|
@@ -1,3 +1,5 @@
|
|
+. ${srcdir}/emulparams/dynamic_undefined_weak.sh
|
|
+
|
|
ARCH=aarch64
|
|
MACHINE=
|
|
NOP=0
|
|
diff -Nbaur binutils-2.29.1-orig/ld/emultempl/aarch64elf.em binutils-2.29.1-dka64/ld/emultempl/aarch64elf.em
|
|
--- binutils-2.29.1-orig/ld/emultempl/aarch64elf.em 2017-07-10 10:54:42.000000000 +0100
|
|
+++ binutils-2.29.1-dka64/ld/emultempl/aarch64elf.em 2017-10-22 06:58:57.719591510 +0100
|
|
@@ -375,7 +375,7 @@
|
|
{ "no-apply-dynamic-relocs", no_argument, NULL, OPTION_NO_APPLY_DYNAMIC_RELOCS},
|
|
'
|
|
|
|
-PARSE_AND_LIST_OPTIONS='
|
|
+PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
|
|
fprintf (file, _(" --no-enum-size-warning Don'\''t warn about objects with incompatible\n"
|
|
" enum sizes\n"));
|
|
fprintf (file, _(" --no-wchar-size-warning Don'\''t warn about objects with incompatible"
|
|
diff -Nbaur binutils-2.29.1-orig/ld/Makefile.am binutils-2.29.1-dka64/ld/Makefile.am
|
|
--- binutils-2.29.1-orig/ld/Makefile.am 2017-07-10 10:54:42.000000000 +0100
|
|
+++ binutils-2.29.1-dka64/ld/Makefile.am 2017-10-22 06:58:57.719591510 +0100
|
|
@@ -1654,19 +1654,23 @@
|
|
$(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elf.c: $(srcdir)/emulparams/aarch64elf.sh \
|
|
- $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
+ $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em ldemul-list.h \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elf32.c: $(srcdir)/emulparams/aarch64elf32.sh \
|
|
- $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
+ $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em ldemul-list.h \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elfb.c: $(srcdir)/emulparams/aarch64elfb.sh $(srcdir)/emulparams/aarch64elf.sh \
|
|
- $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
+ $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em ldemul-list.h \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elf32b.c: $(srcdir)/emulparams/aarch64elf32b.sh $(srcdir)/emulparams/aarch64elf32.sh \
|
|
- $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
+ $(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em ldemul-list.h \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64cloudabi.c: $(srcdir)/emulparams/aarch64cloudabi.sh \
|
|
diff -Nbaur binutils-2.29.1-orig/ld/Makefile.in binutils-2.29.1-dka64/ld/Makefile.in
|
|
--- binutils-2.29.1-orig/ld/Makefile.in 2017-09-15 12:38:08.000000000 +0100
|
|
+++ binutils-2.29.1-dka64/ld/Makefile.in 2017-10-22 06:58:57.719591510 +0100
|
|
@@ -3219,18 +3219,22 @@
|
|
|
|
eaarch64elf.c: $(srcdir)/emulparams/aarch64elf.sh \
|
|
$(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elf32.c: $(srcdir)/emulparams/aarch64elf32.sh \
|
|
$(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elfb.c: $(srcdir)/emulparams/aarch64elfb.sh $(srcdir)/emulparams/aarch64elf.sh \
|
|
$(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64elf32b.c: $(srcdir)/emulparams/aarch64elf32b.sh $(srcdir)/emulparams/aarch64elf32.sh \
|
|
$(ELF_DEPS) $(srcdir)/emultempl/aarch64elf.em \
|
|
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
|
|
$(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
|
|
|
|
eaarch64cloudabi.c: $(srcdir)/emulparams/aarch64cloudabi.sh \
|