[binutils-gdb] ELF DWARF in PE output

Alan Modra amodra@sourceware.org
Tue Mar 9 23:25:21 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2dfa8341e079765f37ab02b2b63cfcffe64c37dd

commit 2dfa8341e079765f37ab02b2b63cfcffe64c37dd
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Mar 6 21:56:15 2021 +1030

    ELF DWARF in PE output
    
            * elf.c (bfd_elf_generic_reloc): Make references between debug
            sections use section relative values.

Diff:
---
 bfd/ChangeLog |  6 ++++++
 bfd/elf.c     | 17 +++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 6c633ebe0b6..fe3808596bb 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2021-03-10  Alan Modra  <amodra@gmail.com>
+	    Jan Beulich  <jbeulich@suse.com>
+
+	* elf.c (bfd_elf_generic_reloc): Make references between debug
+	sections use section relative values.
+
 2021-03-09  Jan Beulich  <jbeulich@suse.com>
 
 	* peXXigen.c (_bfd_XXi_swap_scnhdr_out): Diagnose out of range RVA.
diff --git a/bfd/elf.c b/bfd/elf.c
index 553fa65a118..35c31cf40bf 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1302,8 +1302,7 @@ const char *const bfd_elf_section_type_names[] =
    change anything about the way the reloc is handled, since it will
    all be done at final link time.  Rather than put special case code
    into bfd_perform_relocation, all the reloc types use this howto
-   function.  It just short circuits the reloc if producing
-   relocatable output against an external symbol.  */
+   function, or should call this function for relocatable output.  */
 
 bfd_reloc_status_type
 bfd_elf_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED,
@@ -1323,6 +1322,20 @@ bfd_elf_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED,
       return bfd_reloc_ok;
     }
 
+  /* In some cases the relocation should be treated as output section
+     relative, as when linking ELF DWARF into PE COFF.  Many ELF
+     targets lack section relative relocations and instead use
+     ordinary absolute relocations for references between DWARF
+     sections.  That is arguably a bug in those targets but it happens
+     to work for the usual case of linking to non-loaded ELF debug
+     sections with VMAs forced to zero.  PE COFF on the other hand
+     doesn't allow a section VMA of zero.  */
+  if (output_bfd == NULL
+      && !reloc_entry->howto->pc_relative
+      && (symbol->section->flags & SEC_DEBUGGING) != 0
+      && (input_section->flags & SEC_DEBUGGING) != 0)
+    reloc_entry->addend -= symbol->section->output_section->vma;
+
   return bfd_reloc_continue;
 }


More information about the Binutils-cvs mailing list