* [PATCH dwarves 0/2] Fix DATASEC assignment for global_var VARs @ 2026-11-19 18:52 Stephen Brennan 2026-11-19 18:52 ` [PATCH dwarves 1/2] tests: prep_release: use $VISUAL, not $EDITOR Stephen Brennan 2026-11-19 18:52 ` [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files Stephen Brennan 0 siblings, 2 replies; 6+ messages in thread From: Stephen Brennan @ 2026-11-19 18:52 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: dwarves, linux-debuggers, Stephen Brennan, Alan Maguire Hello Arnaldo & Alan! Two small patches. The first is just a small issue I encountered running the test harness. Second one is the actual priority, a bug in the BTF global_var output generated for Linux kernel modules. It's explained in the patch body already. I saw that you've added some global_var related tests -- thank you! I added a regression test which fails prior to the fix, and passes now. Thanks, Stephen Stephen Brennan (2): tests: prep_release: use $VISUAL, not $EDITOR btf_encoder: fix DATASEC assignment for ET_REL files btf_encoder.c | 13 +++++----- tests/btf_datasec.sh | 56 ++++++++++++++++++++++++++++++++++++++++++- tests/prep_release.sh | 2 +- 3 files changed, 62 insertions(+), 9 deletions(-) -- 2.52.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH dwarves 1/2] tests: prep_release: use $VISUAL, not $EDITOR 2026-11-19 18:52 [PATCH dwarves 0/2] Fix DATASEC assignment for global_var VARs Stephen Brennan @ 2026-11-19 18:52 ` Stephen Brennan 2026-11-19 18:52 ` [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files Stephen Brennan 1 sibling, 0 replies; 6+ messages in thread From: Stephen Brennan @ 2026-11-19 18:52 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: dwarves, linux-debuggers, Stephen Brennan, Alan Maguire The script uses $VISUAL and only falls back to $EDITOR. Systems with $VISUAL set will open the editor during tests, which is not what we want. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> --- tests/prep_release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/prep_release.sh b/tests/prep_release.sh index f8b86ff..62728ec 100755 --- a/tests/prep_release.sh +++ b/tests/prep_release.sh @@ -642,7 +642,7 @@ esac exit 0 EOF chmod +x "$outdir/mark-editor" -export EDITOR="sh $outdir/mark-editor" +export VISUAL="sh $outdir/mark-editor" if ! bash "$script" --yes --no-commit --no-tarball \ --no-build-check --no-tag > "$outdir/run.log" 2>&1; then error_log "FAIL: prep-release.sh exited with an error:" -- 2.52.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files 2026-11-19 18:52 [PATCH dwarves 0/2] Fix DATASEC assignment for global_var VARs Stephen Brennan 2026-11-19 18:52 ` [PATCH dwarves 1/2] tests: prep_release: use $VISUAL, not $EDITOR Stephen Brennan @ 2026-11-19 18:52 ` Stephen Brennan 2026-11-27 16:12 ` Alan Maguire 1 sibling, 1 reply; 6+ messages in thread From: Stephen Brennan @ 2026-11-19 18:52 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: dwarves, linux-debuggers, Stephen Brennan, Alan Maguire When building a kernel with the global_var feature, I encountered some kernel modules whose BTF encoded a DATASEC named ".debug_info" and assigned some variables, such as "__this_module" to this section. For ET_REL files, libdwfl assigns a synthetic address to allocated sections, starting at around 0x10000. Non-allocated sections, like .debug_info, start at address 0. If large enough, a non-allocated section's address range can extend past 0x10000, into the synthetic address range of an allocated section. This can happen with Linux kernel modules, resulting in the above behavior. Pahole iterates the sections in order, so if a variable's address falls into the overlapping range, and the non-allocated section appears first, pahole assigns it to the non-allocated section. Currently, get_elf_section() has logic to filter which sections are actually considered for variables. It uses a cached value of sh_type, but we have no cached sh_flags. Rather than cache more data, we can just filter out ineligible sections when we initialize the secinfo array, allowing us to remove cached sh_type altogether. This keeps the eligibility logic in one place, and removes the need to cache a field. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> --- btf_encoder.c | 13 +++++----- tests/btf_datasec.sh | 56 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index d6b9be6..8907b25 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -116,7 +116,6 @@ struct elf_secinfo { uint64_t addr; const char *name; uint64_t sz; - uint32_t type; bool include; struct gobuffer secinfo; }; @@ -2658,11 +2657,6 @@ static size_t get_elf_section(struct btf_encoder *encoder, uint64_t addr) { /* Start at index 1 to ignore initial SHT_NULL section */ for (size_t i = 1; i < encoder->seccnt; i++) { - /* Variables are only present in PROGBITS or NOBITS (.bss) */ - if (!(encoder->secinfo[i].type == SHT_PROGBITS || - encoder->secinfo[i].type == SHT_NOBITS)) - continue; - if (encoder->secinfo[i].addr <= addr && (addr - encoder->secinfo[i].addr) < encoder->secinfo[i].sz) return i; @@ -2977,10 +2971,15 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam Elf_Scn *sec = elf_section_by_idx(cu->elf, &shdr, shndx, &secname); if (!sec) goto out_delete; + /* Variables are only present in PROGBITS or NOBITS (.bss) */ + if (!(shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS)) + continue; + /* Variables are only present in runtime allocated sections. */ + if (!(shdr.sh_flags & SHF_ALLOC)) + continue; encoder->secinfo[shndx].addr = shdr.sh_addr; encoder->secinfo[shndx].sz = shdr.sh_size; encoder->secinfo[shndx].name = secname; - encoder->secinfo[shndx].type = shdr.sh_type; if (encoder->encode_vars & BTF_VAR_GLOBAL) encoder->secinfo[shndx].include = true; diff --git a/tests/btf_datasec.sh b/tests/btf_datasec.sh index 470c7f2..31d590f 100755 --- a/tests/btf_datasec.sh +++ b/tests/btf_datasec.sh @@ -4,7 +4,8 @@ # # Test BTF VAR and DATASEC encoding for global variables via # btf_encoder__add_var() and btf_encoder__add_datasec() in btf_encoder.c, -# exercised through --btf_features=global_var on a small linked binary. +# exercised through --btf_features=global_var on a small linked binary +# and a relocatable object with overlapping non-allocated sections. # # External globals and statics must each produce a BTF_KIND_VAR entry with # the correct linkage, and their ELF section must appear as a @@ -119,4 +120,57 @@ else info_log "DATASEC VAR references: skipped (old bpftool format)" fi +# For ET_REL files, libdwfl assigns synthetic addresses starting at 0x10000 +# to allocated sections. Non-allocated sections retain address zero, so a +# sufficiently large one appears to overlap the variables' addresses. +# Put one before .late_data to catch lookups that ignore SHF_ALLOC. +cat > "$src" << 'EOF' +asm(".pushsection .debug_padding, \"\"\n" + ".zero 0x20000\n" + ".popsection\n"); +int late_first __attribute__((section(".late_data"))) = 1; +int late_second __attribute__((section(".late_data"))) = 2; +EOF + +obj="$outdir/btf_datasec.o" +btf="$outdir/btf_datasec_rel.btf" +if ! $CC -g -O0 -c -o "$obj" "$src" 2>/dev/null; then + error_log "FAIL: relocatable object compilation failed" + test_fail +fi + +if ! pahole --btf_features=global_var --btf_encode_detached="$btf" "$obj" 2>/dev/null; then + error_log "FAIL: relocatable object BTF encoding failed" + test_fail +fi + +dump=$(bpftool btf dump file "$btf" 2>/dev/null) +if ! echo "$dump" | grep -q "DATASEC '\.late_data' size=8 vlen=2"; then + error_log "FAIL: expected two variables in .late_data DATASEC" + test_fail +fi +if echo "$dump" | grep -q "DATASEC '\.debug_padding'"; then + error_log "FAIL: non-allocated .debug_padding encoded as a DATASEC" + test_fail +fi + +for var in late_first late_second; do + if ! echo "$dump" | grep -q "VAR '$var'"; then + error_log "FAIL: BTF_KIND_VAR '$var' not found" + test_fail + fi +done + +if echo "$dump" | grep -q "(VAR '"; then + for var in late_first late_second; do + if ! echo "$dump" | grep -q "(VAR '$var')"; then + error_log "FAIL: no DATASEC references VAR '$var'" + test_fail + fi + done +else + info_log "DATASEC VAR references: skipped (old bpftool format)" +fi +info_log "Relocatable object ignores non-allocated sections: ok" + test_pass -- 2.52.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files 2026-11-19 18:52 ` [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files Stephen Brennan @ 2026-11-27 16:12 ` Alan Maguire 2026-11-27 16:26 ` Arnaldo Melo 2026-11-30 18:27 ` Stephen Brennan 0 siblings, 2 replies; 6+ messages in thread From: Alan Maguire @ 2026-11-27 16:12 UTC (permalink / raw) To: Stephen Brennan, Arnaldo Carvalho de Melo Cc: dwarves, linux-debuggers, Alan Maguire On 11/19/26 6:52 PM, Stephen Brennan wrote: > When building a kernel with the global_var feature, I encountered some > kernel modules whose BTF encoded a DATASEC named ".debug_info" and > assigned some variables, such as "__this_module" to this section. > > For ET_REL files, libdwfl assigns a synthetic address to allocated > sections, starting at around 0x10000. Non-allocated sections, like > .debug_info, start at address 0. If large enough, a non-allocated > section's address range can extend past 0x10000, into the synthetic > address range of an allocated section. This can happen with Linux kernel > modules, resulting in the above behavior. > > Pahole iterates the sections in order, so if a variable's address falls > into the overlapping range, and the non-allocated section appears first, > pahole assigns it to the non-allocated section. > > Currently, get_elf_section() has logic to filter which sections are > actually considered for variables. It uses a cached value of sh_type, > but we have no cached sh_flags. Rather than cache more data, we can just > filter out ineligible sections when we initialize the secinfo array, > allowing us to remove cached sh_type altogether. This keeps the > eligibility logic in one place, and removes the need to cache a field. > > Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> hi Stephen, this one needs a respin I think as the context in btf_encoder.c has changed; did you build on top of github.com/acmel/dwarves perhaps? Latest is always at https://git.kernel.org/pub/scm/devel/pahole/pahole.git/ Arnaldo, would you mind syncing next, master with pahole.git? Thanks! Alan > --- > btf_encoder.c | 13 +++++----- > tests/btf_datasec.sh | 56 +++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 61 insertions(+), 8 deletions(-) > > diff --git a/btf_encoder.c b/btf_encoder.c > index d6b9be6..8907b25 100644 > --- a/btf_encoder.c > +++ b/btf_encoder.c > @@ -116,7 +116,6 @@ struct elf_secinfo { > uint64_t addr; > const char *name; > uint64_t sz; > - uint32_t type; > bool include; > struct gobuffer secinfo; > }; > @@ -2658,11 +2657,6 @@ static size_t get_elf_section(struct btf_encoder *encoder, uint64_t addr) > { > /* Start at index 1 to ignore initial SHT_NULL section */ > for (size_t i = 1; i < encoder->seccnt; i++) { > - /* Variables are only present in PROGBITS or NOBITS (.bss) */ > - if (!(encoder->secinfo[i].type == SHT_PROGBITS || > - encoder->secinfo[i].type == SHT_NOBITS)) > - continue; > - > if (encoder->secinfo[i].addr <= addr && > (addr - encoder->secinfo[i].addr) < encoder->secinfo[i].sz) > return i; > @@ -2977,10 +2971,15 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam > Elf_Scn *sec = elf_section_by_idx(cu->elf, &shdr, shndx, &secname); > if (!sec) > goto out_delete; > + /* Variables are only present in PROGBITS or NOBITS (.bss) */ > + if (!(shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS)) > + continue; > + /* Variables are only present in runtime allocated sections. */ > + if (!(shdr.sh_flags & SHF_ALLOC)) > + continue; > encoder->secinfo[shndx].addr = shdr.sh_addr; > encoder->secinfo[shndx].sz = shdr.sh_size; > encoder->secinfo[shndx].name = secname; > - encoder->secinfo[shndx].type = shdr.sh_type; > > if (encoder->encode_vars & BTF_VAR_GLOBAL) > encoder->secinfo[shndx].include = true; > diff --git a/tests/btf_datasec.sh b/tests/btf_datasec.sh > index 470c7f2..31d590f 100755 > --- a/tests/btf_datasec.sh > +++ b/tests/btf_datasec.sh > @@ -4,7 +4,8 @@ > # > # Test BTF VAR and DATASEC encoding for global variables via > # btf_encoder__add_var() and btf_encoder__add_datasec() in btf_encoder.c, > -# exercised through --btf_features=global_var on a small linked binary. > +# exercised through --btf_features=global_var on a small linked binary > +# and a relocatable object with overlapping non-allocated sections. > # > # External globals and statics must each produce a BTF_KIND_VAR entry with > # the correct linkage, and their ELF section must appear as a > @@ -119,4 +120,57 @@ else > info_log "DATASEC VAR references: skipped (old bpftool format)" > fi > > +# For ET_REL files, libdwfl assigns synthetic addresses starting at 0x10000 > +# to allocated sections. Non-allocated sections retain address zero, so a > +# sufficiently large one appears to overlap the variables' addresses. > +# Put one before .late_data to catch lookups that ignore SHF_ALLOC. > +cat > "$src" << 'EOF' > +asm(".pushsection .debug_padding, \"\"\n" > + ".zero 0x20000\n" > + ".popsection\n"); > +int late_first __attribute__((section(".late_data"))) = 1; > +int late_second __attribute__((section(".late_data"))) = 2; > +EOF > + > +obj="$outdir/btf_datasec.o" > +btf="$outdir/btf_datasec_rel.btf" > +if ! $CC -g -O0 -c -o "$obj" "$src" 2>/dev/null; then > + error_log "FAIL: relocatable object compilation failed" > + test_fail > +fi > + > +if ! pahole --btf_features=global_var --btf_encode_detached="$btf" "$obj" 2>/dev/null; then > + error_log "FAIL: relocatable object BTF encoding failed" > + test_fail > +fi > + > +dump=$(bpftool btf dump file "$btf" 2>/dev/null) > +if ! echo "$dump" | grep -q "DATASEC '\.late_data' size=8 vlen=2"; then > + error_log "FAIL: expected two variables in .late_data DATASEC" > + test_fail > +fi > +if echo "$dump" | grep -q "DATASEC '\.debug_padding'"; then > + error_log "FAIL: non-allocated .debug_padding encoded as a DATASEC" > + test_fail > +fi > + > +for var in late_first late_second; do > + if ! echo "$dump" | grep -q "VAR '$var'"; then > + error_log "FAIL: BTF_KIND_VAR '$var' not found" > + test_fail > + fi > +done > + > +if echo "$dump" | grep -q "(VAR '"; then > + for var in late_first late_second; do > + if ! echo "$dump" | grep -q "(VAR '$var')"; then > + error_log "FAIL: no DATASEC references VAR '$var'" > + test_fail > + fi > + done > +else > + info_log "DATASEC VAR references: skipped (old bpftool format)" > +fi > +info_log "Relocatable object ignores non-allocated sections: ok" > + > test_pass ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files 2026-11-27 16:12 ` Alan Maguire @ 2026-11-27 16:26 ` Arnaldo Melo 2026-11-30 18:27 ` Stephen Brennan 1 sibling, 0 replies; 6+ messages in thread From: Arnaldo Melo @ 2026-11-27 16:26 UTC (permalink / raw) To: Alan Maguire, Stephen Brennan, Arnaldo Carvalho de Melo Cc: dwarves, linux-debuggers, Alan Maguire On November 27, 2026 1:12:06 PM GMT-03:00, Alan Maguire <almagui@kernel.org> wrote: >On 11/19/26 6:52 PM, Stephen Brennan wrote: >> When building a kernel with the global_var feature, I encountered some >> kernel modules whose BTF encoded a DATASEC named ".debug_info" and >> assigned some variables, such as "__this_module" to this section. >> >> For ET_REL files, libdwfl assigns a synthetic address to allocated >> sections, starting at around 0x10000. Non-allocated sections, like >> .debug_info, start at address 0. If large enough, a non-allocated >> section's address range can extend past 0x10000, into the synthetic >> address range of an allocated section. This can happen with Linux kernel >> modules, resulting in the above behavior. >> >> Pahole iterates the sections in order, so if a variable's address falls >> into the overlapping range, and the non-allocated section appears first, >> pahole assigns it to the non-allocated section. >> >> Currently, get_elf_section() has logic to filter which sections are >> actually considered for variables. It uses a cached value of sh_type, >> but we have no cached sh_flags. Rather than cache more data, we can just >> filter out ineligible sections when we initialize the secinfo array, >> allowing us to remove cached sh_type altogether. This keeps the >> eligibility logic in one place, and removes the need to cache a field. >> >> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> > >hi Stephen, this one needs a respin I think as the context in >btf_encoder.c has changed; did you build on top of github.com/acmel/dwarves >perhaps? Latest is always at https://git.kernel.org/pub/scm/devel/pahole/pahole.git/ > >Arnaldo, would you mind syncing next, master with pahole.git? Thanks! Will do it later today, - Arnaldo ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files 2026-11-27 16:12 ` Alan Maguire 2026-11-27 16:26 ` Arnaldo Melo @ 2026-11-30 18:27 ` Stephen Brennan 1 sibling, 0 replies; 6+ messages in thread From: Stephen Brennan @ 2026-11-30 18:27 UTC (permalink / raw) To: Alan Maguire, Arnaldo Carvalho de Melo Cc: dwarves, linux-debuggers, Alan Maguire Alan Maguire <almagui@kernel.org> writes: > On 11/19/26 6:52 PM, Stephen Brennan wrote: >> When building a kernel with the global_var feature, I encountered some >> kernel modules whose BTF encoded a DATASEC named ".debug_info" and >> assigned some variables, such as "__this_module" to this section. >> >> For ET_REL files, libdwfl assigns a synthetic address to allocated >> sections, starting at around 0x10000. Non-allocated sections, like >> .debug_info, start at address 0. If large enough, a non-allocated >> section's address range can extend past 0x10000, into the synthetic >> address range of an allocated section. This can happen with Linux kernel >> modules, resulting in the above behavior. >> >> Pahole iterates the sections in order, so if a variable's address falls >> into the overlapping range, and the non-allocated section appears first, >> pahole assigns it to the non-allocated section. >> >> Currently, get_elf_section() has logic to filter which sections are >> actually considered for variables. It uses a cached value of sh_type, >> but we have no cached sh_flags. Rather than cache more data, we can just >> filter out ineligible sections when we initialize the secinfo array, >> allowing us to remove cached sh_type altogether. This keeps the >> eligibility logic in one place, and removes the need to cache a field. >> >> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> > > hi Stephen, this one needs a respin I think as the context in > btf_encoder.c has changed; did you build on top of github.com/acmel/dwarves > perhaps? Latest is always at https://git.kernel.org/pub/scm/devel/pahole/pahole.git/ Hi Alan, Yep, I built on acmel/dwarves. Looks like substantial changes, including a newly cached "sh_flags" as mentioned in my commit message. So I'll just use that for a simpler fix. Also I've set "upstream" in my local checkout to point to the proper location, hopefully to avoid this in the future :D Thanks, Stephen > Arnaldo, would you mind syncing next, master with pahole.git? Thanks! > > Alan > >> --- >> btf_encoder.c | 13 +++++----- >> tests/btf_datasec.sh | 56 +++++++++++++++++++++++++++++++++++++++++++- >> 2 files changed, 61 insertions(+), 8 deletions(-) >> >> diff --git a/btf_encoder.c b/btf_encoder.c >> index d6b9be6..8907b25 100644 >> --- a/btf_encoder.c >> +++ b/btf_encoder.c >> @@ -116,7 +116,6 @@ struct elf_secinfo { >> uint64_t addr; >> const char *name; >> uint64_t sz; >> - uint32_t type; >> bool include; >> struct gobuffer secinfo; >> }; >> @@ -2658,11 +2657,6 @@ static size_t get_elf_section(struct btf_encoder *encoder, uint64_t addr) >> { >> /* Start at index 1 to ignore initial SHT_NULL section */ >> for (size_t i = 1; i < encoder->seccnt; i++) { >> - /* Variables are only present in PROGBITS or NOBITS (.bss) */ >> - if (!(encoder->secinfo[i].type == SHT_PROGBITS || >> - encoder->secinfo[i].type == SHT_NOBITS)) >> - continue; >> - >> if (encoder->secinfo[i].addr <= addr && >> (addr - encoder->secinfo[i].addr) < encoder->secinfo[i].sz) >> return i; >> @@ -2977,10 +2971,15 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam >> Elf_Scn *sec = elf_section_by_idx(cu->elf, &shdr, shndx, &secname); >> if (!sec) >> goto out_delete; >> + /* Variables are only present in PROGBITS or NOBITS (.bss) */ >> + if (!(shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS)) >> + continue; >> + /* Variables are only present in runtime allocated sections. */ >> + if (!(shdr.sh_flags & SHF_ALLOC)) >> + continue; >> encoder->secinfo[shndx].addr = shdr.sh_addr; >> encoder->secinfo[shndx].sz = shdr.sh_size; >> encoder->secinfo[shndx].name = secname; >> - encoder->secinfo[shndx].type = shdr.sh_type; >> >> if (encoder->encode_vars & BTF_VAR_GLOBAL) >> encoder->secinfo[shndx].include = true; >> diff --git a/tests/btf_datasec.sh b/tests/btf_datasec.sh >> index 470c7f2..31d590f 100755 >> --- a/tests/btf_datasec.sh >> +++ b/tests/btf_datasec.sh >> @@ -4,7 +4,8 @@ >> # >> # Test BTF VAR and DATASEC encoding for global variables via >> # btf_encoder__add_var() and btf_encoder__add_datasec() in btf_encoder.c, >> -# exercised through --btf_features=global_var on a small linked binary. >> +# exercised through --btf_features=global_var on a small linked binary >> +# and a relocatable object with overlapping non-allocated sections. >> # >> # External globals and statics must each produce a BTF_KIND_VAR entry with >> # the correct linkage, and their ELF section must appear as a >> @@ -119,4 +120,57 @@ else >> info_log "DATASEC VAR references: skipped (old bpftool format)" >> fi >> >> +# For ET_REL files, libdwfl assigns synthetic addresses starting at 0x10000 >> +# to allocated sections. Non-allocated sections retain address zero, so a >> +# sufficiently large one appears to overlap the variables' addresses. >> +# Put one before .late_data to catch lookups that ignore SHF_ALLOC. >> +cat > "$src" << 'EOF' >> +asm(".pushsection .debug_padding, \"\"\n" >> + ".zero 0x20000\n" >> + ".popsection\n"); >> +int late_first __attribute__((section(".late_data"))) = 1; >> +int late_second __attribute__((section(".late_data"))) = 2; >> +EOF >> + >> +obj="$outdir/btf_datasec.o" >> +btf="$outdir/btf_datasec_rel.btf" >> +if ! $CC -g -O0 -c -o "$obj" "$src" 2>/dev/null; then >> + error_log "FAIL: relocatable object compilation failed" >> + test_fail >> +fi >> + >> +if ! pahole --btf_features=global_var --btf_encode_detached="$btf" "$obj" 2>/dev/null; then >> + error_log "FAIL: relocatable object BTF encoding failed" >> + test_fail >> +fi >> + >> +dump=$(bpftool btf dump file "$btf" 2>/dev/null) >> +if ! echo "$dump" | grep -q "DATASEC '\.late_data' size=8 vlen=2"; then >> + error_log "FAIL: expected two variables in .late_data DATASEC" >> + test_fail >> +fi >> +if echo "$dump" | grep -q "DATASEC '\.debug_padding'"; then >> + error_log "FAIL: non-allocated .debug_padding encoded as a DATASEC" >> + test_fail >> +fi >> + >> +for var in late_first late_second; do >> + if ! echo "$dump" | grep -q "VAR '$var'"; then >> + error_log "FAIL: BTF_KIND_VAR '$var' not found" >> + test_fail >> + fi >> +done >> + >> +if echo "$dump" | grep -q "(VAR '"; then >> + for var in late_first late_second; do >> + if ! echo "$dump" | grep -q "(VAR '$var')"; then >> + error_log "FAIL: no DATASEC references VAR '$var'" >> + test_fail >> + fi >> + done >> +else >> + info_log "DATASEC VAR references: skipped (old bpftool format)" >> +fi >> +info_log "Relocatable object ignores non-allocated sections: ok" >> + >> test_pass ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-30 18:27 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-19 18:52 [PATCH dwarves 0/2] Fix DATASEC assignment for global_var VARs Stephen Brennan 2026-11-19 18:52 ` [PATCH dwarves 1/2] tests: prep_release: use $VISUAL, not $EDITOR Stephen Brennan 2026-11-19 18:52 ` [PATCH dwarves 2/2] btf_encoder: fix DATASEC assignment for ET_REL files Stephen Brennan 2026-11-27 16:12 ` Alan Maguire 2026-11-27 16:26 ` Arnaldo Melo 2026-11-30 18:27 ` Stephen Brennan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox