Bug 28054 - SEC_ELF_OCTETS not set for ".debug_*" sections causing invalid relocs for targets with OCTETS_PER_BYTE > 1
Summary: SEC_ELF_OCTETS not set for ".debug_*" sections causing invalid relocs for tar...
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2021-07-04 15:43 UTC by Tucker
Modified: 2021-07-13 14:49 UTC (History)
1 user (show)

See Also:
Last reconfirmed:

Possible patch that sets the flags in obj_elf_change_section (478 bytes, patch)
2021-07-04 15:43 UTC, Tucker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tucker 2021-07-04 15:43:53 UTC
Created attachment 13535 [details]
Possible patch that sets the flags in obj_elf_change_section

For targets where OCTETS_PER_BYTE > 1, invalid relocs & fixups are generated in the DWARF2 ".debug_*" sections because SEC_ELF_OCTETS is not set when these sections are created.

Since SEC_ELF_OCTETS is not set various functions do not compute proper offset and addresses in these sections. e.g. bfd_octets_per_byte, frag_now_fix, resolve_symbol_value, bfd_install_relocation, bfd_perform_relocation.

Currently the only place this flag is set is in _bfd_elf_make_section_from_shdr.

Attached is a patch that mimics the code from _bfd_elf_make_section_from_shdr in obj_elf_change_section to ensure these flags are set.
Comment 1 cvs-commit@gcc.gnu.org 2021-07-12 16:14:34 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:


commit ef744040b49e92ecd3de3ae3b94c8f85020111c3
Author: Tucker <tuckkern@sourceware@gmail.com>
Date:   Mon Jul 12 17:12:13 2021 +0100

    Add the SEC_ELF_OCTETS flag to debug sections created by the assembler.
            PR 28054
    gas     * config/obj-elf.c (obj_elf_change_section): Set the
            SEF_ELF_OCTETS flag on debug sections.
Comment 2 Nick Clifton 2021-07-12 16:26:23 UTC
Hi Tucker,

  I have applied half of your patch.  During testing I found that setting
  the SEC_DEBUGGING flag causes binutils testsuite regressions for the FT32
  and MSP430 targets.  I am not entirely sure why, but I suspect that it
  is because these targets then start generating relocs to set values in
  the .debug_info and .debug_line sections, and these relocs are either 
  wrong, or not implemented properly.

  So I have applied the part that sets SEC_ELF_OCTETS, but not the part
  that sets SEC_ELF_DEBUGGING.

  One day, in my copious free time, I will investigate the SEC_DEBUGGING
  issue further. :-)

Comment 3 Tucker 2021-07-13 14:49:04 UTC
Hi Nick,

Thanks for the quick action.

Ah, maybe I can take a look at those regressions for you. A cursory looks tells me it's likely in FT32's "relaxable_section" function which appears to kick out any sections marked as SEC_DEBUGGING.

For MSP430, it's probably the implementation of TC_FORCE_RELOCATION_SUB_SAME which does a similar check for SEC_DEBUGGING.

Either way, having SEC_ELF_OCTETS set properly lets me keep going.