[llvm] 7d0e893 - [BPF] put not-section-attribute externs into BTF ".extern" data section
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 11:46:37 PST 2019
Author: Yonghong Song
Date: 2019-12-10T11:45:17-08:00
New Revision: 7d0e8930ed08b5f938a317f13d8fc994dd8c551c
URL: https://github.com/llvm/llvm-project/commit/7d0e8930ed08b5f938a317f13d8fc994dd8c551c
DIFF: https://github.com/llvm/llvm-project/commit/7d0e8930ed08b5f938a317f13d8fc994dd8c551c.diff
LOG: [BPF] put not-section-attribute externs into BTF ".extern" data section
Currently for extern variables with section attribute, those
BTF_KIND_VARs will not be placed in any DataSec. This is
inconvenient as any other generated BTF_KIND_VAR belongs to
one DataSec. This patch put these extern variables into
".extern" section so bpf loader can have a consistent
processing mechanism for all data sections and variables.
Added:
Modified:
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/test/CodeGen/BPF/BTF/extern-var-func-weak.ll
llvm/test/CodeGen/BPF/BTF/extern-var-func.ll
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 9dce734ea088..bdc7ce71a88c 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -1065,6 +1065,10 @@ 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"))
@@ -1113,8 +1117,7 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
std::make_unique<BTFKindVar>(Global.getName(), GVTypeId, GVarInfo);
uint32_t VarId = addType(std::move(VarEntry));
- if (SecName.empty())
- continue;
+ assert(!SecName.empty());
// Find or create a DataSec
if (DataSecEntries.find(SecName) == DataSecEntries.end()) {
@@ -1167,7 +1170,7 @@ void BTFDebug::processFuncPrototypes() {
StringRef SecName = F.getSection();
if (SecName.empty())
- continue;
+ SecName = ".extern";
if (DataSecEntries.find(SecName) == DataSecEntries.end()) {
DataSecEntries[SecName] = std::make_unique<BTFKindDataSec>(Asm, SecName);
diff --git a/llvm/test/CodeGen/BPF/BTF/extern-var-func-weak.ll b/llvm/test/CodeGen/BPF/BTF/extern-var-func-weak.ll
index e841fafc4daa..539ff3efd026 100644
--- a/llvm/test/CodeGen/BPF/BTF/extern-var-func-weak.ll
+++ b/llvm/test/CodeGen/BPF/BTF/extern-var-func-weak.ll
@@ -23,9 +23,9 @@ declare !dbg !4 extern_weak dso_local i32 @global_func(i8 signext) local_unnamed
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 0
-; CHECK-NEXT: .long 92
-; CHECK-NEXT: .long 92
-; CHECK-NEXT: .long 72
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 80
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
@@ -49,6 +49,12 @@ declare !dbg !4 extern_weak dso_local i32 @global_func(i8 signext) local_unnamed
; CHECK-NEXT: .long 234881024 # 0xe000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 2
+; CHECK-NEXT: .long 72 # BTF_KIND_DATASEC(id = 7)
+; CHECK-NEXT: .long 251658241 # 0xf000001
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 6
+; CHECK-NEXT: .long global_func
+; CHECK-NEXT: .long 8
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
@@ -62,6 +68,8 @@ declare !dbg !4 extern_weak dso_local i32 @global_func(i8 signext) local_unnamed
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "global_func" # string offset=60
; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .ascii ".extern" # string offset=72
+; CHECK-NEXT: .byte 0
attributes #0 = { nounwind "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" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="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-func.ll b/llvm/test/CodeGen/BPF/BTF/extern-var-func.ll
index a91e1c53c120..3243dcfd6b3b 100644
--- a/llvm/test/CodeGen/BPF/BTF/extern-var-func.ll
+++ b/llvm/test/CodeGen/BPF/BTF/extern-var-func.ll
@@ -22,9 +22,9 @@ entry:
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .long 24
; CHECK-NEXT: .long 0
-; CHECK-NEXT: .long 92
-; CHECK-NEXT: .long 92
-; CHECK-NEXT: .long 72
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 80
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
@@ -48,6 +48,12 @@ entry:
; CHECK-NEXT: .long 234881024 # 0xe000000
; CHECK-NEXT: .long 4
; CHECK-NEXT: .long 2
+; CHECK-NEXT: .long 72 # BTF_KIND_DATASEC(id = 7)
+; CHECK-NEXT: .long 251658241 # 0xf000001
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 6
+; CHECK-NEXT: .long global_func
+; CHECK-NEXT: .long 8
; CHECK-NEXT: .byte 0 # string offset=0
; CHECK-NEXT: .ascii "int" # string offset=1
; CHECK-NEXT: .byte 0
@@ -61,6 +67,8 @@ entry:
; CHECK-NEXT: .byte 0
; CHECK-NEXT: .ascii "global_func" # string offset=60
; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .ascii ".extern" # string offset=72
+; CHECK-NEXT: .byte 0
declare !dbg !4 dso_local i32 @global_func(i8 signext) local_unnamed_addr #1
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 1400d4b2f395..70e197441382 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 92
-; CHECK-NEXT: .long 92
-; CHECK-NEXT: .long 73
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 81
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
@@ -50,6 +50,12 @@ 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
@@ -67,6 +73,8 @@ 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 7a354e68662d..a8ec7851def3 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 92
-; CHECK-NEXT: .long 92
-; CHECK-NEXT: .long 73
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 116
+; CHECK-NEXT: .long 81
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
@@ -51,6 +51,12 @@ 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
@@ -68,6 +74,8 @@ 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