Stop the BFD library from automatically converting OS and PROC specific symbol sectio...
authorNick Clifton <nickc@redhat.com>
Thu, 20 Feb 2020 13:08:29 +0000 (13:08 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 20 Feb 2020 13:08:29 +0000 (13:08 +0000)
* elf-bfd.h (struct elf_backend_data): Add symbol_section_index
callback.
* elfxx-target.h (elf_backend_symbol_section_index): Provide
default definition.
(elfNN_bed): Initialise the symbol_section_index field.
* elf.c (swap_out_syms): Call symbol_section_index, if defined, on
OS and PROC specific section indicies.  Warn if converting other
reserved incidies to SHN_ABS.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf.c
bfd/elfxx-target.h

index 6c1c1316af83305db0c5f2d765a2c75de7f58a94..6ee734c4fc9797211f71c79b5104565286585fcf 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-20  Nick Clifton  <nickc@redhat.com>
+
+       * elf-bfd.h (struct elf_backend_data): Add symbol_section_index
+       callback.
+       * elfxx-target.h (elf_backend_symbol_section_index): Provide
+       default definition.
+       (elfNN_bed): Initialise the symbol_section_index field.
+       * elf.c (swap_out_syms): Call symbol_section_index, if defined, on
+       OS and PROC specific section indicies.  Warn if converting other
+       reserved incidies to SHN_ABS.
+
 2020-02-19  Sergey Belyashov  <sergey.belyashov@gmail.com>
 
        PR 25537
index cbbba153f4966926a9bf7c45020da39774d0ed25..7d36e23ea11161a1db67ebbcd2a36be9c460934e 100644 (file)
@@ -1503,6 +1503,12 @@ struct elf_backend_data
   /* Opcode representing no unwind.  */
   int (*cant_unwind_opcode) (struct bfd_link_info *);
 
+  /* Called when emitting an ELF symbol whoes input version had an
+     ST_SHNDX field set to a value in the range SHN_LOPROC..SHN_HIOS.
+     Returns the value to be installed in the ST_SHNDX field of the
+     emitted symbol.  If not defined, the value is left unchanged.  */
+  unsigned int (*symbol_section_index) (bfd *, elf_symbol_type *);
+  
   /* This is non-zero if static TLS segments require a special alignment.  */
   unsigned static_tls_alignment;
 
index deb93b0a5a9f27f5dafce99473f2c65aa0663501..4342e847527e288791a13aaaf1d23a78166baea8 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8194,9 +8194,26 @@ swap_out_syms (bfd *abfd,
                  if (elf_symtab_shndx_list (abfd))
                    shndx = elf_symtab_shndx_list (abfd)->ndx;
                  break;
-               default:
+               case SHN_COMMON:
+               case SHN_ABS:
                  shndx = SHN_ABS;
                  break;
+               default:
+                 if (shndx >= SHN_LOPROC && shndx <= SHN_HIOS)
+                   {
+                     if (bed->symbol_section_index)
+                       shndx = bed->symbol_section_index (abfd, type_ptr);
+                     /* Otherwise just leave the index alone.  */
+                   }
+                 else
+                   {
+                     if (shndx > SHN_HIOS && shndx < SHN_HIRESERVE)
+                       _bfd_error_handler (_("%pB: \
+Unable to handle section index %x in ELF symbol.  Using ABS instead."),
+                                         abfd, shndx);
+                     shndx = SHN_ABS;
+                   }
+                 break;
                }
            }
          else
index caca83f5c97fddcdeb2ec87dc792477fedddc09e..e9cac0a5352dd3fc8a355ac0cbf59c890aefceda 100644 (file)
 #define elf_backend_cant_unwind_opcode 0
 #endif
 
+#ifndef elf_backend_symbol_section_index
+#define elf_backend_symbol_section_index NULL
+#endif
 #ifndef elf_match_priority
 #define elf_match_priority \
   (ELF_ARCH == bfd_arch_unknown ? 2 : ELF_OSABI == ELFOSABI_NONE ? 1 : 0)
@@ -895,6 +899,7 @@ static struct elf_backend_data elfNN_bed =
   elf_backend_fixup_gnu_properties,
   elf_backend_compact_eh_encoding,
   elf_backend_cant_unwind_opcode,
+  elf_backend_symbol_section_index,
   elf_backend_static_tls_alignment,
   elf_backend_stack_align,
   elf_backend_strtab_flags,