Introduce new section flag: SEC_ELF_OCTETS
authorChristian Eggers <ceggers@gmx.de>
Thu, 21 Nov 2019 21:17:29 +0000 (22:17 +0100)
committerAlan Modra <amodra@gmail.com>
Mon, 25 Nov 2019 04:02:19 +0000 (14:32 +1030)
All symbols, sizes and relocations in this section are octets instead of
bytes.  Required for DWARF debug sections as DWARF information is
organized in octets, not bytes.

bfd/
* section.c (struct bfd_section): New flag SEC_ELF_OCTETS.
* archures.c (bfd_octets_per_byte): New parameter sec.
If section is not NULL and SEC_ELF_OCTETS is set, one octet es
returned [ELF targets only].
* bfd.c (bfd_get_section_limit): Provide section parameter to
bfd_octets_per_byte.
* bfd-in2.h: regenerate.
* binary.c (binary_set_section_contents): Move call to
bfd_octets_per_byte into section loop. Provide section parameter
to bfd_octets_per_byte.
* coff-arm.c (coff_arm_reloc): Provide section parameter
to bfd_octets_per_byte.
* coff-i386.c (coff_i386_reloc): likewise.
* coff-mips.c (mips_reflo_reloc): likewise.
* coff-x86_64.c (coff_amd64_reloc): likewise.
* cofflink.c (_bfd_coff_link_input_bfd): likewise.
(_bfd_coff_reloc_link_order): likewise.
* elf.c (_bfd_elf_section_offset): likewise.
(_bfd_elf_make_section_from_shdr): likewise.
Set SEC_ELF_OCTETS for sections with names .gnu.build.attributes,
.debug*, .zdebug* and .note.gnu*.
* elf32-msp430.c (rl78_sym_diff_handler): Provide section parameter
to bfd_octets_per_byte.
* elf32-nds.c (nds32_elf_get_relocated_section_contents): likewise.
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): likewise.
* elf32-pru.c (pru_elf32_do_ldi32_relocate): likewise.
* elf32-s12z.c (opru18_reloc): likewise.
* elf32-sh.c (sh_elf_reloc): likewise.
* elf32-spu.c (spu_elf_rel9): likewise.
* elf32-xtensa.c (bfd_elf_xtensa_reloc): likewise
* elf64-ppc.c (ppc64_elf_brtaken_reloc): likewise.
(ppc64_elf_addr16_ha_reloc): likewise.
(ppc64_elf_toc64_reloc): likewise.
* elflink.c (bfd_elf_final_link): likewise.
(bfd_elf_perform_complex_relocation): likewise.
(elf_fixup_link_order): likewise.
(elf_link_input_bfd): likewise.
(elf_link_sort_relocs): likewise.
(elf_reloc_link_order): likewise.
(resolve_section): likewise.
* linker.c (_bfd_generic_reloc_link_order): likewise.
(bfd_generic_define_common_symbol): likewise.
(default_data_link_order): likewise.
(default_indirect_link_order): likewise.
* srec.c (srec_set_section_contents): likewise.
(srec_write_section): likewise.
* syms.c (_bfd_stab_section_find_nearest_line): likewise.
* reloc.c (_bfd_final_link_relocate): likewise.
(bfd_generic_get_relocated_section_contents): likewise.
(bfd_install_relocation): likewise.
For section which have SEC_ELF_OCTETS set, multiply output_base
and output_offset with bfd_octets_per_byte.
(bfd_perform_relocation): likewise.
include/
* coff/ti.h (GET_SCNHDR_SIZE, PUT_SCNHDR_SIZE, GET_SCN_SCNLEN),
(PUT_SCN_SCNLEN): Adjust bfd_octets_per_byte calls.
binutils/
* objdump.c (disassemble_data): Provide section parameter to
bfd_octets_per_byte.
(dump_section): likewise
(dump_section_header): likewise. Show SEC_ELF_OCTETS flag if set.
gas/
* as.h: Define SEC_OCTETS as SEC_ELF_OCTETS if OBJ_ELF.
* dwarf2dbg.c: (dwarf2_finish): Set section flag SEC_OCTETS for
.debug_line, .debug_info, .debug_abbrev, .debug_aranges, .debug_str
and .debug_ranges sections.
* write.c (maybe_generate_build_notes): Set section flag
SEC_OCTETS for .gnu.build.attributes section.
* frags.c (frag_now_fix): Don't divide by OCTETS_PER_BYTE if
SEC_OCTETS is set.
* symbols.c (resolve_symbol_value): Likewise.
ld/
* ldexp.c (fold_name): Provide section parameter to
bfd_octets_per_byte.
* ldlang (init_opb): New argument s. Set opb_shift to 0 if
SEC_ELF_OCTETS for the current section is set.
(print_input_section): Pass current section to init_opb.
(print_data_statement,print_reloc_statement,
print_padding_statement): Likewise.
(lang_check_section_addresses): Call init_opb for each
section.
(lang_size_sections_1,lang_size_sections_1,
lang_do_assignments_1): Likewise.
(lang_process): Pass NULL to init_opb.

39 files changed:
bfd/ChangeLog
bfd/archures.c
bfd/bfd-in2.h
bfd/bfd.c
bfd/binary.c
bfd/coff-arm.c
bfd/coff-i386.c
bfd/coff-mips.c
bfd/coff-x86_64.c
bfd/cofflink.c
bfd/elf.c
bfd/elf32-msp430.c
bfd/elf32-nds32.c
bfd/elf32-ppc.c
bfd/elf32-pru.c
bfd/elf32-s12z.c
bfd/elf32-sh.c
bfd/elf32-spu.c
bfd/elf32-xtensa.c
bfd/elf64-ppc.c
bfd/elflink.c
bfd/linker.c
bfd/reloc.c
bfd/section.c
bfd/srec.c
bfd/syms.c
binutils/ChangeLog
binutils/objdump.c
gas/ChangeLog
gas/as.h
gas/dwarf2dbg.c
gas/frags.c
gas/symbols.c
gas/write.c
include/ChangeLog
include/coff/ti.h
ld/ChangeLog
ld/ldexp.c
ld/ldlang.c

