public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* How to handle symbol indexes in gas and ld.bfd ?
@ 2023-04-03 16:07 Greg McGary
  0 siblings, 0 replies; only message in thread
From: Greg McGary @ 2023-04-03 16:07 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1455 bytes --]

I am implementing the RISCV Zisslpcfi extension. Without going into context
&
rationale for the new section, I will go straight to implementation
challenges.

I have a new section named .riscv.zisslpcfi_lp that contains a vector of
pairs
(<symbol>, <label>). <symbol> is represented as an index into the symbol
table--the same way that symbol references are represented in relocation
records--and <label> is a 32-bit integer.

The .riscv.zisslpcfi_lp section is ...

1) written by gas,
   resolving asymbol* to symndx

2) read & parsed by ld.bfd,
   resolving input symndx to riscv_elf_link_hash_entry*

3) written by ld.bfd when the output is relocatable,
   resolving riscv_elf_link_hash_entry* to output symndx

#1 is easy: write from _bfd_riscv_elf_set_section_contents() which
uses _bfd_elf_symbol_from_bfd_symbol() to get the symndx

#2 is easy: from _bfd_riscv_elf_merge_private_bfd_data(), parse
symndx and retrieve the symbol hash entry via
sym_hashes[symndx - symtab_hdr->sh_info]

#3 seems impossible without refactoring. There is no API for mapping
a symbol hash entry to its output symndx. The relocation code, which
also needs to transform input symndx into output symndx, does it
within elf_link_input_bfd() via the temporary flinfo->indices[] vector.

Moreover, gas internally uses asymbol* (struct bfd_symbol) while ld.bfd
uses symbol hash entries, which presents challenges for writing a generic
_bfd_riscv_elf_set_section_contents()

G

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-03 16:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03 16:07 How to handle symbol indexes in gas and ld.bfd ? Greg McGary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).