This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH v2 2/2] BFD: Use `bfd_is_abs_symbol' to determine whether a symbol is absolute
- From: "Maciej W. Rozycki" <macro at mips dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Nick Clifton <nickc at redhat dot com>, Richard Earnshaw <rearnsha at arm dot com>, Marcus Shawcroft <marcus dot shawcroft at arm dot com>, Kuan-Lin Chen <kuanlinchentw at gmail dot com>, Wei-Cheng Wang <cole945 at gmail dot com>, Richard Sandiford <rdsandiford at googlemail dot com>, <binutils at sourceware dot org>
- Date: Tue, 17 Jul 2018 00:58:25 +0100
- Subject: [PATCH v2 2/2] BFD: Use `bfd_is_abs_symbol' to determine whether a symbol is absolute
- References: <alpine.DEB.2.00.1807162321200.30992@tp.orcam.me.uk>
Use `bfd_is_abs_symbol' to determine whether a symbol is absolute,
avoiding a problem with ordinary symbols defined in a linker script
outside an output section definition. Such symbols have its owning
section set to the absolute section up to the final link phase. A flag
has been added to the link hash to identify such symbols. Rather than
checking the flag by hand, use the macro that does it uniformly for all
users.
bfd/
* elf32-nds32.c (nds32_elf_relax_loadstore): Use
`bfd_is_abs_symbol' rather than `bfd_is_abs_section' in checking
whether the symbol is absolute.
(nds32_elf_relax_lo12): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
(elfNN_aarch64_check_relocs): Likewise.
* xcofflink.c (xcoff_need_ldrel_p): Likewise.
(bfd_xcoff_import_symbol): Likewise.
(xcoff_write_global_symbol): Likewise.
---
Hi,
As I noted in my earlier reply I think the updated assertion in
`xcoff_write_global_symbol' is stronger than the original, as now it will
check both `h->root.u.def.section' for being the absolute section AND
`h->root.rel_from_abs' for being clear, and therefore I have decided to
leave the update in place.
Please let me know if I missed anything.
So the only update here is the removal of the type check ahead of the
call to `bfd_is_abs_symbol' in `xcoff_need_ldrel_p', as it duplicates the
checks made by the macro itself in v2.
Maciej
Changes from v1:
- remove symbol type checks now made redundant from `xcoff_need_ldrel_p'.
---
bfd/elf32-nds32.c | 4 ++--
bfd/elfnn-aarch64.c | 6 ++----
bfd/xcofflink.c | 9 +++------
3 files changed, 7 insertions(+), 12 deletions(-)
binutils-ld-rel-from-abs-update.diff
Index: binutils/bfd/elf32-nds32.c
===================================================================
--- binutils.orig/bfd/elf32-nds32.c 2018-07-16 20:57:28.588873712 +0100
+++ binutils/bfd/elf32-nds32.c 2018-07-16 23:19:39.598102764 +0100
@@ -10567,7 +10567,7 @@ nds32_elf_relax_loadstore (struct bfd_li
/* This is avoid to relax symbol address which is fixed
relocations. Ex: _stack. */
- if (h && bfd_is_abs_section (h->root.u.def.section))
+ if (h && bfd_is_abs_symbol (&h->root))
return FALSE;
}
@@ -10707,7 +10707,7 @@ nds32_elf_relax_lo12 (struct bfd_link_in
/* This is avoid to relax symbol address which is fixed
relocations. Ex: _stack. */
else if (N32_OP6 (insn) == N32_OP6_ORI
- && h && bfd_is_abs_section (h->root.u.def.section))
+ && h && bfd_is_abs_symbol (&h->root))
return;
else
{
Index: binutils/bfd/elfnn-aarch64.c
===================================================================
--- binutils.orig/bfd/elfnn-aarch64.c 2018-07-16 20:57:28.601977510 +0100
+++ binutils/bfd/elfnn-aarch64.c 2018-07-16 23:19:39.620300603 +0100
@@ -5224,8 +5224,7 @@ elfNN_aarch64_final_link_relocate (reloc
weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
: bfd_is_und_section (sym_sec));
- abs_symbol_p = (h !=NULL && h->root.type == bfd_link_hash_defined
- && bfd_is_abs_section (h->root.u.def.section));
+ abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root);
/* Since STT_GNU_IFUNC symbol must go through PLT, we handle
@@ -7363,8 +7362,7 @@ elfNN_aarch64_check_relocs (bfd *abfd, s
if (h != NULL
/* This is an absolute symbol. It represents a value instead
of an address. */
- && ((h->root.type == bfd_link_hash_defined
- && bfd_is_abs_section (h->root.u.def.section))
+ && (bfd_is_abs_symbol (&h->root)
/* This is an undefined symbol. */
|| h->root.type == bfd_link_hash_undefined))
break;
Index: binutils/bfd/xcofflink.c
===================================================================
--- binutils.orig/bfd/xcofflink.c 2018-07-16 20:57:28.614063037 +0100
+++ binutils/bfd/xcofflink.c 2018-07-17 00:08:44.144566894 +0100
@@ -2687,10 +2687,7 @@ xcoff_need_ldrel_p (struct bfd_link_info
case R_RLA:
/* Absolute relocations against absolute symbols can be
resolved statically. */
- if (h != NULL
- && (h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak)
- && bfd_is_abs_section (h->root.u.def.section))
+ if (h != NULL && bfd_is_abs_symbol (&h->root))
return FALSE;
return TRUE;
@@ -3125,7 +3122,7 @@ bfd_xcoff_import_symbol (bfd *output_bfd
if (val != (bfd_vma) -1)
{
if (h->root.type == bfd_link_hash_defined
- && (! bfd_is_abs_section (h->root.u.def.section)
+ && (!bfd_is_abs_symbol (&h->root)
|| h->root.u.def.value != val))
(*info->callbacks->multiple_definition) (info, &h->root, output_bfd,
bfd_abs_section_ptr, val);
@@ -5589,7 +5586,7 @@ xcoff_write_global_symbol (struct bfd_ha
|| h->root.type == bfd_link_hash_defweak)
&& h->smclas == XMC_XO)
{
- BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
+ BFD_ASSERT (bfd_is_abs_symbol (&h->root));
isym.n_value = h->root.u.def.value;
isym.n_scnum = N_UNDEF;
if (h->root.type == bfd_link_hash_defweak