index a1ef734af6a882809113578786e2c2b5827c8c6e..c310fea4c72517d9f769de40268722ed7db77680 100644 (file)
@@ -1,3 +1,59 @@
+2019-11-25  Christian Eggers  <ceggers@gmx.de>
+
+       * section.c (struct bfd_section): New flag SEC_ELF_OCTETS.
+       * archures.c (bfd_octets_per_byte): New parameter sec.
+       If section is not NULL and SEC_ELF_OCTETS is set, one octet es
+       returned [ELF targets only].
+       * bfd.c (bfd_get_section_limit): Provide section parameter to
+       bfd_octets_per_byte.
+       * bfd-in2.h: regenerate.
+       * binary.c (binary_set_section_contents): Move call to
+       bfd_octets_per_byte into section loop. Provide section parameter
+       to bfd_octets_per_byte.
+       * coff-arm.c (coff_arm_reloc): Provide section parameter
+       to bfd_octets_per_byte.
+       * coff-i386.c (coff_i386_reloc): likewise.
+       * coff-mips.c (mips_reflo_reloc): likewise.
+       * coff-x86_64.c (coff_amd64_reloc): likewise.
+       * cofflink.c (_bfd_coff_link_input_bfd): likewise.
+       (_bfd_coff_reloc_link_order): likewise.
+       * elf.c (_bfd_elf_section_offset): likewise.
+       (_bfd_elf_make_section_from_shdr): likewise.
+       Set SEC_ELF_OCTETS for sections with names .gnu.build.attributes,
+       .debug*, .zdebug* and .note.gnu*.
+       * elf32-msp430.c (rl78_sym_diff_handler): Provide section parameter
+       to bfd_octets_per_byte.
+       * elf32-nds.c (nds32_elf_get_relocated_section_contents): likewise.
+       * elf32-ppc.c (ppc_elf_addr16_ha_reloc): likewise.
+       * elf32-pru.c (pru_elf32_do_ldi32_relocate): likewise.
+       * elf32-s12z.c (opru18_reloc): likewise.
+       * elf32-sh.c (sh_elf_reloc): likewise.
+       * elf32-spu.c (spu_elf_rel9): likewise.
+       * elf32-xtensa.c (bfd_elf_xtensa_reloc): likewise
+       * elf64-ppc.c (ppc64_elf_brtaken_reloc): likewise.
+       (ppc64_elf_addr16_ha_reloc): likewise.
+       (ppc64_elf_toc64_reloc): likewise.
+       * elflink.c (bfd_elf_final_link): likewise.
+       (bfd_elf_perform_complex_relocation): likewise.
+       (elf_fixup_link_order): likewise.
+       (elf_link_input_bfd): likewise.
+       (elf_link_sort_relocs): likewise.
+       (elf_reloc_link_order): likewise.
+       (resolve_section): likewise.
+       * linker.c (_bfd_generic_reloc_link_order): likewise.
+       (bfd_generic_define_common_symbol): likewise.
+       (default_data_link_order): likewise.
+       (default_indirect_link_order): likewise.
+       * srec.c (srec_set_section_contents): likewise.
+       (srec_write_section): likewise.
+       * syms.c (_bfd_stab_section_find_nearest_line): likewise.
+       * reloc.c (_bfd_final_link_relocate): likewise.
+       (bfd_generic_get_relocated_section_contents): likewise.
+       (bfd_install_relocation): likewise.
+       For section which have SEC_ELF_OCTETS set, multiply output_base
+       and output_offset with bfd_octets_per_byte.
+       (bfd_perform_relocation): likewise.
+
 2019-11-21  Alan Modra  <amodra@gmail.com>
 
        * elf32-arm.c (elf32_arm_size_stubs): Exclude dynamic library
index 569876eed0e86e4aaff066658378f9071d27d508..1e6611069c8adb8590a836b50487d7939a8aa333 100644 (file)
@@ -1379,7 +1379,8 @@ FUNCTION
        bfd_octets_per_byte
 
 SYNOPSIS
-       unsigned int bfd_octets_per_byte (const bfd *abfd);
+       unsigned int bfd_octets_per_byte (const bfd *abfd,
+                                         const asection *sec);
 
 DESCRIPTION
        Return the number of octets (8-bit quantities) per target byte
@@ -1388,10 +1389,17 @@ DESCRIPTION
 */
 
 unsigned int
-bfd_octets_per_byte (const bfd *abfd)
+bfd_octets_per_byte (const bfd *abfd, const asection *sec)
 {
-  return bfd_arch_mach_octets_per_byte (bfd_get_arch (abfd),
-                                       bfd_get_mach (abfd));
+  unsigned int opb = bfd_arch_mach_octets_per_byte (bfd_get_arch (abfd),
+                                                   bfd_get_mach (abfd));
+
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+      && sec != NULL
+      && (sec->flags & SEC_ELF_OCTETS) != 0)
+    opb = 1;
+
+  return opb;
 }
 
 /*
index a00dfa35150528dbbe3e411b71c93d457c4cdda7..80ff8e89b58413b15530da7967ea43d0c371f8a6 100644 (file)
@@ -992,6 +992,11 @@ typedef struct bfd_section
   /* This section contains vliw code.  This is for Toshiba MeP only.  */
 #define SEC_MEP_VLIW               0x20000000
 
+  /* All symbols, sizes and relocations in this section are octets
+     instead of bytes.  Required for DWARF debug sections as DWARF
+     information is organized in octets, not bytes.  */
+#define SEC_ELF_OCTETS             0x40000000
+
   /* Indicate that section has the no read flag set. This happens
      when memory read flag isn't set. */
 #define SEC_COFF_NOREAD            0x40000000
@@ -1993,7 +1998,8 @@ const bfd_arch_info_type *bfd_lookup_arch
 const char *bfd_printable_arch_mach
    (enum bfd_architecture arch, unsigned long machine);
 
-unsigned int bfd_octets_per_byte (const bfd *abfd);
+unsigned int bfd_octets_per_byte (const bfd *abfd,
+    const asection *sec);
 
 unsigned int bfd_arch_mach_octets_per_byte
    (enum bfd_architecture arch, unsigned long machine);
