libbpf: Silence newly-added and unused sections
Yonghong Song
reviewerPATCH 1/1 libbpf: Silence newly-added and unused sections
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...
The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...
[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1 [24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1
...
Adding the above two sections in elf section ignore list can avoid the above info dump during selftest build.
[1] https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81
--- tools/lib/bpf/libbpf.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/lib/bpf/libbpf.c +8 -0
@@ -3788,6 +3788,14 @@ static bool ignore_elf_section(Elf64_Shdr *hdr, const char *name)if (is_sec_name_dwarf (name))return true; +/* .comment section */ +if (strcmp (name,".comment" ) ==0 ) +return true; + +/* .note.GNU-stack section */ +if (strcmp (name,".note.GNU-stack" ) ==0 ) +return true; +if (str_has_pfx (name,".rel" )) { name +=sizeof (".rel" ) -1 ;/* DWARF section relocations */
Signature · 1 line
2.47.3
Quoted 13 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...
Quoted 8 lines
[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1 [24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1...
Adding the above two sections in elf section ignore list can avoid the above info dump during selftest build.
[1] https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81
Can we revert this instead?
Why do we need these sections if we're not doing anything with them?
Quoted 27 lines
Signed-off-by Yonghong Song <[email protected]>--- tools/lib/bpf/libbpf.c | 8 ++++++++ 1 file changed, 8 insertions(+)tools/lib/bpf/libbpf.c +8
-1@@ -3788,6 +3788,14 @@ static bool ignore_elf_section(Elf64_Shdr *hdr, const char *name)if (is_sec_name_dwarf (name))return true; +/* .comment section */ +if (strcmp (name,".comment" ) ==0 ) +return true; + +/* .note.GNU-stack section */ +if (strcmp (name,".note.GNU-stack" ) ==0 ) +return true; +if (str_has_pfx (name,".rel" )) { name +=sizeof (".rel" ) -1 ;/* DWARF section relocations */ --2.47.3
Yonghong Song
reviewerQuoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1 [24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1...
Quoted 6 lines
Quoted 4 lines
Adding the above two sections in elf section ignore list can avoid the above info dump during selftest build.
[1] https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81Can we revert this instead?
Why do we need these sections if we're not doing anything with them?
Yes, we can revert at llvm side. It does not add any value to libbpf. Will submit a llvm pull request soon.
Quoted 28 lines
Quoted 28 lines
Signed-off-by Yonghong Song <[email protected]>--- tools/lib/bpf/libbpf.c | 8 ++++++++ 1 file changed, 8 insertions(+)tools/lib/bpf/libbpf.c +8
-1@@ -3788,6 +3788,14 @@ static bool ignore_elf_section(Elf64_Shdr *hdr, const char *name)if (is_sec_name_dwarf (name))return true; +/* .comment section */ +if (strcmp (name,".comment" ) ==0 ) +return true; + +/* .note.GNU-stack section */ +if (strcmp (name,".note.GNU-stack" ) ==0 ) +return true; +if (str_has_pfx (name,".rel" )) { name +=sizeof (".rel" ) -1 ;/* DWARF section relocations */ --2.47.3
Yonghong Song
reviewerQuoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1 [24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1...
Quoted 6 lines
Quoted 4 lines
Adding the above two sections in elf section ignore list can avoid the above info dump during selftest build.
[1] https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81Can we revert this instead?
Why do we need these sections if we're not doing anything with them?
I did further investigation and it looks like it is hard to revert.
To make things work at llvm level, we need to revert the following two llvm commits:
https://github.com/llvm/llvm-project/commit/87c73f498d3e98c7b6471f81e25b7e08106053fe
and then
https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81
The commit
https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81
lets BPFMCAsmInfo derives from MCAsmInfoELF, and the commit
https://github.com/llvm/llvm-project/commit/87c73f498d3e98c7b6471f81e25b7e08106053fe
push printSwitchToSection() to each variant of MCAsmInfo. The MCAsmInfo itself contains
+ virtual void printSwitchToSection(const MCSection &, uint32_t Subsection,
+ const Triple &, raw_ostream &) const {}
and
MCAsmInfoCOFF, MCAsmInfoDarwin and MCAsmInfoELF have their own specific implementation.
So if just revert d9489fd073c0e100c6fbb1e5aef140b00cf62b81, then at BPF backend, printSwitchToSection() will be a noop. This will miss a lot of '.seciton ...' cases. For example, there are totally 89 llvm BPF selftest failures.
For example, for jump table support, all '.jumptables' section name will not in asm code. Another example, '.BTF' section name will miss as well.
So to make the thing work, reverting both commits are necessary.
But tt will be hard to revert llvm commit 87c73f498d3e98c7b6471f81e25b7e08106053fe since it contains lots of non-BPF changes.
So I recommend to fix the problem at libbpf level.
Quoted 28 lines
Quoted 28 lines
Signed-off-by Yonghong Song <[email protected]>--- tools/lib/bpf/libbpf.c | 8 ++++++++ 1 file changed, 8 insertions(+)tools/lib/bpf/libbpf.c +8
-1@@ -3788,6 +3788,14 @@ static bool ignore_elf_section(Elf64_Shdr *hdr, const char *name)if (is_sec_name_dwarf (name))return true; +/* .comment section */ +if (strcmp (name,".comment" ) ==0 ) +return true; + +/* .note.GNU-stack section */ +if (strcmp (name,".note.GNU-stack" ) ==0 ) +return true; +if (str_has_pfx (name,".rel" )) { name +=sizeof (".rel" ) -1 ;/* DWARF section relocations */ --2.47.3
Quoted 51 lines · Yonghong Song
Quoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1 [24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1...
Quoted 6 lines
Quoted 4 lines
Adding the above two sections in elf section ignore list can avoid the above info dump during selftest build.
[1] https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81Can we revert this instead?
Why do we need these sections if we're not doing anything with them?I did further investigation and it looks like it is hard to revert.
To make things work at llvm level, we need to revert the following two llvm commits:https://github.com/llvm/llvm-project/commit/87c73f498d3e98c7b6471f81e25b7e08106053feand then
https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81The commit
https://github.com/llvm/llvm-project/commit/d9489fd073c0e100c6fbb1e5aef140b00cf62b81
lets BPFMCAsmInfo derives from MCAsmInfoELF, and the commit
https://github.com/llvm/llvm-project/commit/87c73f498d3e98c7b6471f81e25b7e08106053fe
pushprintSwitchToSection()to each variant of MCAsmInfo. The MCAsmInfo itself contains(quoted diff) +2
-0+ virtual void printSwitchToSection(const MCSection &, uint32_t Subsection, + const Triple &, raw_ostream &) const {}and
MCAsmInfoCOFF, MCAsmInfoDarwin and MCAsmInfoELF have their own specific implementation.So if just revert
d9489fd073c0e100c6fbb1e5aef140b00cf62b81, then at BPF backend,printSwitchToSection()will be a noop. This will miss a lot of '.seciton ...' cases. For example, there are totally 89 llvm BPF selftest failures.
Quoted 6 lines
For example, for jump table support, all '.jumptables' section name will not in asm code. Another example, '.BTF' section name will miss as well.
So to make the thing work, reverting both commits are necessary.
But tt will be hard to revert llvm commit87c73f498d3e98c7b6471f81e25b7e08106053fesince it contains lots of non-BPF changes.
Hmm.
Can filter out these couple section by name in BPFMCAsmInfo ?
Quoted 1 line
So I recommend to fix the problem at libbpf level.
It's probably ok, but let's see whether we can do something on llvm side.
Eduard Zingerman
maintainerQuoted 7 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...
Quoted 6 lines
The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...
[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1
This section is generated by MCELFStreamer::emitIdent(), virtual function.
Quoted 1 line
[24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1
And this one is generated by MCELFStreamer::initSections() virtual function and is controlled by NoExecStack formal parameter.
MCELFStreamer instance for BPF backend is created by function BPFMCTargetDesc.cpp:createBPFMCStreamer().
I think we can define a sub-class BPFMCELFStreamer, override the above virtual functions and suppress generation of the sections above.
[...]
Yonghong Song
reviewerQuoted 21 lines · Eduard Zingerman
Quoted 7 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...Quoted 6 lines
The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...
[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1This section is generated by
MCELFStreamer::emitIdent(), virtual function.Quoted 1 line
[24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1And this one is generated by
MCELFStreamer::initSections()virtual function and is controlled by NoExecStack formal parameter.
Quoted 7 lines
MCELFStreamer instance for BPF backend is created by function BPFMCTargetDesc.cpp:createBPFMCStreamer().
I think we can define a sub-class BPFMCELFStreamer, override the above virtual functions and suppress generation of the sections above.
[...]
Two llvm pull request:
to avoid generating .comment section:
https://github.com/llvm/llvm-project/pull/159958 to avoid generating .note.GNU-stack section: https://github.com/llvm/llvm-project/pull/159960
Eduard Zingerman
maintainerQuoted 29 lines · Yonghong Song
Quoted 27 lines · Eduard Zingerman
Quoted 7 lines · Yonghong Song
With latest llvm22, when building bpf selftest, I got the following info emitted by libbpf:
...
libbpf: elf: skipping unrecognized data section(14) .comment
libbpf: elf: skipping section(15) .note.GNU-stack (size 0)
...Quoted 6 lines
The reason is due to llvm patch [1]. Previously, bpf class BPFMCAsmInfo inherits class MCAsmInfo. With [1], BPFMCAsmInfo inherits class MCAsmInfoELF. Such a change added two more sections in the bpf binary, e.g.
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
...
[23] .comment PROGBITS 0000000000000000 0035ac 00006d 01 MS 0 0 1This section is generated by
MCELFStreamer::emitIdent(), virtual function.Quoted 1 line
[24] .note.GNU-stack PROGBITS 0000000000000000 003619 000000 00 0 0 1And this one is generated by
MCELFStreamer::initSections()virtual function and is controlled by NoExecStack formal parameter.MCELFStreamer instance for BPF backend is created by function BPFMCTargetDesc.cpp:createBPFMCStreamer().
I think we can define a sub-class BPFMCELFStreamer, override the above virtual functions and suppress generation of the sections above.
Quoted 7 lines
Quoted 1 line
[...]
Two llvm pull request:
to avoid generating .comment section:https://github.com/llvm/llvm-project/pull/159958 to avoid generating .note.GNU-stack section: https://github.com/llvm/llvm-project/pull/159960
Ack, thank you for the links.