aboutsummaryrefslogtreecommitdiff
path: root/ld/pe-dll.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2021-03-04 16:55:01 +0100
committerJan Beulich <jbeulich@suse.com>2021-03-04 16:55:01 +0100
commit6fa7408d72b3805536e3579ba46b48f07f2e780a (patch)
tree4bf2a749afaa5ad0866b5659d2f4f6534fad2d5d /ld/pe-dll.c
parent1178743e4c05d9c0daad5a105277fbc42872c9ea (diff)
downloadbinutils-6fa7408d72b3805536e3579ba46b48f07f2e780a.zip
binutils-6fa7408d72b3805536e3579ba46b48f07f2e780a.tar.gz
binutils-6fa7408d72b3805536e3579ba46b48f07f2e780a.tar.bz2
ld: don't generate base relocations in PE output for absolute symbols
It is the very nature of absolute symbols that they don't change even if the loader decides to put the image at other than its link-time base address. Of the linker-defined (and PE-specific) symbols __image_base__ (and its alias) needs special casing, as it'll still appear to be absolute at this point. A new inquiry function in ldexp.c is needed because PE base relocations get generated before ldexp_finalize_syms() runs, yet whether a relocation is needed depends on the ultimate property of a symbol.
Diffstat (limited to 'ld/pe-dll.c')
-rw-r--r--ld/pe-dll.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 3c82f8d..afcf6fe 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -1579,13 +1579,13 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
&& relocs[i]->howto->type != pe_details->imagebase_reloc)
{
struct bfd_symbol *sym = *relocs[i]->sym_ptr_ptr;
+ const struct bfd_link_hash_entry *blhe
+ = bfd_wrapped_link_hash_lookup (abfd, info, sym->name,
+ FALSE, FALSE, FALSE);
/* Don't create relocs for undefined weak symbols. */
if (sym->flags == BSF_WEAK)
{
- struct bfd_link_hash_entry *blhe
- = bfd_wrapped_link_hash_lookup (abfd, info, sym->name,
- FALSE, FALSE, FALSE);
if (blhe && blhe->type == bfd_link_hash_undefweak)
{
/* Check aux sym and see if it is defined or not. */
@@ -1617,6 +1617,12 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
if (!strcmp (s->name, ".eh_frame"))
continue;
}
+ /* Nor for absolute symbols. */
+ else if (blhe && ldexp_is_final_sym_absolute (blhe)
+ && (!blhe->linker_def
+ || (strcmp (sym->name, "__image_base__")
+ && strcmp (sym->name, U ("__ImageBase")))))
+ continue;
reloc_data[total_relocs].vma = sec_vma + relocs[i]->address;
reloc_data[total_relocs].idx = total_relocs;