@@ -6854,7 +6860,8 @@ bfd_get_section_limit_octets (const bfd *abfd, const asection *sec)
 static inline bfd_size_type
 bfd_get_section_limit (const bfd *abfd, const asection *sec)
 {
-  return bfd_get_section_limit_octets (abfd, sec) / bfd_octets_per_byte (abfd);
+  return (bfd_get_section_limit_octets (abfd, sec)
+          / bfd_octets_per_byte (abfd, NULL));
 }
 
 /* Functions to handle insertion and deletion of a bfd's sections.  These
index e92213b543eb5daaec392fd93cf0a17accbf684a..c1f3fcadd69f0938ffd1548566e55c5ccf9b580c 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -492,7 +492,8 @@ CODE_FRAGMENT
 .static inline bfd_size_type
 .bfd_get_section_limit (const bfd *abfd, const asection *sec)
 .{
-.  return bfd_get_section_limit_octets (abfd, sec) / bfd_octets_per_byte (abfd);
+.  return (bfd_get_section_limit_octets (abfd, sec)
+.         / bfd_octets_per_byte (abfd, NULL));
 .}
 .
 .{* Functions to handle insertion and deletion of a bfd's sections.  These
index eb87d11b6ea0dd9d46fec43c6793a6cb92dd2c7c..06dfdf7b6efd134c3e8618905414cc0c5ff71c68 100644 (file)
@@ -230,7 +230,6 @@ binary_set_section_contents (bfd *abfd,
 
   if (! abfd->output_has_begun)
     {
-      unsigned int opb;
       bfd_boolean found_low;
       bfd_vma low;
       asection *s;
@@ -251,9 +250,10 @@ binary_set_section_contents (bfd *abfd,
            found_low = TRUE;
          }
 
-      opb = bfd_octets_per_byte (abfd);
       for (s = abfd->sections; s != NULL; s = s->next)
        {
+         unsigned int opb = bfd_octets_per_byte (abfd, s);
+
          s->filepos = (s->lma - low) * opb;
 
          /* Skip following warning check for sections that will not
index c9a7c098f541a9014ea0e11cb34e057e5dc617e9..e297df27e833975b84717f2e4ad8fdb127cc0434 100644 (file)
@@ -118,7 +118,7 @@ coff_arm_reloc (bfd *abfd,
 
       if (! bfd_reloc_offset_in_range (howto, abfd, input_section,
                                       reloc_entry->address
-                                      * bfd_octets_per_byte (abfd)))
+                                      * bfd_octets_per_byte (abfd, NULL)))
        return bfd_reloc_outofrange;
 
       switch (howto->size)
index 9810fd71be3a94635b539751956225ba95920737..f28eb8af0cd3cb40604debbaae93420907c0f6dd 100644 (file)
@@ -146,7 +146,7 @@ coff_i386_reloc (bfd *abfd,
 
       if (! bfd_reloc_offset_in_range (howto, abfd, input_section,
                                       reloc_entry->address
-                                      * bfd_octets_per_byte (abfd)))
+                                      * bfd_octets_per_byte (abfd, NULL)))
        return bfd_reloc_outofrange;
 
       switch (howto->size)
index c6fe679a6c68e56cdf02a9b1464b068c62fa8773..c9c7fc66ba229261f92c663da0562ebd0072aa7c 100644 (file)
@@ -507,7 +507,7 @@ mips_reflo_reloc (bfd *abfd ATTRIBUTE_UNUSED,
          if (! bfd_reloc_offset_in_range (reloc_entry->howto, abfd,
                                           input_section,
                                           reloc_entry->address
-                                          * bfd_octets_per_byte (abfd)))
+                                          * bfd_octets_per_byte (abfd, NULL)))
            return bfd_reloc_outofrange;
 
          /* Do the REFHI relocation.  Note that we actually don't
index c5e9a346ae063f16252576da5e492458a363b068..94fd7ac3e4f9c2d7e282d157f7a127d982dec809 100644 (file)
@@ -145,7 +145,7 @@ coff_amd64_reloc (bfd *abfd,
 
       if (! bfd_reloc_offset_in_range (howto, abfd, input_section,
                                       reloc_entry->address
-                                      * bfd_octets_per_byte (abfd)))
+                                      * bfd_octets_per_byte (abfd, NULL)))
        return bfd_reloc_outofrange;
 
       switch (howto->size)
index 2115e9c36ab0990b83e59636a520bc957186ef3a..23a8e6b2264c835e8bce75db54c7c527be0279b7 100644 (file)
@@ -2541,7 +2541,8 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
       /* Write out the modified section contents.  */
       if (secdata == NULL || secdata->stab_info == NULL)
        {
-         file_ptr loc = o->output_offset * bfd_octets_per_byte (output_bfd);
+         file_ptr loc = (o->output_offset
+                         * bfd_octets_per_byte (output_bfd, NULL));
          if (! bfd_set_section_contents (output_bfd, o->output_section,
                                          contents, loc, o->size))
            return FALSE;
@@ -2852,7 +2853,7 @@ _bfd_coff_reloc_link_order (bfd *output_bfd,
             (bfd *) NULL, (asection *) NULL, (bfd_vma) 0);
          break;
        }
-      loc = link_order->offset * bfd_octets_per_byte (output_bfd);
+      loc = link_order->offset * bfd_octets_per_byte (output_bfd, NULL);
       ok = bfd_set_section_contents (output_bfd, output_section, buf,
                                     loc, size);
       free (buf);
index a221bf0d04bd572e6bf1b752339ac42d8c8e3b63..43ef632fa7959ddba67560b3c6059d7ca0338bce 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1120,6 +1120,15 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
            p = NULL, n = 0;
          if (p != NULL && strncmp (name, p, n) == 0)
            flags |= SEC_DEBUGGING;
+
+         /* DWARF debug sections and ELF notes are organized in octets. */
+         if (strncmp (name, ".debug", 6) == 0 ||
+             strncmp (name, ".zdebug", 7) == 0 ||
+             strncmp (name, GNU_BUILD_ATTRS_SECTION_NAME, 21) == 0 ||
+             strncmp (name, ".note.gnu", 9) == 0)
+           {
+             flags |= SEC_ELF_OCTETS;
+           }
        }
     }
 
@@ -12054,7 +12063,8 @@ _bfd_elf_section_offset (bfd *abfd,
 
          /* address_size and sec->size are in octets.  Convert
             to bytes before subtracting the original offset.  */
-         offset = (sec->size - address_size) / bfd_octets_per_byte (abfd) - offset;
+         offset = ((sec->size - address_size)
+                   / bfd_octets_per_byte (abfd, NULL) - offset);
        }
       return offset;
     }
