From: Greg McGary <gkm@rivosinc.com>
To: binutils@sourceware.org
Subject: How to handle symbol indexes in gas and ld.bfd ?
Date: Mon, 3 Apr 2023 09:07:58 -0700 [thread overview]
Message-ID: <CACe4iF0ai9UcMWgoh98r1dyOd0b-Juqwox=m-twE_m7KKiqfYA@mail.gmail.com> (raw)
[-- 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
reply other threads:[~2023-04-03 16:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACe4iF0ai9UcMWgoh98r1dyOd0b-Juqwox=m-twE_m7KKiqfYA@mail.gmail.com' \
--to=gkm@rivosinc.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).