public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6702] bpf: ensure correct string offsets in BTF.ext
@ 2022-01-18 21:23 David Faust
0 siblings, 0 replies; only message in thread
From: David Faust @ 2022-01-18 21:23 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7db42268ce4bc77bc13f13ba0899221747255bb5
commit r12-6702-g7db42268ce4bc77bc13f13ba0899221747255bb5
Author: David Faust <david.faust@oracle.com>
Date: Tue Dec 14 13:48:21 2021 -0800
bpf: ensure correct string offsets in BTF.ext
BPF CO-RE relocations contain offsets to strings buffered in the BTF
string table. These BTF-specific strings are stored in memory in the
CTF auxilliary strtab, which at output time is concatenated onto the end
of the standard strtab.
Previously, these string offsets were computed at the time the
relocations were created. But strings could be added to the standard
strtab after this point, causing the offsets to no longer be correct.
Compute the offsets just before output instead, when they are sure to no
longer change.
gcc/ChangeLog:
* config/bpf/coreout.cc (bpf_core_reloc_add): Do not account
for base strtab offset yet as it may change.
(output_asm_btfext_core_reloc): Do so here instead.
(output_btfext_core_sections): Likewise.
Diff:
---
gcc/config/bpf/coreout.cc | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index 4ec12ecd305..cceaaa969cc 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -168,11 +168,8 @@ bpf_core_reloc_add (const tree type, const char * section_name,
bpf_core_reloc_ref bpfcr = ggc_cleared_alloc<bpf_core_reloc_t> ();
ctf_container_ref ctfc = ctf_get_tu_ctfc ();
- /* Buffer the access string in the auxiliary strtab. Since the two string
- tables are concatenated, add the length of the first to the offset. */
- size_t strtab_len = ctfc_get_strtab_len (ctfc, CTF_STRTAB);
+ /* Buffer the access string in the auxiliary strtab. */
ctf_add_string (ctfc, buf, &(bpfcr->bpfcr_astr_off), CTF_AUX_STRTAB);
- bpfcr->bpfcr_astr_off += strtab_len;
bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type));
bpfcr->bpfcr_insn_label = label;
@@ -191,7 +188,6 @@ bpf_core_reloc_add (const tree type, const char * section_name,
sec = ggc_cleared_alloc<bpf_core_section_t> ();
ctf_add_string (ctfc, section_name, &sec->name_offset, CTF_AUX_STRTAB);
- sec->name_offset += strtab_len;
if (strcmp (section_name, ""))
ctfc->ctfc_aux_strlen += strlen (section_name) + 1;
@@ -287,6 +283,9 @@ output_btfext_header (void)
static void
output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr)
{
+ bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (),
+ CTF_STRTAB);
+
dw2_assemble_integer (4, gen_rtx_LABEL_REF (Pmode, bpfcr->bpfcr_insn_label));
fprintf (asm_out_file, "\t%s bpfcr_insn\n", ASM_COMMENT_START);
@@ -323,6 +322,11 @@ output_btfext_core_sections (void)
/* Section name offset, refers to the offset of a string with the name of
the section to which these CORE relocations refer, e.g. '.text'.
The string is buffered in the BTF strings table. */
+
+ /* BTF specific strings are in CTF_AUX_STRTAB, which is concatenated
+ after CTF_STRTAB. Add the length of STRTAB to the final offset. */
+ sec->name_offset += ctfc_get_strtab_len (ctf_get_tu_ctfc (), CTF_STRTAB);
+
dw2_asm_output_data (4, sec->name_offset, "btfext_secinfo_sec_name_off");
dw2_asm_output_data (4, vec_safe_length (sec->relocs),
"btfext_secinfo_num_recs");
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-01-18 21:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 21:23 [gcc r12-6702] bpf: ensure correct string offsets in BTF.ext David Faust
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).