[PATCH v3 0/2] Fix several mix up between octets and bytes in ELF program headers
Christian Eggers
ceggers@gmx.de
Sun Feb 16 08:22:00 GMT 2020
Dear Alan,
On Wed, 18 Dec 2019 12:42:57 +1030, Alan Modra wrote:
> I'm also wondering about relocations, symbols and dynamic tags with
> address values.
I'm unsure whether I can answer this questions correctly because currently "it
simply works for me". But I will try...
> Does r_offset specify bytes or octets in the ELF file?
As far I can see, struct elf_internal_rela::r_offset is set from
struct reloc_cache_entry::address [1].
from my gas/config/tc-sdma.c:
arelent *
sdma_cgen_tc_gen_reloc (asection *section, fixS *fixP)
{
arelent *reloc = gas_cgen_tc_gen_reloc(section, fixP);
if (! (section->flags & SEC_ELF_OCTETS))
{
reloc->address >>= OCTETS_PER_BYTE_POWER;
}
return reloc;
}
So it depends on whether SEC_ELF_OCTETS is set for the section where the
relocation is installed. Particularly relocations offsets inside .debug_line
are often not aligned to target bytes, see we need octets here.
> If octets, then do we convert in elf_swap_reloca_in/out making
> internal r_offset in bytes which should be most convenient since it is
> often used with section vma?
I think that no further conversion should be done here.
> How about r_addend
Usually in *bytes*, but for sections like .debug_str, *octets* are required.
So it depends on whether SEC_ELF_OCTETS is set for the section of the symbol.
> and st_value?
debugging through gas showed that struct elf_internal_sym::st_value is set
from struct bfd_symbol::value [2] which in turn is set from struct
expressionS::X_add_number [3].
For sections like .text, all these values are in *bytes*. For sections which
have SEC_ELF_OCTETS set (like .debug_info), there exists only the section
symbols which have a value of 0. In absence of of "real" symbols inside these
sections, I cannot say whether st_value can also be in octets.
> Anyway, those can be left for a later patch if necessary.
I hope this could clarify you questions. As I already said, from the point of
the SDMA, everything works fine as it is.
regards
Christian
[1] bfd/elfcode.h:978
[2] bfd/elf.c:8139/8192
[3] gas/write.c:2311/2410
More information about the Binutils
mailing list