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.
The master branch has been updated by Nick Clifton <firstname.lastname@example.org>:
Author: Tucker <tuckkern@email@example.com>
Date: Mon Jul 12 17:12:13 2021 +0100
Add the SEC_ELF_OCTETS flag to debug sections created by the assembler.
gas * config/obj-elf.c (obj_elf_change_section): Set the
SEF_ELF_OCTETS flag on debug sections.
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. :-)
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.