Index: llvm/trunk/lib/Target/BPF/BTF.h =================================================================== --- llvm/trunk/lib/Target/BPF/BTF.h +++ llvm/trunk/lib/Target/BPF/BTF.h @@ -55,6 +55,7 @@ BTFEnumSize = 8, BTFMemberSize = 12, BTFParamSize = 8, + BTFDataSecVarSize = 12, SecFuncInfoSize = 8, SecLineInfoSize = 8, BPFFuncInfoSize = 8, @@ -76,7 +77,7 @@ }; enum : uint32_t { - MAX_VLEN = 0xffff ///< Max # of struct/union/enum members or func args + MAX_VLEN = 0xffff ///< Max # of struct/union/enum members or func args }; enum TypeKinds : uint8_t { @@ -103,7 +104,7 @@ /// "Size" tells the size of the type it is describing. /// /// "Type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, - /// FUNC and FUNC_PROTO. + /// FUNC, FUNC_PROTO and VAR. /// "Type" is a type_id referring to another type. union { uint32_t Size; @@ -121,7 +122,11 @@ // BTF_INT_BITS(VAL) : ((VAL) & 0x000000ff) /// Attributes stored in the INT_ENCODING. -enum : uint8_t { INT_SIGNED = (1 << 0), INT_CHAR = (1 << 1), INT_BOOL = (1 << 2) }; +enum : uint8_t { + INT_SIGNED = (1 << 0), + INT_CHAR = (1 << 1), + INT_BOOL = (1 << 2) +}; /// BTF_KIND_ENUM is followed by multiple "struct BTFEnum". /// The exact number of btf_enum is stored in the vlen (of the @@ -162,6 +167,23 @@ uint32_t Type; }; +/// Variable scoping information. +enum : uint8_t { + VAR_STATIC = 0, ///< Linkage: InternalLinkage + VAR_GLOBAL_ALLOCATED = 1, ///< Linkage: ExternalLinkage + VAR_GLOBAL_TENTATIVE = 2, ///< Linkage: CommonLinkage + VAR_GLOBAL_EXTERNAL = 3, ///< Linkage: ExternalLinkage +}; + +/// BTF_KIND_DATASEC are followed by multiple "struct BTFDataSecVar". +/// The exist number of BTFDataSec is stored in the vlen (of the info +/// in "struct CommonType"). +struct BTFDataSec { + uint32_t Type; ///< A BTF_KIND_VAR type + uint32_t Offset; ///< In-section offset + uint32_t Size; ///< Occupied memory size +}; + /// The .BTF.ext section header definition. struct ExtHeader { uint16_t Magic; Index: llvm/trunk/lib/Target/BPF/BTF.def =================================================================== --- llvm/trunk/lib/Target/BPF/BTF.def +++ llvm/trunk/lib/Target/BPF/BTF.def @@ -28,5 +28,7 @@ HANDLE_BTF_KIND(11, RESTRICT) HANDLE_BTF_KIND(12, FUNC) HANDLE_BTF_KIND(13, FUNC_PROTO) +HANDLE_BTF_KIND(14, VAR) +HANDLE_BTF_KIND(15, DATASEC) #undef HANDLE_BTF_KIND Index: llvm/trunk/lib/Target/BPF/BTFDebug.h =================================================================== --- llvm/trunk/lib/Target/BPF/BTFDebug.h +++ llvm/trunk/lib/Target/BPF/BTFDebug.h @@ -153,6 +153,37 @@ void emitType(MCStreamer &OS); }; +/// Handle variable instances +class BTFKindVar : public BTFTypeBase { + StringRef Name; + uint32_t Info; + +public: + BTFKindVar(StringRef VarName, uint32_t TypeId, uint32_t VarInfo); + uint32_t getSize() { return BTFTypeBase::getSize() + 4; } + void completeType(BTFDebug &BDebug); + void emitType(MCStreamer &OS); +}; + +/// Handle data sections +class BTFKindDataSec : public BTFTypeBase { + AsmPrinter *Asm; + std::string Name; + std::vector> Vars; + +public: + BTFKindDataSec(AsmPrinter *AsmPrt, std::string SecName); + uint32_t getSize() { + return BTFTypeBase::getSize() + BTF::BTFDataSecVarSize * Vars.size(); + } + void addVar(uint32_t Id, const MCSymbol *Sym, uint32_t Size) { + Vars.push_back(std::make_tuple(Id, Sym, Size)); + } + std::string getName() { return Name; } + void completeType(BTFDebug &BDebug); + void emitType(MCStreamer &OS); +}; + /// String table. class BTFStringTable { /// String table size in bytes. @@ -201,11 +232,13 @@ std::unordered_map> FuncInfoTable; std::unordered_map> LineInfoTable; StringMap> FileContent; + std::unordered_map> + DataSecEntries; /// Add types to TypeEntries. /// @{ /// Add types to TypeEntries and DIToIdMap. - void addType(std::unique_ptr TypeEntry, const DIType *Ty); + uint32_t addType(std::unique_ptr TypeEntry, const DIType *Ty); /// Add types to TypeEntries only and return type id. uint32_t addType(std::unique_ptr TypeEntry); /// @} @@ -213,17 +246,20 @@ /// IR type visiting functions. /// @{ void visitTypeEntry(const DIType *Ty); - void visitBasicType(const DIBasicType *BTy); + void visitTypeEntry(const DIType *Ty, uint32_t &TypeId); + void visitBasicType(const DIBasicType *BTy, uint32_t &TypeId); void visitSubroutineType( const DISubroutineType *STy, bool ForSubprog, const std::unordered_map &FuncArgNames, uint32_t &TypeId); - void visitFwdDeclType(const DICompositeType *CTy, bool IsUnion); - void visitCompositeType(const DICompositeType *CTy); - void visitStructType(const DICompositeType *STy, bool IsStruct); - void visitArrayType(const DICompositeType *ATy); - void visitEnumType(const DICompositeType *ETy); - void visitDerivedType(const DIDerivedType *DTy); + void visitFwdDeclType(const DICompositeType *CTy, bool IsUnion, + uint32_t &TypeId); + void visitCompositeType(const DICompositeType *CTy, uint32_t &TypeId); + void visitStructType(const DICompositeType *STy, bool IsStruct, + uint32_t &TypeId); + void visitArrayType(const DICompositeType *ATy, uint32_t &TypeId); + void visitEnumType(const DICompositeType *ETy, uint32_t &TypeId); + void visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId); /// @} /// Get the file content for the subprogram. Certain lines of the file @@ -234,6 +270,9 @@ void constructLineInfo(const DISubprogram *SP, MCSymbol *Label, uint32_t Line, uint32_t Column); + /// Generate types and variables for globals. + void processGlobals(void); + /// Emit common header of .BTF and .BTF.ext sections. void emitCommonHeader(); Index: llvm/trunk/lib/Target/BPF/BTFDebug.cpp =================================================================== --- llvm/trunk/lib/Target/BPF/BTFDebug.cpp +++ llvm/trunk/lib/Target/BPF/BTFDebug.cpp @@ -302,6 +302,45 @@ void BTFTypeFunc::emitType(MCStreamer &OS) { BTFTypeBase::emitType(OS); } +BTFKindVar::BTFKindVar(StringRef VarName, uint32_t TypeId, uint32_t VarInfo) + : Name(VarName) { + Kind = BTF::BTF_KIND_VAR; + BTFType.Info = Kind << 24; + BTFType.Type = TypeId; + Info = VarInfo; +} + +void BTFKindVar::completeType(BTFDebug &BDebug) { + BTFType.NameOff = BDebug.addString(Name); +} + +void BTFKindVar::emitType(MCStreamer &OS) { + BTFTypeBase::emitType(OS); + OS.EmitIntValue(Info, 4); +} + +BTFKindDataSec::BTFKindDataSec(AsmPrinter *AsmPrt, std::string SecName) + : Asm(AsmPrt), Name(SecName) { + Kind = BTF::BTF_KIND_DATASEC; + BTFType.Info = Kind << 24; + BTFType.Size = 0; +} + +void BTFKindDataSec::completeType(BTFDebug &BDebug) { + BTFType.NameOff = BDebug.addString(Name); + BTFType.Info |= Vars.size(); +} + +void BTFKindDataSec::emitType(MCStreamer &OS) { + BTFTypeBase::emitType(OS); + + for (const auto &V : Vars) { + OS.EmitIntValue(std::get<0>(V), 4); + Asm->EmitLabelReference(std::get<1>(V), 4); + OS.EmitIntValue(std::get<2>(V), 4); + } +} + uint32_t BTFStringTable::addString(StringRef S) { // Check whether the string already exists. for (auto &OffsetM : OffsetToIdMap) { @@ -322,11 +361,13 @@ addString("\0"); } -void BTFDebug::addType(std::unique_ptr TypeEntry, - const DIType *Ty) { +uint32_t BTFDebug::addType(std::unique_ptr TypeEntry, + const DIType *Ty) { TypeEntry->setId(TypeEntries.size() + 1); - DIToIdMap[Ty] = TypeEntry->getId(); + uint32_t Id = TypeEntry->getId(); + DIToIdMap[Ty] = Id; TypeEntries.push_back(std::move(TypeEntry)); + return Id; } uint32_t BTFDebug::addType(std::unique_ptr TypeEntry) { @@ -336,7 +377,7 @@ return Id; } -void BTFDebug::visitBasicType(const DIBasicType *BTy) { +void BTFDebug::visitBasicType(const DIBasicType *BTy, uint32_t &TypeId) { // Only int types are supported in BTF. uint32_t Encoding = BTy->getEncoding(); if (Encoding != dwarf::DW_ATE_boolean && Encoding != dwarf::DW_ATE_signed && @@ -349,7 +390,7 @@ // DIToIdMap for cross-type reference check. auto TypeEntry = llvm::make_unique( Encoding, BTy->getSizeInBits(), BTy->getOffsetInBits(), BTy->getName()); - addType(std::move(TypeEntry), BTy); + TypeId = addType(std::move(TypeEntry), BTy); } /// Handle subprogram or subroutine types. @@ -370,7 +411,7 @@ if (ForSubprog) TypeId = addType(std::move(TypeEntry)); // For subprogram else - addType(std::move(TypeEntry), STy); // For func ptr + TypeId = addType(std::move(TypeEntry), STy); // For func ptr // Visit return type and func arg types. for (const auto Element : Elements) { @@ -379,7 +420,8 @@ } /// Handle structure/union types. -void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct) { +void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct, + uint32_t &TypeId) { const DINodeArray Elements = CTy->getElements(); uint32_t VLen = Elements.size(); if (VLen > BTF::MAX_VLEN) @@ -397,16 +439,16 @@ auto TypeEntry = llvm::make_unique(CTy, IsStruct, HasBitField, VLen); - addType(std::move(TypeEntry), CTy); + TypeId = addType(std::move(TypeEntry), CTy); // Visit all struct members. for (const auto *Element : Elements) visitTypeEntry(cast(Element)); } -void BTFDebug::visitArrayType(const DICompositeType *CTy) { +void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) { auto TypeEntry = llvm::make_unique(CTy); - addType(std::move(TypeEntry), CTy); + TypeId = addType(std::move(TypeEntry), CTy); // The IR does not have a type for array index while BTF wants one. // So create an array index type if there is none. @@ -420,74 +462,82 @@ visitTypeEntry(CTy->getBaseType().resolve()); } -void BTFDebug::visitEnumType(const DICompositeType *CTy) { +void BTFDebug::visitEnumType(const DICompositeType *CTy, uint32_t &TypeId) { DINodeArray Elements = CTy->getElements(); uint32_t VLen = Elements.size(); if (VLen > BTF::MAX_VLEN) return; auto TypeEntry = llvm::make_unique(CTy, VLen); - addType(std::move(TypeEntry), CTy); + TypeId = addType(std::move(TypeEntry), CTy); // No need to visit base type as BTF does not encode it. } /// Handle structure/union forward declarations. -void BTFDebug::visitFwdDeclType(const DICompositeType *CTy, bool IsUnion) { +void BTFDebug::visitFwdDeclType(const DICompositeType *CTy, bool IsUnion, + uint32_t &TypeId) { auto TypeEntry = llvm::make_unique(CTy->getName(), IsUnion); - addType(std::move(TypeEntry), CTy); + TypeId = addType(std::move(TypeEntry), CTy); } /// Handle structure, union, array and enumeration types. -void BTFDebug::visitCompositeType(const DICompositeType *CTy) { +void BTFDebug::visitCompositeType(const DICompositeType *CTy, + uint32_t &TypeId) { auto Tag = CTy->getTag(); if (Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) { // Handle forward declaration differently as it does not have members. if (CTy->isForwardDecl()) - visitFwdDeclType(CTy, Tag == dwarf::DW_TAG_union_type); + visitFwdDeclType(CTy, Tag == dwarf::DW_TAG_union_type, TypeId); else - visitStructType(CTy, Tag == dwarf::DW_TAG_structure_type); + visitStructType(CTy, Tag == dwarf::DW_TAG_structure_type, TypeId); } else if (Tag == dwarf::DW_TAG_array_type) - visitArrayType(CTy); + visitArrayType(CTy, TypeId); else if (Tag == dwarf::DW_TAG_enumeration_type) - visitEnumType(CTy); + visitEnumType(CTy, TypeId); } /// Handle pointer, typedef, const, volatile, restrict and member types. -void BTFDebug::visitDerivedType(const DIDerivedType *DTy) { +void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId) { unsigned Tag = DTy->getTag(); if (Tag == dwarf::DW_TAG_pointer_type || Tag == dwarf::DW_TAG_typedef || Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type || Tag == dwarf::DW_TAG_restrict_type) { auto TypeEntry = llvm::make_unique(DTy, Tag); - addType(std::move(TypeEntry), DTy); + TypeId = addType(std::move(TypeEntry), DTy); } else if (Tag != dwarf::DW_TAG_member) { return; } // Visit base type of pointer, typedef, const, volatile, restrict or // struct/union member. - visitTypeEntry(DTy->getBaseType().resolve()); + visitTypeEntry(DTy->getBaseType().resolve(), TypeId); } -void BTFDebug::visitTypeEntry(const DIType *Ty) { - if (!Ty || DIToIdMap.find(Ty) != DIToIdMap.end()) +void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId) { + if (!Ty || DIToIdMap.find(Ty) != DIToIdMap.end()) { + TypeId = DIToIdMap[Ty]; return; + } - uint32_t TypeId; if (const auto *BTy = dyn_cast(Ty)) - visitBasicType(BTy); + visitBasicType(BTy, TypeId); else if (const auto *STy = dyn_cast(Ty)) visitSubroutineType(STy, false, std::unordered_map(), TypeId); else if (const auto *CTy = dyn_cast(Ty)) - visitCompositeType(CTy); + visitCompositeType(CTy, TypeId); else if (const auto *DTy = dyn_cast(Ty)) - visitDerivedType(DTy); + visitDerivedType(DTy, TypeId); else llvm_unreachable("Unknown DIType"); } +void BTFDebug::visitTypeEntry(const DIType *Ty) { + uint32_t TypeId; + visitTypeEntry(Ty, TypeId); +} + /// Read file contents from the actual file or from the source std::string BTFDebug::populateFileContent(const DISubprogram *SP) { auto File = SP->getFile(); @@ -746,7 +796,7 @@ PrevInstLoc = DL; } -void BTFDebug::endModule() { +void BTFDebug::processGlobals() { // Collect all types referenced by globals. const Module *M = MMI->getModule(); for (const GlobalVariable &Global : M->globals()) { @@ -756,11 +806,65 @@ SmallVector GVs; Global.getDebugInfo(GVs); + uint32_t GVTypeId = 0; for (auto *GVE : GVs) { - visitTypeEntry(GVE->getVariable()->getType().resolve()); + visitTypeEntry(GVE->getVariable()->getType().resolve(), GVTypeId); + break; + } + + // Only support the following globals: + // . static variables + // . non-static global variables with section attributes + // Essentially means: + // . .bcc/.data/.rodata DataSec entities only contain static data + // . Other DataSec entities contain static or initialized global data. + // Initialized global data are mostly used for finding map key/value type + // id's. Whether DataSec is readonly or not can be found from + // corresponding ELF section flags. + auto Linkage = Global.getLinkage(); + if (Linkage != GlobalValue::InternalLinkage && + (Linkage != GlobalValue::ExternalLinkage || !Global.hasSection())) + continue; + + uint32_t GVarInfo = Linkage == GlobalValue::ExternalLinkage + ? BTF::VAR_GLOBAL_ALLOCATED + : BTF::VAR_STATIC; + auto VarEntry = + llvm::make_unique(Global.getName(), GVTypeId, GVarInfo); + uint32_t VarId = addType(std::move(VarEntry)); + + // Decide the section name. + std::string SecName; + if (Global.hasSection()) { + SecName = Global.getSection().str(); + } else { + // data, bss, or readonly sections + if (Global.isConstant()) + SecName += ".rodata"; + else + SecName += Global.getInitializer()->isZeroValue() ? ".bss" : ".data"; } + + // Find or create a DataSec + if (DataSecEntries.find(SecName) == DataSecEntries.end()) { + DataSecEntries[SecName] = llvm::make_unique(Asm, SecName); + } + + // Calculate symbol size + const DataLayout &DL = Global.getParent()->getDataLayout(); + uint32_t Size = DL.getTypeAllocSize(Global.getType()->getElementType()); + + DataSecEntries[SecName]->addVar(VarId, Asm->getSymbol(&Global), Size); } + for (auto &DataSec : DataSecEntries) + addType(std::move(DataSec.second)); +} + +void BTFDebug::endModule() { + // Collect all global types/variables. + processGlobals(); + // Complete BTF type cross refereences. for (const auto &TypeEntry : TypeEntries) TypeEntry->completeType(*this); Index: llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll @@ -0,0 +1,73 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; const int gv1 __attribute__((section("maps"))); +; const int gv2 __attribute__((section("maps"))) = 5; +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@gv2 = dso_local local_unnamed_addr constant i32 5, section "maps", align 4, !dbg !0 +@gv1 = dso_local local_unnamed_addr constant i32 0, section "maps", align 4, !dbg !6 + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 96 +; CHECK-NEXT: .long 96 +; CHECK-NEXT: .long 18 +; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 1) +; CHECK-NEXT: .long 167772160 # 0xa000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 5 # BTF_KIND_VAR(id = 3) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 9 # BTF_KIND_VAR(id = 4) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 13 # BTF_KIND_DATASEC(id = 5) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 3 +; CHECK-NEXT: .long gv2 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long gv1 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii "int" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "gv2" # string offset=5 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "gv1" # string offset=9 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "maps" # string offset=13 +; CHECK-NEXT: .byte 0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!10, !11, !12} +!llvm.ident = !{!13} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "gv2", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !{} +!5 = !{!0, !6} +!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) +!7 = distinct !DIGlobalVariable(name: "gv1", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) +!8 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !9) +!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!10 = !{i32 2, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 3} +!12 = !{i32 1, !"wchar_size", i32 4} +!13 = !{!"clang version 8.0.20181009 "} Index: llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll @@ -0,0 +1,69 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; int gv1 __attribute__((section("maps"))); +; int gv2 __attribute__((section("maps"))) = 5; +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@gv2 = dso_local local_unnamed_addr global i32 5, section "maps", align 4, !dbg !0 +@gv1 = dso_local local_unnamed_addr global i32 0, section "maps", align 4, !dbg !6 + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 84 +; CHECK-NEXT: .long 84 +; CHECK-NEXT: .long 18 +; CHECK-NEXT: .long 1 # BTF_KIND_INT(id = 1) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 5 # BTF_KIND_VAR(id = 2) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 9 # BTF_KIND_VAR(id = 3) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 13 # BTF_KIND_DATASEC(id = 4) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long gv2 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 3 +; CHECK-NEXT: .long gv1 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii "int" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "gv2" # string offset=5 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "gv1" # string offset=9 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "maps" # string offset=13 +; CHECK-NEXT: .byte 0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!9, !10, !11} +!llvm.ident = !{!12} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "gv2", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !{} +!5 = !{!0, !6} +!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) +!7 = distinct !DIGlobalVariable(name: "gv1", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) +!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!9 = !{i32 2, !"Dwarf Version", i32 4} +!10 = !{i32 2, !"Debug Info Version", i32 3} +!11 = !{i32 1, !"wchar_size", i32 4} +!12 = !{!"clang version 8.0.20181009 "} Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll @@ -0,0 +1,130 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; static volatile char a __attribute__((section("maps"))) = 3; +; int foo() { +; static volatile short b __attribute__((section("maps"))) = 4; +; return a + b; +; } +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@foo.b = internal global i16 4, section "maps", align 2, !dbg !0 +@a = internal global i8 3, section "maps", align 1, !dbg !10 + +; Function Attrs: norecurse nounwind +define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 { + %1 = load volatile i8, i8* @a, align 1, !dbg !20, !tbaa !21 + %2 = sext i8 %1 to i32, !dbg !20 + %3 = load volatile i16, i16* @foo.b, align 2, !dbg !24, !tbaa !25 + %4 = sext i16 %3 to i32, !dbg !24 + %5 = add nsw i32 %4, %2, !dbg !27 + ret i32 %5, !dbg !28 +} + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 76 +; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) +; CHECK-NEXT: .long 218103808 # 0xd000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3) +; CHECK-NEXT: .long 201326592 # 0xc000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 5) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 16777232 # 0x1000010 +; CHECK-NEXT: .long 58 # BTF_KIND_VAR(id = 6) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 7) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 64 # BTF_KIND_INT(id = 8) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 69 # BTF_KIND_VAR(id = 9) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 71 # BTF_KIND_DATASEC(id = 10) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long foo.b +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long a +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii ".text" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "int" # string offset=44 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo" # string offset=48 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "short" # string offset=52 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo.b" # string offset=58 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=64 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=69 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "maps" # string offset=71 +; CHECK-NEXT: .byte 0 + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" } + +!llvm.dbg.cu = !{!7} +!llvm.module.flags = !{!16, !17, !18} +!llvm.ident = !{!19} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !DISubroutineType(types: !5) +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) +!8 = !{} +!9 = !{!0, !10} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) +!12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !15) +!15 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) +!16 = !{i32 2, !"Dwarf Version", i32 4} +!17 = !{i32 2, !"Debug Info Version", i32 3} +!18 = !{i32 1, !"wchar_size", i32 4} +!19 = !{!"clang version 8.0.20181009 "} +!20 = !DILocation(line: 4, column: 10, scope: !2) +!21 = !{!22, !22, i64 0} +!22 = !{!"omnipotent char", !23, i64 0} +!23 = !{!"Simple C/C++ TBAA"} +!24 = !DILocation(line: 4, column: 14, scope: !2) +!25 = !{!26, !26, i64 0} +!26 = !{!"short", !22, i64 0} +!27 = !DILocation(line: 4, column: 12, scope: !2) +!28 = !DILocation(line: 4, column: 3, scope: !2) Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll @@ -0,0 +1,130 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; static volatile char a = 3; +; int foo() { +; static volatile short b = 4; +; return a + b; +; } +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@foo.b = internal global i16 4, align 2, !dbg !0 +@a = internal global i8 3, align 1, !dbg !10 + +; Function Attrs: norecurse nounwind +define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 { + %1 = load volatile i8, i8* @a, align 1, !dbg !20, !tbaa !21 + %2 = sext i8 %1 to i32, !dbg !20 + %3 = load volatile i16, i16* @foo.b, align 2, !dbg !24, !tbaa !25 + %4 = sext i16 %3 to i32, !dbg !24 + %5 = add nsw i32 %4, %2, !dbg !27 + ret i32 %5, !dbg !28 +} + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 77 +; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) +; CHECK-NEXT: .long 218103808 # 0xd000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3) +; CHECK-NEXT: .long 201326592 # 0xc000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 5) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 16777232 # 0x1000010 +; CHECK-NEXT: .long 58 # BTF_KIND_VAR(id = 6) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 7) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 64 # BTF_KIND_INT(id = 8) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 69 # BTF_KIND_VAR(id = 9) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 71 # BTF_KIND_DATASEC(id = 10) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long foo.b +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long a +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii ".text" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "int" # string offset=44 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo" # string offset=48 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "short" # string offset=52 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo.b" # string offset=58 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=64 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=69 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii ".data" # string offset=71 +; CHECK-NEXT: .byte 0 + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" } + +!llvm.dbg.cu = !{!7} +!llvm.module.flags = !{!16, !17, !18} +!llvm.ident = !{!19} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !DISubroutineType(types: !5) +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) +!8 = !{} +!9 = !{!0, !10} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) +!12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !15) +!15 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) +!16 = !{i32 2, !"Dwarf Version", i32 4} +!17 = !{i32 2, !"Debug Info Version", i32 3} +!18 = !{i32 1, !"wchar_size", i32 4} +!19 = !{!"clang version 8.0.20181009 "} +!20 = !DILocation(line: 4, column: 10, scope: !2) +!21 = !{!22, !22, i64 0} +!22 = !{!"omnipotent char", !23, i64 0} +!23 = !{!"Simple C/C++ TBAA"} +!24 = !DILocation(line: 4, column: 14, scope: !2) +!25 = !{!26, !26, i64 0} +!26 = !{!"short", !22, i64 0} +!27 = !DILocation(line: 4, column: 12, scope: !2) +!28 = !DILocation(line: 4, column: 3, scope: !2) Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll @@ -0,0 +1,138 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; static volatile const char __attribute__((section("maps"))) a; +; int foo() { +; static volatile const short b __attribute__((section("maps"))) = 3; +; return a + b; +; } +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@foo.b = internal constant i16 3, section "maps", align 2, !dbg !0 +@a = internal constant i8 0, section "maps", align 1, !dbg !10 + +; Function Attrs: norecurse nounwind +define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 { + %1 = load volatile i8, i8* @a, align 1, !dbg !22, !tbaa !23 + %2 = sext i8 %1 to i32, !dbg !22 + %3 = load volatile i16, i16* @foo.b, align 2, !dbg !26, !tbaa !27 + %4 = sext i16 %3 to i32, !dbg !26 + %5 = add nsw i32 %4, %2, !dbg !29 + ret i32 %5, !dbg !30 +} + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 188 +; CHECK-NEXT: .long 188 +; CHECK-NEXT: .long 76 +; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) +; CHECK-NEXT: .long 218103808 # 0xd000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3) +; CHECK-NEXT: .long 201326592 # 0xc000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 4) +; CHECK-NEXT: .long 167772160 # 0xa000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 5) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 6) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 16777232 # 0x1000010 +; CHECK-NEXT: .long 58 # BTF_KIND_VAR(id = 7) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 8) +; CHECK-NEXT: .long 167772160 # 0xa000000 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 9) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 10 +; CHECK-NEXT: .long 64 # BTF_KIND_INT(id = 10) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 69 # BTF_KIND_VAR(id = 11) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 10 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 71 # BTF_KIND_DATASEC(id = 12) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 7 +; CHECK-NEXT: .long foo.b +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 11 +; CHECK-NEXT: .long a +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii ".text" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "int" # string offset=44 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo" # string offset=48 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "short" # string offset=52 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo.b" # string offset=58 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=64 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=69 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "maps" # string offset=71 +; CHECK-NEXT: .byte 0 + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" } + +!llvm.dbg.cu = !{!7} +!llvm.module.flags = !{!18, !19, !20} +!llvm.ident = !{!21} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !15, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !DISubroutineType(types: !5) +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) +!8 = !{} +!9 = !{!0, !10} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) +!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13) +!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !14) +!14 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!15 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !16) +!16 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !17) +!17 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) +!18 = !{i32 2, !"Dwarf Version", i32 4} +!19 = !{i32 2, !"Debug Info Version", i32 3} +!20 = !{i32 1, !"wchar_size", i32 4} +!21 = !{!"clang version 8.0.20181009 "} +!22 = !DILocation(line: 4, column: 10, scope: !2) +!23 = !{!24, !24, i64 0} +!24 = !{!"omnipotent char", !25, i64 0} +!25 = !{!"Simple C/C++ TBAA"} +!26 = !DILocation(line: 4, column: 14, scope: !2) +!27 = !{!28, !28, i64 0} +!28 = !{!"short", !24, i64 0} +!29 = !DILocation(line: 4, column: 12, scope: !2) +!30 = !DILocation(line: 4, column: 3, scope: !2) Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll @@ -0,0 +1,138 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; static volatile const char a; +; int foo() { +; static volatile const short b = 3; +; return a + b; +; } +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@foo.b = internal constant i16 3, align 2, !dbg !0 +@a = internal constant i8 0, align 1, !dbg !10 + +; Function Attrs: norecurse nounwind +define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 { + %1 = load volatile i8, i8* @a, align 1, !dbg !22, !tbaa !23 + %2 = sext i8 %1 to i32, !dbg !22 + %3 = load volatile i16, i16* @foo.b, align 2, !dbg !26, !tbaa !27 + %4 = sext i16 %3 to i32, !dbg !26 + %5 = add nsw i32 %4, %2, !dbg !29 + ret i32 %5, !dbg !30 +} + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 188 +; CHECK-NEXT: .long 188 +; CHECK-NEXT: .long 79 +; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) +; CHECK-NEXT: .long 218103808 # 0xd000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3) +; CHECK-NEXT: .long 201326592 # 0xc000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 4) +; CHECK-NEXT: .long 167772160 # 0xa000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 5) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 6) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 16777232 # 0x1000010 +; CHECK-NEXT: .long 58 # BTF_KIND_VAR(id = 7) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 0 # BTF_KIND_CONST(id = 8) +; CHECK-NEXT: .long 167772160 # 0xa000000 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 9) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 10 +; CHECK-NEXT: .long 64 # BTF_KIND_INT(id = 10) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 69 # BTF_KIND_VAR(id = 11) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 10 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 71 # BTF_KIND_DATASEC(id = 12) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 7 +; CHECK-NEXT: .long foo.b +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 11 +; CHECK-NEXT: .long a +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii ".text" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "int" # string offset=44 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo" # string offset=48 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "short" # string offset=52 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo.b" # string offset=58 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=64 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=69 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii ".rodata" # string offset=71 +; CHECK-NEXT: .byte 0 + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" } + +!llvm.dbg.cu = !{!7} +!llvm.module.flags = !{!18, !19, !20} +!llvm.ident = !{!21} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !15, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !DISubroutineType(types: !5) +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) +!8 = !{} +!9 = !{!0, !10} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) +!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13) +!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !14) +!14 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!15 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !16) +!16 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !17) +!17 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) +!18 = !{i32 2, !"Dwarf Version", i32 4} +!19 = !{i32 2, !"Debug Info Version", i32 3} +!20 = !{i32 1, !"wchar_size", i32 4} +!21 = !{!"clang version 8.0.20181009 "} +!22 = !DILocation(line: 4, column: 10, scope: !2) +!23 = !{!24, !24, i64 0} +!24 = !{!"omnipotent char", !25, i64 0} +!25 = !{!"Simple C/C++ TBAA"} +!26 = !DILocation(line: 4, column: 14, scope: !2) +!27 = !{!28, !28, i64 0} +!28 = !{!"short", !24, i64 0} +!29 = !DILocation(line: 4, column: 12, scope: !2) +!30 = !DILocation(line: 4, column: 3, scope: !2) Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll @@ -0,0 +1,130 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; static volatile char a __attribute__((section("maps"))); +; int foo() { +; static volatile short b __attribute__((section("maps"))); +; return a + b; +; } +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@foo.b = internal global i16 0, section "maps", align 2, !dbg !0 +@a = internal global i8 0, section "maps", align 1, !dbg !10 + +; Function Attrs: norecurse nounwind +define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 { + %1 = load volatile i8, i8* @a, align 1, !dbg !20, !tbaa !21 + %2 = sext i8 %1 to i32, !dbg !20 + %3 = load volatile i16, i16* @foo.b, align 2, !dbg !24, !tbaa !25 + %4 = sext i16 %3 to i32, !dbg !24 + %5 = add nsw i32 %4, %2, !dbg !27 + ret i32 %5, !dbg !28 +} + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 76 +; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) +; CHECK-NEXT: .long 218103808 # 0xd000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3) +; CHECK-NEXT: .long 201326592 # 0xc000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 5) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 16777232 # 0x1000010 +; CHECK-NEXT: .long 58 # BTF_KIND_VAR(id = 6) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 7) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 64 # BTF_KIND_INT(id = 8) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 69 # BTF_KIND_VAR(id = 9) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 71 # BTF_KIND_DATASEC(id = 10) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long foo.b +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long a +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii ".text" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "int" # string offset=44 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo" # string offset=48 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "short" # string offset=52 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "foo.b" # string offset=58 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=64 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=69 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "maps" # string offset=71 +; CHECK-NEXT: .byte 0 + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" } + +!llvm.dbg.cu = !{!7} +!llvm.module.flags = !{!16, !17, !18} +!llvm.ident = !{!19} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !14, isLocal: true, isDefinition: true) +!2 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !4, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !7, retainedNodes: !8) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !DISubroutineType(types: !5) +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !8, globals: !9, nameTableKind: None) +!8 = !{} +!9 = !{!0, !10} +!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression()) +!11 = distinct !DIGlobalVariable(name: "a", scope: !7, file: !3, line: 1, type: !12, isLocal: true, isDefinition: true) +!12 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !15) +!15 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) +!16 = !{i32 2, !"Dwarf Version", i32 4} +!17 = !{i32 2, !"Debug Info Version", i32 3} +!18 = !{i32 1, !"wchar_size", i32 4} +!19 = !{!"clang version 8.0.20181009 "} +!20 = !DILocation(line: 4, column: 10, scope: !2) +!21 = !{!22, !22, i64 0} +!22 = !{!"omnipotent char", !23, i64 0} +!23 = !{!"Simple C/C++ TBAA"} +!24 = !DILocation(line: 4, column: 14, scope: !2) +!25 = !{!26, !26, i64 0} +!26 = !{!"short", !22, i64 0} +!27 = !DILocation(line: 4, column: 12, scope: !2) +!28 = !DILocation(line: 4, column: 3, scope: !2) Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll @@ -0,0 +1,142 @@ +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s +; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s + +; Source code: +; struct t { +; int a; +; int b; +; char c[]; +; }; +; static volatile struct t sv = {3, 4, "abcdefghi"}; +; int test() { return sv.a; } +; Compilation flag: +; clang -target bpf -O2 -g -S -emit-llvm test.c + +@sv = internal global { i32, i32, [10 x i8] } { i32 3, i32 4, [10 x i8] c"abcdefghi\00" }, align 4, !dbg !0 + +; Function Attrs: norecurse nounwind +define dso_local i32 @test() local_unnamed_addr #0 !dbg !21 { + %1 = load volatile i32, i32* getelementptr inbounds ({ i32, i32, [10 x i8] }, { i32, i32, [10 x i8] }* @sv, i64 0, i32 0), align 4, !dbg !24, !tbaa !25 + ret i32 %1, !dbg !29 +} + +; CHECK: .section .BTF,"",@progbits +; CHECK-NEXT: .short 60319 # 0xeb9f +; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .long 24 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 196 +; CHECK-NEXT: .long 196 +; CHECK-NEXT: .long 95 +; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) +; CHECK-NEXT: .long 218103808 # 0xd000000 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 44 # BTF_KIND_INT(id = 2) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 16777248 # 0x1000020 +; CHECK-NEXT: .long 48 # BTF_KIND_FUNC(id = 3) +; CHECK-NEXT: .long 201326592 # 0xc000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 4) +; CHECK-NEXT: .long 150994944 # 0x9000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 53 # BTF_KIND_STRUCT(id = 5) +; CHECK-NEXT: .long 67108867 # 0x4000003 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 55 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 0 # 0x0 +; CHECK-NEXT: .long 57 +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 32 # 0x20 +; CHECK-NEXT: .long 59 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long 64 # 0x40 +; CHECK-NEXT: .long 0 # BTF_KIND_ARRAY(id = 6) +; CHECK-NEXT: .long 50331648 # 0x3000000 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 7 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 61 # BTF_KIND_INT(id = 7) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .long 32 # 0x20 +; CHECK-NEXT: .long 81 # BTF_KIND_INT(id = 8) +; CHECK-NEXT: .long 16777216 # 0x1000000 +; CHECK-NEXT: .long 1 +; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 86 # BTF_KIND_VAR(id = 9) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 89 # BTF_KIND_DATASEC(id = 10) +; CHECK-NEXT: .long 251658241 # 0xf000001 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long sv +; CHECK-NEXT: .long 20 +; CHECK-NEXT: .byte 0 # string offset=0 +; CHECK-NEXT: .ascii ".text" # string offset=1 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "/home/yhs/work/tests/llvm/bug/test.c" # string offset=7 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "int" # string offset=44 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "test" # string offset=48 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 116 # string offset=53 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=55 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 98 # string offset=57 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 99 # string offset=59 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "__ARRAY_SIZE_TYPE__" # string offset=61 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=81 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "sv" # string offset=86 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii ".data" # string offset=89 +; CHECK-NEXT: .byte 0 + +attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" } + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!17, !18, !19} +!llvm.ident = !{!20} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "sv", scope: !2, file: !3, line: 6, type: !6, isLocal: true, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None) +!3 = !DIFile(filename: "test.c", directory: "/home/yhs/work/tests/llvm/bug") +!4 = !{} +!5 = !{!0} +!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7) +!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", file: !3, line: 1, size: 64, elements: !8) +!8 = !{!9, !11, !12} +!9 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !7, file: !3, line: 2, baseType: !10, size: 32) +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!11 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !7, file: !3, line: 3, baseType: !10, size: 32, offset: 32) +!12 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !7, file: !3, line: 4, baseType: !13, offset: 64) +!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, elements: !15) +!14 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!15 = !{!16} +!16 = !DISubrange(count: -1) +!17 = !{i32 2, !"Dwarf Version", i32 4} +!18 = !{i32 2, !"Debug Info Version", i32 3} +!19 = !{i32 1, !"wchar_size", i32 4} +!20 = !{!"clang version 8.0.20181009 "} +!21 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 7, type: !22, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !2, retainedNodes: !4) +!22 = !DISubroutineType(types: !23) +!23 = !{!10} +!24 = !DILocation(line: 7, column: 24, scope: !21) +!25 = !{!26, !26, i64 0} +!26 = !{!"int", !27, i64 0} +!27 = !{!"omnipotent char", !28, i64 0} +!28 = !{!"Simple C/C++ TBAA"} +!29 = !DILocation(line: 7, column: 14, scope: !21) Index: llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll +++ llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll @@ -29,9 +29,9 @@ ; CHECK-NEXT: .byte 0 ; CHECK-NEXT: .long 24 ; CHECK-NEXT: .long 0 -; CHECK-NEXT: .long 96 -; CHECK-NEXT: .long 96 -; CHECK-NEXT: .long 63 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 164 +; CHECK-NEXT: .long 76 ; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1) ; CHECK-NEXT: .long 218103808 # 0xd000000 ; CHECK-NEXT: .long 2 @@ -49,13 +49,30 @@ ; CHECK-NEXT: .long 16777216 # 0x1000000 ; CHECK-NEXT: .long 2 ; CHECK-NEXT: .long 16777232 # 0x1000010 -; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 6) +; CHECK-NEXT: .long 58 # BTF_KIND_VAR(id = 6) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 5 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 0 # BTF_KIND_VOLATILE(id = 7) ; CHECK-NEXT: .long 150994944 # 0x9000000 -; CHECK-NEXT: .long 7 -; CHECK-NEXT: .long 58 # BTF_KIND_INT(id = 7) +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 64 # BTF_KIND_INT(id = 8) ; CHECK-NEXT: .long 16777216 # 0x1000000 ; CHECK-NEXT: .long 1 ; CHECK-NEXT: .long 16777224 # 0x1000008 +; CHECK-NEXT: .long 69 # BTF_KIND_VAR(id = 9) +; CHECK-NEXT: .long 234881024 # 0xe000000 +; CHECK-NEXT: .long 8 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 71 # BTF_KIND_DATASEC(id = 10) +; CHECK-NEXT: .long 251658242 # 0xf000002 +; CHECK-NEXT: .long 0 +; CHECK-NEXT: .long 6 +; CHECK-NEXT: .long foo.b +; CHECK-NEXT: .long 2 +; CHECK-NEXT: .long 9 +; CHECK-NEXT: .long a +; CHECK-NEXT: .long 1 ; CHECK-NEXT: .byte 0 # string offset=0 ; CHECK-NEXT: .ascii ".text" # string offset=1 ; CHECK-NEXT: .byte 0 @@ -67,7 +84,13 @@ ; CHECK-NEXT: .byte 0 ; CHECK-NEXT: .ascii "short" # string offset=52 ; CHECK-NEXT: .byte 0 -; CHECK-NEXT: .ascii "char" # string offset=58 +; CHECK-NEXT: .ascii "foo.b" # string offset=58 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "char" # string offset=64 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 97 # string offset=69 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii ".bss" # string offset=71 ; CHECK-NEXT: .byte 0 attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }