diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -1146,10 +1146,6 @@ 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 @@ std::make_unique(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 --- 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 @@ ; 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 @@ ; 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 @@ ; 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 --- a/llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll +++ b/llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll @@ -25,9 +25,9 @@ ; 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 @@ ; 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 @@ ; 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" }