index d581dbcd9308a67e18fd3cb6b35ac2ca7014d176..7f675fcc34d20b6828c44a7ac46454e122af283f 100644 (file)
@@ -36,7 +36,7 @@ rl78_sym_diff_handler (bfd * abfd,
                       char ** error_message ATTRIBUTE_UNUSED)
 {
   bfd_size_type octets;
-  octets = reloc->address * bfd_octets_per_byte (abfd);
+  octets = reloc->address * bfd_octets_per_byte (abfd, NULL);
 
   /* Catch the case where bfd_install_relocation would return
      bfd_reloc_outofrange because the SYM_DIFF reloc is being used in a very
index 482fb290d14b5d154f5c311393f9d2ea4d7c11ee..a47d98e27084d1ae302278b098a9853b82235b1b 100644 (file)
@@ -13220,7 +13220,7 @@ nds32_elf_get_relocated_section_contents (bfd *abfd,
                = HOWTO (0, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL,
                         "unused", FALSE, 0, 0, FALSE);
 
-             off = (*parent)->address * bfd_octets_per_byte (input_bfd);
+             off = (*parent)->address * bfd_octets_per_byte (input_bfd, NULL);
              _bfd_clear_contents ((*parent)->howto, input_bfd,
                                   input_section, data, off);
              (*parent)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
index b9bcc506ae7e67c7976350f4dae04d42fd3b9028..0e6a3476d28b7c7addaa5cdf1a5f161d28b52746 100644 (file)
@@ -956,7 +956,7 @@ ppc_elf_addr16_ha_reloc (bfd *abfd,
            + input_section->output_section->vma);
   value >>= 16;
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, NULL);
   insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
   insn &= ~0x1fffc1;
   insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
index 054f1650f264a5930d4338a917c846bc4ff9b28d..98b2018621acd5b8f821bb728fb022466c24417e 100644 (file)
@@ -537,7 +537,7 @@ pru_elf32_do_ldi32_relocate (bfd *abfd, reloc_howto_type *howto,
                             bfd_vma symbol_value, bfd_vma addend)
 {
   bfd_signed_vma relocation;
-  bfd_size_type octets = offset * bfd_octets_per_byte (abfd);
+  bfd_size_type octets = offset * bfd_octets_per_byte (abfd, NULL);
   bfd_byte *location;
   unsigned long in1, in2;
 
@@ -557,7 +557,7 @@ pru_elf32_do_ldi32_relocate (bfd *abfd, reloc_howto_type *howto,
   BFD_ASSERT (!howto->pc_relative);
 
   /* A hacked-up version of _bfd_relocate_contents() follows.  */
-  location = data + offset * bfd_octets_per_byte (abfd);
+  location = data + offset * bfd_octets_per_byte (abfd, NULL);
 
   BFD_ASSERT (!howto->pc_relative);
 
index ba6498505a2a1b76d5b24001aa6bce98bb692840..8b3099c26ee3f98846404cc13de70fa5abe60160 100644 (file)
@@ -43,7 +43,8 @@ opru18_reloc (bfd *abfd, arelent *reloc_entry, struct bfd_symbol *symbol,
      is shifted one place to the left of where it would normally be.  See
      Appendix A.4 of the S12Z reference manual.  */
 
-  bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  bfd_size_type octets = (reloc_entry->address
+                         * bfd_octets_per_byte (abfd, NULL));
   bfd_vma result = bfd_get_24 (abfd, (unsigned char *) data + octets);
   bfd_vma val = bfd_asymbol_value (symbol);
 
index c10691e422ca50fc228c29b70d8bcb34679ed87d..3dc25eefe5937a4433db9c15c81caca7dbf9e90a 100644 (file)
@@ -254,7 +254,8 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
     return bfd_reloc_undefined;
 
   /* PR 17512: file: 9891ca98.  */
-  if (addr * bfd_octets_per_byte (abfd) + bfd_get_reloc_size (reloc_entry->howto)
+  if ((addr * bfd_octets_per_byte (abfd, NULL)
+       + bfd_get_reloc_size (reloc_entry->howto))
       > bfd_get_section_limit_octets (abfd, input_section))
     return bfd_reloc_outofrange;
 
index 9a1648f850fb64c789b6d3a554a774567ea7672b..6f8b32ab58d450a005da2f5f573e8d2b0f6806ad 100644 (file)
@@ -212,7 +212,7 @@ spu_elf_rel9 (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
 
   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, NULL);
 
   /* Get symbol value.  */
   val = 0;
index 306b18b4f265fad72ab81afdf1230e7c213b7f33..31e9530256d3a33c1e04a18a67d20a90c13b17cd 100644 (file)
@@ -2103,7 +2103,8 @@ bfd_elf_xtensa_reloc (bfd *abfd,
 {
   bfd_vma relocation;
   bfd_reloc_status_type flag;
-  bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  bfd_size_type octets = (reloc_entry->address
+                         * bfd_octets_per_byte (abfd, NULL));
   bfd_vma output_base = 0;
   reloc_howto_type *howto = reloc_entry->howto;
   asection *reloc_target_output_section;
index 4ece6fbde0195c5e4d9ebb702174bb2e53c421c6..5c7f32315fa57cb7fee28f82bfbe8e60fe04d2e9 100644 (file)
@@ -1405,7 +1405,7 @@ ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
            + input_section->output_section->vma);
   value = (bfd_signed_vma) value >> 16;
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, NULL);
   insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
   insn &= ~0x1fffc1;
   insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
@@ -1480,7 +1480,7 @@ ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
     return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
                                  input_section, output_bfd, error_message);
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, NULL);
   insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
   insn &= ~(0x01 << 21);
   r_type = reloc_entry->howto->type;
@@ -1630,7 +1630,7 @@ ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   if (TOCstart == 0)
     TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
 
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, NULL);
   bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
   return bfd_reloc_ok;
 }
index 9d7f69afda52472bfc63b783d60053cecb386452..824669a53649c81a1aa0273705b9710d2cb25a80 100644 (file)
@@ -8456,7 +8456,8 @@ resolve_section (const char *name,
        {
          if (strncmp (".end", name + len, 4) == 0)
            {
-             *result = curr->vma + curr->size / bfd_octets_per_byte (abfd);
+             *result = (curr->vma
+                        + curr->size / bfd_octets_per_byte (abfd, NULL));
              return TRUE;
            }
 
@@ -8778,7 +8779,8 @@ bfd_elf_perform_complex_relocation (bfd *input_bfd,
     shift = (8 * wordsz) - (start + len);
 
   x = get_value (wordsz, chunksz, input_bfd,
-                contents + rel->r_offset * bfd_octets_per_byte (input_bfd));
+                contents
+                + rel->r_offset * bfd_octets_per_byte (input_bfd, NULL));
 
 #ifdef DEBUG
   printf ("Doing complex reloc: "
@@ -8811,7 +8813,7 @@ bfd_elf_perform_complex_relocation (bfd *input_bfd,
          (unsigned long) ((relocation & mask) << shift), (unsigned long) x);
 #endif
   put_value (wordsz, chunksz, input_bfd, x,
-            contents + rel->r_offset * bfd_octets_per_byte (input_bfd));
+            contents + rel->r_offset * bfd_octets_per_byte (input_bfd, NULL));
   return r;
 }
 
@@ -9175,7 +9177,7 @@ elf_link_sort_relocs (bfd *abfd, struct bfd_link_info *info, asection **psec)
   struct elf_link_sort_rela *sq;
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   int i2e = bed->s->int_rels_per_ext_rel;
-  unsigned int opb = bfd_octets_per_byte (abfd);
+  unsigned int opb = bfd_octets_per_byte (abfd, NULL);
   void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
   void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
   struct bfd_link_order *lo;
@@ -11303,7 +11305,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
                file_ptr offset = (file_ptr) o->output_offset;
                bfd_size_type todo = o->size;
 
-               offset *= bfd_octets_per_byte (output_bfd);
+               offset *= bfd_octets_per_byte (output_bfd, NULL);
 
                if ((o->flags & SEC_ELF_REVERSE_COPY))
                  {
@@ -11465,7 +11467,7 @@ elf_reloc_link_order (bfd *output_bfd,
 
       ok = bfd_set_section_contents (output_bfd, output_section, buf,
                                     link_order->offset
-                                    * bfd_octets_per_byte (output_bfd),
+                                    * bfd_octets_per_byte (output_bfd, NULL),
                                     size);
       free (buf);
       if (! ok)
@@ -11633,7 +11635,7 @@ elf_fixup_link_order (bfd *abfd, asection *o)
       s = sections[n]->u.indirect.section;
       mask = ~(bfd_vma) 0 << s->alignment_power;
       offset = (offset + ~mask) & mask;
-      s->output_offset = offset / bfd_octets_per_byte (abfd);
+      s->output_offset = offset / bfd_octets_per_byte (abfd, NULL);
       sections[n]->offset = offset;
       offset += sections[n]->size;
     }
@@ -12857,7 +12859,8 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
              if (! bfd_set_section_contents (abfd, o->output_section,
                                              o->contents,
                                              (file_ptr) o->output_offset
-                                             * bfd_octets_per_byte (abfd),
+                                             * bfd_octets_per_byte (abfd,
+                                                                    NULL),
                                              o->size))
                goto error_return;
            }
index 382b69d8c3d62079fbd6ffd8392acf2fbb6064ae..b247cf589b72a6da486dadfc0573ac611c5d95d7 100644 (file)
@@ -2402,7 +2402,7 @@ _bfd_generic_reloc_link_order (bfd *abfd,
             NULL, NULL, 0);
          break;
        }
