diff --git a/lib/Target/BPF/BTFDebug.cpp b/lib/Target/BPF/BTFDebug.cpp index 9dce734ea08..bdc7ce71a88 100644 --- a/lib/Target/BPF/BTFDebug.cpp +++ b/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(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(Asm, SecName); diff --git a/test/CodeGen/BPF/BTF/extern-var-func-weak.ll b/test/CodeGen/BPF/BTF/extern-var-func-weak.ll index e841fafc4da..539ff3efd02 100644 --- a/test/CodeGen/BPF/BTF/extern-var-func-weak.ll +++ b/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/test/CodeGen/BPF/BTF/extern-var-func.ll b/test/CodeGen/BPF/BTF/extern-var-func.ll index a91e1c53c12..3243dcfd6b3 100644 --- a/test/CodeGen/BPF/BTF/extern-var-func.ll +++ b/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/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll b/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll index 1400d4b2f39..70e19744138 100644 --- a/test/CodeGen/BPF/BTF/extern-var-struct-weak.ll +++ b/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/test/CodeGen/BPF/BTF/extern-var-struct.ll b/test/CodeGen/BPF/BTF/extern-var-struct.ll index 7a354e68662..a8ec7851def 100644 --- a/test/CodeGen/BPF/BTF/extern-var-struct.ll +++ b/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" }