forked from OSchip/llvm-project
BPF: remove default .extern data section
Currently, for any extern variable, if it doesn't have section attribution, it will be put into a default ".extern" btf DataSec. The initial design is to put every extern variable in a DataSec so libbpf can use it. But later on, libbpf actually requires extern variables to put into special sections, e.g., ".kconfig", ".ksyms", etc. so they can be used properly based on section name. Andrii mentioned since ".extern" variables are not actually used, it makes sense to remove it from the compiler so libbpf does not need to deal with it, esp. for static linking. The BTF for these extern variables is still generated. With this patch, I tested kernel selftests/bpf and all tests passed. Indeed, removing ".extern" DataSec seems having no impact. Differential Revision: https://reviews.llvm.org/D100392
This commit is contained in:
parent
b351590bae
commit
a285bdb56f
|
@ -1146,10 +1146,6 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
|
|||
SecName = ".rodata";
|
||||
else
|
||||
SecName = Global.getInitializer()->isZeroValue() ? ".bss" : ".data";
|
||||
} else {
|
||||
// extern variables without explicit section,
|
||||
// put them into ".extern" section.
|
||||
SecName = ".extern";
|
||||
}
|
||||
|
||||
if (ProcessingMapDef != SecName.startswith(".maps"))
|
||||
|
@ -1213,7 +1209,9 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
|
|||
std::make_unique<BTFKindVar>(Global.getName(), GVTypeId, GVarInfo);
|
||||
uint32_t VarId = addType(std::move(VarEntry));
|
||||
|
||||
assert(!SecName.empty());
|
||||
// An empty SecName means an extern variable without section attribute.
|
||||
if (SecName.empty())
|
||||
continue;
|
||||
|
||||
// Find or create a DataSec
|
||||
if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
|
||||
|
|
|
@ -24,9 +24,9 @@ entry:
|
|||
; CHECK-NEXT: .byte 0
|
||||
; CHECK-NEXT: .long 24
|
||||
; CHECK-NEXT: .long 0
|
||||
; CHECK-NEXT: .long 116
|
||||
; CHECK-NEXT: .long 116
|
||||
; CHECK-NEXT: .long 81
|
||||
; CHECK-NEXT: .long 92
|
||||
; CHECK-NEXT: .long 92
|
||||
; CHECK-NEXT: .long 73
|
||||
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
|
||||
; CHECK-NEXT: .long 218103808 # 0xd000000
|
||||
; CHECK-NEXT: .long 2
|
||||
|
@ -50,12 +50,6 @@ entry:
|
|||
; CHECK-NEXT: .long 234881024 # 0xe000000
|
||||
; CHECK-NEXT: .long 4
|
||||
; CHECK-NEXT: .long 2
|
||||
; CHECK-NEXT: .long 73 # BTF_KIND_DATASEC(id = 7)
|
||||
; CHECK-NEXT: .long 251658241 # 0xf000001
|
||||
; CHECK-NEXT: .long 0
|
||||
; CHECK-NEXT: .long 6
|
||||
; CHECK-NEXT: .long global
|
||||
; CHECK-NEXT: .long 4
|
||||
; CHECK-NEXT: .byte 0 # string offset=0
|
||||
; CHECK-NEXT: .ascii "int" # string offset=1
|
||||
; CHECK-NEXT: .byte 0
|
||||
|
@ -73,8 +67,6 @@ entry:
|
|||
; CHECK-NEXT: .byte 0
|
||||
; CHECK-NEXT: .ascii "global" # string offset=66
|
||||
; CHECK-NEXT: .byte 0
|
||||
; CHECK-NEXT: .ascii ".extern" # string offset=73
|
||||
; CHECK-NEXT: .byte 0
|
||||
|
||||
attributes #0 = { norecurse nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ entry:
|
|||
; CHECK-NEXT: .byte 0
|
||||
; CHECK-NEXT: .long 24
|
||||
; CHECK-NEXT: .long 0
|
||||
; CHECK-NEXT: .long 116
|
||||
; CHECK-NEXT: .long 116
|
||||
; CHECK-NEXT: .long 81
|
||||
; CHECK-NEXT: .long 92
|
||||
; CHECK-NEXT: .long 92
|
||||
; CHECK-NEXT: .long 73
|
||||
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
|
||||
; CHECK-NEXT: .long 218103808 # 0xd000000
|
||||
; CHECK-NEXT: .long 2
|
||||
|
@ -51,12 +51,6 @@ entry:
|
|||
; CHECK-NEXT: .long 234881024 # 0xe000000
|
||||
; CHECK-NEXT: .long 4
|
||||
; CHECK-NEXT: .long 2
|
||||
; CHECK-NEXT: .long 73 # BTF_KIND_DATASEC(id = 7)
|
||||
; CHECK-NEXT: .long 251658241 # 0xf000001
|
||||
; CHECK-NEXT: .long 0
|
||||
; CHECK-NEXT: .long 6
|
||||
; CHECK-NEXT: .long global
|
||||
; CHECK-NEXT: .long 4
|
||||
; CHECK-NEXT: .byte 0 # string offset=0
|
||||
; CHECK-NEXT: .ascii "int" # string offset=1
|
||||
; CHECK-NEXT: .byte 0
|
||||
|
@ -74,8 +68,6 @@ entry:
|
|||
; CHECK-NEXT: .byte 0
|
||||
; CHECK-NEXT: .ascii "global" # string offset=66
|
||||
; CHECK-NEXT: .byte 0
|
||||
; CHECK-NEXT: .ascii ".extern" # string offset=73
|
||||
; CHECK-NEXT: .byte 0
|
||||
|
||||
attributes #0 = { norecurse nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
|
||||
|
|
Loading…
Reference in New Issue