-      loc = link_order->offset * bfd_octets_per_byte (abfd);
+      loc = link_order->offset * bfd_octets_per_byte (abfd, sec);
       ok = bfd_set_section_contents (abfd, sec, buf, loc, size);
       free (buf);
       if (! ok)
@@ -2518,7 +2518,7 @@ default_data_link_order (bfd *abfd,
        }
     }
 
-  loc = link_order->offset * bfd_octets_per_byte (abfd);
+  loc = link_order->offset * bfd_octets_per_byte (abfd, sec);
   result = bfd_set_section_contents (abfd, sec, fill, loc, size);
 
   if (fill != link_order->u.data.contents)
@@ -2655,7 +2655,8 @@ default_indirect_link_order (bfd *output_bfd,
     }
 
   /* Output the section contents.  */
-  loc = input_section->output_offset * bfd_octets_per_byte (output_bfd);
+  loc = (input_section->output_offset
+        * bfd_octets_per_byte (output_bfd, output_section));
   if (! bfd_set_section_contents (output_bfd, output_section,
                                  new_contents, loc, input_section->size))
     goto error_return;
@@ -3099,7 +3100,7 @@ bfd_generic_define_common_symbol (bfd *output_bfd,
 
   /* Increase the size of the section to align the common symbol.
      The alignment must be a power of two.  */
-  alignment = bfd_octets_per_byte (output_bfd) << power_of_two;
+  alignment = bfd_octets_per_byte (output_bfd, section) << power_of_two;
   BFD_ASSERT (alignment != 0 && (alignment & -alignment) == alignment);
   section->size += alignment - 1;
   section->size &= -alignment;
index cc842d7514f3864eebab9827935d503faf6b404c..e01cb5182ec2a1e4d3d5675662d791b85d0fa5fa 100644 (file)
@@ -722,7 +722,7 @@ bfd_perform_relocation (bfd *abfd,
     return bfd_reloc_undefined;
 
   /* Is the address of the relocation really within the section?  */
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, input_section);
   if (!bfd_reloc_offset_in_range (howto, abfd, input_section, octets))
     return bfd_reloc_outofrange;
 
@@ -744,7 +744,14 @@ bfd_perform_relocation (bfd *abfd,
   else
     output_base = reloc_target_output_section->vma;
 
-  relocation += output_base + symbol->section->output_offset;
+  /* For sections where relocations are in octets, output_base and
+     output_offset must also be converted to octets.  */
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+      && (symbol->section->flags & SEC_ELF_OCTETS))
+    relocation += ((output_base + symbol->section->output_offset)
+                  * bfd_octets_per_byte (abfd, NULL));
+  else
+    relocation += output_base + symbol->section->output_offset;
 
   /* Add in supplied addend.  */
   relocation += reloc_entry->addend;
@@ -1052,7 +1059,7 @@ bfd_install_relocation (bfd *abfd,
      it will have been checked in `bfd_perform_relocation already'.  */
 
   /* Is the address of the relocation really within the section?  */
-  octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+  octets = reloc_entry->address * bfd_octets_per_byte (abfd, input_section);
   if (!bfd_reloc_offset_in_range (howto, abfd, input_section, octets))
     return bfd_reloc_outofrange;
 
@@ -1073,7 +1080,14 @@ bfd_install_relocation (bfd *abfd,
   else
     output_base = reloc_target_output_section->vma;
 
-  relocation += output_base + symbol->section->output_offset;
+  /* For sections where relocations are in octets, output_base and
+     output_offset must also be converted to octets.  */
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+      && (symbol->section->flags & SEC_ELF_OCTETS))
+    relocation += ((output_base + symbol->section->output_offset)
+                  * bfd_octets_per_byte (abfd, NULL));
+  else
+    relocation += output_base + symbol->section->output_offset;
 
   /* Add in supplied addend.  */
   relocation += reloc_entry->addend;
@@ -1337,7 +1351,8 @@ _bfd_final_link_relocate (reloc_howto_type *howto,
                          bfd_vma addend)
 {
   bfd_vma relocation;
-  bfd_size_type octets = address * bfd_octets_per_byte (input_bfd);
+  bfd_size_type octets = (address
+                         * bfd_octets_per_byte (input_bfd, input_section));
 
   /* Sanity check the address.  */
   if (!bfd_reloc_offset_in_range (howto, input_bfd, input_section, octets))
@@ -1369,7 +1384,9 @@ _bfd_final_link_relocate (reloc_howto_type *howto,
 
   return _bfd_relocate_contents (howto, input_bfd, relocation,
                                 contents
-                                + address * bfd_octets_per_byte (input_bfd));
+                                + address
+                                * bfd_octets_per_byte (input_bfd,
+                                                       input_section));
 }
 
 /* Relocate a given location using a given value and howto.  */
@@ -8346,7 +8363,8 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
                = HOWTO (0, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL,
                         "unused", FALSE, 0, 0, FALSE);
 
-             off = (*parent)->address * bfd_octets_per_byte (input_bfd);
+             off = ((*parent)->address
+                    * bfd_octets_per_byte (input_bfd, input_section));
              _bfd_clear_contents ((*parent)->howto, input_bfd,
                                   input_section, data, off);
              (*parent)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
index 34e08aef57eb9e02559100bb324d7df410b55923..470792de144e8c47b025d7f995462b335fbbe166 100644 (file)
@@ -351,6 +351,11 @@ CODE_FRAGMENT
 .  {* This section contains vliw code.  This is for Toshiba MeP only.  *}
 .#define SEC_MEP_VLIW               0x20000000
 .
+.  {* All symbols, sizes and relocations in this section are octets
+.     instead of bytes.  Required for DWARF debug sections as DWARF
+.     information is organized in octets, not bytes.  *}
+.#define SEC_ELF_OCTETS             0x40000000
+.
 .  {* Indicate that section has the no read flag set. This happens
 .     when memory read flag isn't set. *}
 .#define SEC_COFF_NOREAD            0x40000000
index 218276837cc19a58abd322c1bb1f85914cf5215d..449d88c6b0868bcf2f4c48d346f2b495e9a60453 100644 (file)
@@ -885,7 +885,7 @@ srec_set_section_contents (bfd *abfd,
                           file_ptr offset,
                           bfd_size_type bytes_to_do)
 {
-  int opb = bfd_octets_per_byte (abfd);
+  int opb = bfd_octets_per_byte (abfd, NULL);
   tdata_type *tdata = abfd->tdata.srec_data;
   srec_data_list_type *entry;
 
@@ -1053,7 +1053,8 @@ srec_write_section (bfd *abfd,
       if (octets_this_chunk > _bfd_srec_len)
        octets_this_chunk = _bfd_srec_len;
 
-      address = list->where + octets_written / bfd_octets_per_byte (abfd);
+      address = list->where + (octets_written
+                              / bfd_octets_per_byte (abfd, NULL));
 
       if (! srec_write_record (abfd,
                               tdata->type,
index 146f674a1304c38b8dedda178995cad8f922a6f1..ec7d2c8dbafc720e6a8125bc52358e77d39c9611 100644 (file)
@@ -1090,7 +1090,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                  || r->howto->pc_relative
                  || r->howto->bitpos != 0
                  || r->howto->dst_mask != 0xffffffff
-                 || r->address * bfd_octets_per_byte (abfd) + 4 > stabsize)
+                 || (r->address * bfd_octets_per_byte (abfd, NULL) + 4
+                     > stabsize))
                {
                  _bfd_error_handler
                    (_("unsupported .stab relocation"));
@@ -1101,12 +1102,13 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                }
 
              val = bfd_get_32 (abfd, info->stabs
-                               + r->address * bfd_octets_per_byte (abfd));
+                               + (r->address
+                                  * bfd_octets_per_byte (abfd, NULL)));
              val &= r->howto->src_mask;
              sym = *r->sym_ptr_ptr;
              val += sym->value + sym->section->vma + r->addend;
              bfd_put_32 (abfd, (bfd_vma) val, info->stabs
-                         + r->address * bfd_octets_per_byte (abfd));
+                         + r->address * bfd_octets_per_byte (abfd, NULL));
            }
        }
 
index c4f7e3d5b3d126a9dd19fed4b83bfb3227ba7d44..7c0d0feadcabf0e7f073202a2b801dd388b1c23c 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-25  Christian Eggers  <ceggers@gmx.de>
+
+       * objdump.c (disassemble_data): Provide section parameter to
+       bfd_octets_per_byte.
+       (dump_section): likewise
+       (dump_section_header): likewise. Show SEC_ELF_OCTETS flag if set.
+
 2019-11-21  Alan Modra  <amodra@gmail.com>
 
        PR 273
index 1be3b232353585a79505adc9d2df5db444f3c52d..115f1fc000421d723230747990bff3597ea8b0dd 100644 (file)
@@ -532,7 +532,7 @@ static void
 dump_section_header (bfd *abfd, asection *section, void *data)
 {
   char *comma = "";
-  unsigned int opb = bfd_octets_per_byte (abfd);
+  unsigned int opb = bfd_octets_per_byte (abfd, section);
   int longest_section_name = *((int *) data);
 
   /* Ignore linker created section.  See elfNN_ia64_object_p in
@@ -584,7 +584,10 @@ dump_section_header (bfd *abfd, asection *section, void *data)
       PF (SEC_COFF_NOREAD, "NOREAD");
     }
   else if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
-    PF (SEC_ELF_PURECODE, "PURECODE");
+    {
+      PF (SEC_ELF_OCTETS, "OCTETS");
+      PF (SEC_ELF_PURECODE, "PURECODE");
+    }
   PF (SEC_THREAD_LOCAL, "THREAD_LOCAL");
   PF (SEC_GROUP, "GROUP");
   if (bfd_get_arch (abfd) == bfd_arch_mep)
@@ -2682,7 +2685,7 @@ disassemble_data (bfd *abfd)
   disasm_info.arch = bfd_get_arch (abfd);
   disasm_info.mach = bfd_get_mach (abfd);
   disasm_info.disassembler_options = disassembler_options;
-  disasm_info.octets_per_byte = bfd_octets_per_byte (abfd);
+  disasm_info.octets_per_byte = bfd_octets_per_byte (abfd, NULL);
   disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
   disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
   disasm_info.disassembler_needs_relocs = FALSE;
@@ -3459,7 +3462,7 @@ dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED)
   bfd_vma addr_offset;
   bfd_vma start_offset;
   bfd_vma stop_offset;
-  unsigned int opb = bfd_octets_per_byte (abfd);
+  unsigned int opb = bfd_octets_per_byte (abfd, section);
   /* Bytes per line.  */
   const int onaline = 16;
   char buf[64];
index 1751b00101b4851c9b2ec408e3416e54fbb4d105..b3affbbaa170fd73c5cb1d8823b244a5998f25f5 100644 (file)
@@ -1,3 +1,15 @@
+2019-11-25  Christian Eggers  <ceggers@gmx.de>
+
+       * as.h: Define SEC_OCTETS as SEC_ELF_OCTETS if OBJ_ELF.
+       * dwarf2dbg.c: (dwarf2_finish): Set section flag SEC_OCTETS for
+       .debug_line, .debug_info, .debug_abbrev, .debug_aranges, .debug_str
+       and .debug_ranges sections.
+       * write.c (maybe_generate_build_notes): Set section flag
+       SEC_OCTETS for .gnu.build.attributes section.
+       * frags.c (frag_now_fix): Don't divide by OCTETS_PER_BYTE if
+       SEC_OCTETS is set.
+       * symbols.c (resolve_symbol_value): Likewise.
+
 2019-11-25  Christian Eggers  <ceggers@gmx.de>
 
        * dwarf2dbg.c (out_set_addr): Revert 2019-03-13 change.
index 3c37519c1bf13874a0de7db120ee5348fd7eaf99..3d492d4eb1f6f03940b7b2097bcc4dd59a2293e5 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -649,4 +649,11 @@ COMMON int flag_sectname_subst;
  #error "Octets per byte conflicts with its power-of-two definition!"
 #endif
 
+#if defined OBJ_ELF || defined OBJ_MAYBE_ELF
+/* On ELF platforms, mark debug sections with SEC_ELF_OCTETS */
+#define SEC_OCTETS (IS_ELF ? SEC_ELF_OCTETS : 0)
+#else
+#define SEC_OCTETS 0
+#endif
+
 #endif /* GAS */
index dce96033df7f74378d07a3ca0cb310c72f5ef869..001e2a16ad190043a2f7b08bedc4608cf36d1313 100644 (file)
@@ -2215,7 +2215,7 @@ dwarf2_finish (void)
 
   /* Create and switch to the line number section.  */
   line_seg = subseg_new (".debug_line", 0);
-  bfd_set_section_flags (line_seg, SEC_READONLY | SEC_DEBUGGING);
+  bfd_set_section_flags (line_seg, SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
 
   /* For each subsection, chain the debug entries together.  */
   for (s = all_segs; s; s = s->next)
@@ -2261,11 +2261,15 @@ dwarf2_finish (void)
       aranges_seg = subseg_new (".debug_aranges", 0);
       str_seg = subseg_new (".debug_str", 0);
 
-      bfd_set_section_flags (info_seg, SEC_READONLY | SEC_DEBUGGING);
-      bfd_set_section_flags (abbrev_seg, SEC_READONLY | SEC_DEBUGGING);
-      bfd_set_section_flags (aranges_seg, SEC_READONLY | SEC_DEBUGGING);
-      bfd_set_section_flags (str_seg, (SEC_READONLY | SEC_DEBUGGING
-                                      | SEC_MERGE | SEC_STRINGS));
+      bfd_set_section_flags (info_seg,
+                             SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
+      bfd_set_section_flags (abbrev_seg,
+                             SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
+      bfd_set_section_flags (aranges_seg,
+                             SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
+      bfd_set_section_flags (str_seg,
+                             SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS
+                                      | SEC_MERGE | SEC_STRINGS);
       str_seg->entsize = 1;
 
       record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
@@ -2275,7 +2279,8 @@ dwarf2_finish (void)
       else
        {
          ranges_seg = subseg_new (".debug_ranges", 0);
-         bfd_set_section_flags (ranges_seg, SEC_READONLY | SEC_DEBUGGING);
+         bfd_set_section_flags (ranges_seg,
+                                SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
          record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);
          out_debug_ranges (ranges_seg);
        }
index 2f21b9db200d8301b300d0c0dd58fad13c467036..f35cc80a386ed0dd6e04af32e9ba7cb520ecb437 100644 (file)
@@ -395,7 +395,12 @@ frag_now_fix_octets (void)
 addressT
 frag_now_fix (void)
 {
-  return frag_now_fix_octets () / OCTETS_PER_BYTE;
+  /* Symbols whose section has SEC_ELF_OCTETS set,
+     resolve to octets instead of target bytes.  */
+  if (now_seg->flags & SEC_OCTETS)
+    return frag_now_fix_octets ();
+  else
+    return frag_now_fix_octets () / OCTETS_PER_BYTE;
 }
 
 void
index cff24059e6c7b9b125c0ffb21e7525b510b43d0f..857a3e6c5cc44eb921ab3f63937d54e4420a06c7 100644 (file)
@@ -1217,7 +1217,13 @@ resolve_symbol_value (symbolS *symp)
       if (local_symbol_resolved_p (locsym))
        return final_val;
 
-      final_val += local_symbol_get_frag (locsym)->fr_address / OCTETS_PER_BYTE;
+      /* Symbols whose section has SEC_ELF_OCTETS set,
+        resolve to octets instead of target bytes. */
+      if (locsym->lsy_section->flags & SEC_OCTETS)
+       final_val += local_symbol_get_frag (locsym)->fr_address;
+      else
+       final_val += (local_symbol_get_frag (locsym)->fr_address
+                     / OCTETS_PER_BYTE);
 
       if (finalize_syms)
        {
@@ -1330,7 +1336,12 @@ resolve_symbol_value (symbolS *symp)
          /* Fall through.  */
 
        case O_constant:
-         final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
+         /* Symbols whose section has SEC_ELF_OCTETS set,
+            resolve to octets instead of target bytes. */
+         if (symp->bsym->section->flags & SEC_OCTETS)
+           final_val += symp->sy_frag->fr_address;
+         else
+           final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE;
          if (final_seg == expr_section)
            final_seg = absolute_section;
          /* Fall through.  */
index 8f7786eb367cc646e031cd8f46e8a00914e5336f..d5da41850cc428bb4f716f079de339b7dbb1f8ff 100644 (file)
@@ -1960,7 +1960,8 @@ maybe_generate_build_notes (void)
   /* Create a GNU Build Attribute section.  */
   sec = subseg_new (GNU_BUILD_ATTRS_SECTION_NAME, FALSE);
   elf_section_type (sec) = SHT_NOTE;
-  bfd_set_section_flags (sec, SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA);
+  bfd_set_section_flags (sec, (SEC_READONLY | SEC_HAS_CONTENTS | SEC_DATA
+                              | SEC_OCTETS));
   bfd_set_section_alignment (sec, 2);
 
   /* Work out the size of the notes that we will create,
index 3ead0119101910a5c222af82b99efd0bf6772f50..47bb86cf712809dade16d6558c6095f4783929d7 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-25  Alan Modra  <amodra@gmail.com>
+
+       * coff/ti.h (GET_SCNHDR_SIZE, PUT_SCNHDR_SIZE, GET_SCN_SCNLEN),
+       (PUT_SCN_SCNLEN): Adjust bfd_octets_per_byte calls.
+
 2019-11-22  Mihail Ionescu  <mihail.ionescu@arm.com>
 
        * opcode/arm.h (ARM_EXT2_CRC): New extension feature
@@ -26,7 +31,7 @@
        instructions that do not require special handling.
 
 2019-11-07  Mihail Ionescu  <mihail.ionescu@arm.com>
-2019-11-07  Matthew Malcomson  <matthew.malcomson@arm.com>
+           Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * opcode/arm.h (ARM_EXT2_V8_6A, ARM_AEXT2_V8_6A,
        ARM_ARCH_V8_6A): New.
@@ -34,7 +39,7 @@
        (ARM_AEXT2_V8_6A): Include above macro in definition.
 
 2019-11-07  Mihail Ionescu  <mihail.ionescu@arm.com>
-2019-11-07  Matthew Malcomson  <matthew.malcomson@arm.com>
+           Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * opcode/aarch64.h (AARCH64_FEATURE_BFLOAT16): New feature macros.
        (AARCH64_ARCH_V8_6): Include BFloat16 feature macros.
@@ -45,7 +50,7 @@
        instructions to support the movprfx constraint.
 
 2019-11-07  Mihail Ionescu  <mihail.ionescu@arm.com>
-2019-11-07  Matthew Malcomson  <matthew.malcomson@arm.com>
+           Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * opcode/aarch64.h (AARCH64_FEATURE_V8_6): New.
        (AARCH64_ARCH_V8_6): New.
index 0e8f5324967c99c180f7e6ac90b493aafc1b2178..17bac8c0fc5d3a19272fc7f51fdaf5eb68e093e3 100644 (file)
@@ -313,9 +313,9 @@ struct external_scnhdr {
 /* TI COFF stores section size as number of bytes (address units, not octets),
    so adjust to be number of octets, which is what BFD expects */ 
 #define GET_SCNHDR_SIZE(ABFD, SZP) \
-  (H_GET_32 (ABFD, SZP) * bfd_octets_per_byte (ABFD))
+  (H_GET_32 (ABFD, SZP) * bfd_octets_per_byte (ABFD, NULL))
 #define PUT_SCNHDR_SIZE(ABFD, SZ, SZP) \
-  H_PUT_32 (ABFD, (SZ) / bfd_octets_per_byte (ABFD), SZP)
+  H_PUT_32 (ABFD, (SZ) / bfd_octets_per_byte (ABFD, NULL), SZP)
 
 #define COFF_ADJUST_SCNHDR_IN_POST(ABFD, EXT, INT) \
   do                                                                   \
@@ -471,9 +471,9 @@ union external_auxent {
 
 /* section lengths are in target bytes (not host bytes) */
 #define GET_SCN_SCNLEN(ABFD, EXT) \
-  (H_GET_32 (ABFD, (EXT)->x_scn.x_scnlen) * bfd_octets_per_byte (ABFD))
+  (H_GET_32 (ABFD, (EXT)->x_scn.x_scnlen) * bfd_octets_per_byte (ABFD, NULL))
 #define PUT_SCN_SCNLEN(ABFD, INT, EXT) \
-  H_PUT_32 (ABFD, (INT) / bfd_octets_per_byte (ABFD), (EXT)->x_scn.x_scnlen)
+  H_PUT_32 (ABFD, (INT) / bfd_octets_per_byte (ABFD, NULL), (EXT)->x_scn.x_scnlen)
 
 /* lnsz size is in bits in COFF file, in bytes in BFD */
 #define GET_LNSZ_SIZE(abfd, ext) \
index 6498fb0e7ec3b8fbf883b2def1809384a41793f6..e969c0f1f739d6cdb9b2a17ab98b21330ceca205 100644 (file)
@@ -1,3 +1,18 @@
+2019-11-25  Christian Eggers  <ceggers@gmx.de>
+
+       * ldexp.c (fold_name): Provide section parameter to
+       bfd_octets_per_byte.
+       * ldlang (init_opb): New argument s. Set opb_shift to 0 if
+       SEC_ELF_OCTETS for the current section is set.
+       (print_input_section): Pass current section to init_opb.
+       (print_data_statement,print_reloc_statement,
+       print_padding_statement): Likewise.
+       (lang_check_section_addresses): Call init_opb for each
+       section.
+       (lang_size_sections_1,lang_size_sections_1,
+       lang_do_assignments_1): Likewise.
+       (lang_process): Pass NULL to init_opb.
+
 2019-11-22  Nick Clifton  <nickc@redhat.com>
 
        * ld.texi (Output Section Discarding): Add note indicating that
index 23ee5c59c280128e22efac5232a18fc730431420..8327a3f2bc14b9ceaa75d5d40a6a19a26aac8be6 100644 (file)
@@ -852,7 +852,7 @@ fold_name (etree_type *tree)
 
              if (tree->type.node_code == SIZEOF)
                val = (os->bfd_section->size
-                      / bfd_octets_per_byte (link_info.output_bfd));
+                      / bfd_octets_per_byte (link_info.output_bfd, NULL));
              else
                val = (bfd_vma)1 << os->bfd_section->alignment_power;
 
index eedcb7f4050c82b8cb12818551cc2a582fd3bcd2..3bcab7a876e3036cf69c14daeeed0a0c7ef06845 100644 (file)
@@ -3440,10 +3440,17 @@ ldlang_open_output (lang_statement_union_type *statement)
 }
 
 static void
-init_opb (void)
+init_opb (asection *s)
 {
   unsigned x = bfd_arch_mach_octets_per_byte (ldfile_output_architecture,
                                              ldfile_output_machine);
+  if (s != NULL)
+    {
+      if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+         && (s->flags & SEC_ELF_OCTETS))
+       x = 1;
+    }
+
   opb_shift = 0;
   if (x > 1)
     while ((x & 1) == 0)
@@ -4626,7 +4633,7 @@ print_input_section (asection *i, bfd_boolean is_discarded)
   int len;
   bfd_vma addr;
 
-  init_opb ();
+  init_opb (i);
 
   print_space ();
   minfo ("%s", i->name);
@@ -4707,7 +4714,7 @@ print_data_statement (lang_data_statement_type *data)
   bfd_size_type size;
   const char *name;
 
-  init_opb ();
+  init_opb (data->output_section);
   for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
     print_space ();
 
@@ -4776,7 +4783,7 @@ print_reloc_statement (lang_reloc_statement_type *reloc)
   bfd_vma addr;
   bfd_size_type size;
 
-  init_opb ();
+  init_opb (reloc->output_section);
   for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
     print_space ();
 
@@ -4806,7 +4813,7 @@ print_padding_statement (lang_padding_statement_type *s)
   int len;
   bfd_vma addr;
 
-  init_opb ();
+  init_opb (s->output_section);
   minfo (" *fill*");
 
   len = sizeof " *fill*" - 1;
@@ -5276,6 +5283,7 @@ lang_check_section_addresses (void)
   for (p = NULL, i = 0; i < count; i++)
     {
       s = sections[i].sec;
+      init_opb (s);
       if ((s->flags & SEC_LOAD) != 0)
        {
          s_start = s->lma;
@@ -5326,6 +5334,7 @@ lang_check_section_addresses (void)
       for (p = NULL, i = 0; i < count; i++)
        {
          s = sections[i].sec;
+         init_opb (s);
          s_start = s->vma;
          s_end = s_start + TO_ADDR (s->size) - 1;
 
@@ -5450,6 +5459,7 @@ lang_size_sections_1
            int section_alignment = 0;
 
            os = &s->output_section_statement;
+           init_opb (os->bfd_section);
            if (os->constraint == -1)
              break;
 
@@ -6191,6 +6201,7 @@ lang_do_assignments_1 (lang_statement_union_type *s,
 
            os = &(s->output_section_statement);
            os->after_end = *found_end;
+           init_opb (os->bfd_section);
            if (os->bfd_section != NULL && !os->ignored)
              {
                if ((os->bfd_section->flags & SEC_ALLOC) != 0)
@@ -7622,7 +7633,7 @@ lang_process (void)
 
   /* Open the output file.  */
   lang_for_each_statement (ldlang_open_output);
-  init_opb ();
+  init_opb (NULL);
 
   ldemul_create_output_section_statements ();
 
This page took 0.063319 seconds and 4 git commands to generate.