[llvm] a285bdb - BPF: remove default .extern data section
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 13 11:37:59 PDT 2021
Author: Yonghong Song
Date: 2021-04-13T11:35:52-07:00
New Revision: a285bdb56fb47a05281afdcb84d96c1fa3da63c1
URL: https://github.com/llvm/llvm-project/commit/a285bdb56fb47a05281afdcb84d96c1fa3da63c1
DIFF: https://github.com/llvm/llvm-project/commit/a285bdb56fb47a05281afdcb84d96c1fa3da63c1.diff
LOG: 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
Added:
Modified:
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll
llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index 9249d679c7bd1..37a5184893f39 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -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()) {
diff --git a/llvm/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll b/llvm/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll
index 3422afe948371..f44ce6ee50e86 100644
--- a/llvm/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll
+++ b/llvm/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll
@@ -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" }
diff --git a/llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll b/llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
index 5d8883b71f5ac..3257b23a47ee7 100644
--- a/llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
+++ b/llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
@@ -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" }
More information about the llvm-commits
mailing list