alloc_tag: remove empty module tag section
PATCH 1/1 alloc_tag: remove empty module tag section
The empty MOD_CODETAG_SECTIONS() macro added an incomplete .data section in module linker script, which caused symbol lookup tools like gdb to misinterpret symbol addresses e.g., __ib_process_cq incorrectly mapping to unrelated functions like below.
(gdb) disas __ib_process_cq
Dump of assembler code for function trace_event_fields_cq_schedule:
Removing the empty section restores proper symbol resolution and layout, ensuring .data placement behaves as expected.
22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
--- include/asm-generic/codetag.lds.h | 6 ------ scripts/module.lds.S | 5 ----- 2 files changed, 11 deletions(-)
include/asm-generic/codetag.lds.h +0 -6
@@ -11,12 +11,6 @@#define CODETAG_SECTIONS () \ SECTION_WITH_BOUNDARIES(alloc_tags) -/* -* Module codetags which aren't used after module unload, therefore have the -* same lifespan as the module and can be safely unloaded with the module. -*/ -#define MOD_CODETAG_SECTIONS () -#define MOD_SEPARATE_CODETAG_SECTION (_name) \ .codetag.##_name : { \ SECTION_WITH_BOUNDARIES(_name) \
scripts/module.lds.S +0 -5
@@ -50,17 +50,12 @@ SECTIONS { .data : { *(.data .data.[0-9a-zA-Z_]*) *(.data..L*) - MOD_CODETAG_SECTIONS() } .rodata : { *(.rodata .rodata.[0-9a-zA-Z_]*) *(.rodata..L*) } -#else - .data : { - MOD_CODETAG_SECTIONS() - } #endif MOD_SEPARATE_CODETAG_SECTIONS() }
Signature · 1 line
2.34.1
Petr Pavlu
maintainerQuoted 10 lines · Casey Chen
The empty
MOD_CODETAG_SECTIONS()macro added an incomplete .data section in module linker script, which caused symbol lookup tools like gdb to misinterpret symbol addresses e.g.,__ib_process_cqincorrectly mapping to unrelated functions like below.(gdb) disas
__ib_process_cq
Dump of assembler code for functiontrace_event_fields_cq_schedule:Removing the empty section restores proper symbol resolution and layout, ensuring .data placement behaves as expected.
The patch looks ok me, but I'm somewhat confused about the problem. I think a linker should not add an empty output section if it doesn't contain anything, or if .data actually contains something then the extra dummy definition should be also harmless?
This also reminds me of my previous related fix "codetag: Avoid unused alloc_tags sections/symbols" [1] which fell through the cracks. I can rebase it on top of this patch.
[1] https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Thanks, Petr
Suren Baghdasaryan
maintainerQuoted 10 lines · Petr Pavlu
Quoted 8 lines · Casey Chen
The empty
MOD_CODETAG_SECTIONS()macro added an incomplete .data section in module linker script, which caused symbol lookup tools like gdb to misinterpret symbol addresses e.g.,__ib_process_cqincorrectly mapping to unrelated functions like below.(gdb) disas
__ib_process_cq
Dump of assembler code for functiontrace_event_fields_cq_schedule:
Quoted 7 lines
Quoted 2 lines
Removing the empty section restores proper symbol resolution and layout, ensuring .data placement behaves as expected.
The patch looks ok me, but I'm somewhat confused about the problem. I think a linker should not add an empty output section if it doesn't contain anything, or if .data actually contains something then the extra dummy definition should be also harmless?
I also assumed so but apparently this is not entirely harmless.
Quoted 6 lines
This also reminds me of my previous related fix "codetag: Avoid unused
alloc_tagssections/symbols" [1] which fell through the cracks. I can rebase it on top of this patch.
Yes please.
Quoted 4 lines
--
Thanks,
Petr