[llvm] r356326 - [BPF] Add BTF Var and DataSec Support
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 16 08:36:31 PDT 2019
Author: yhs
Date: Sat Mar 16 08:36:31 2019
New Revision: 356326
URL: http://llvm.org/viewvc/llvm-project?rev=356326&view=rev
Log:
[BPF] Add BTF Var and DataSec Support
Two new kinds, BTF_KIND_VAR and BTF_KIND_DATASEC, are added.
BTF_KIND_VAR has the following specification:
btf_type.name: var name
btf_type.info: type kind
btf_type.type: var type
// btf_type is followed by one u32
u32: varinfo (currently, only 0 - static, 1 - global allocated in elf sections)
Not all globals are supported in this patch. The following globals are supported:
. static variables with or without section attributes
. global variables with section attributes
The inclusion of globals with section attributes
is for future potential extraction of key/value
type id's from map definition.
BTF_KIND_DATASEC has the following specification:
btf_type.name: section name associated with variable or
one of .data/.bss/.readonly
btf_type.info: type kind and vlen for # of variables
btf_type.size: 0
#vlen number of the following:
u32: id of corresponding BTF_KIND_VAR
u32: in-session offset of the var
u32: the size of memory var occupied
At the time of debug info emission, the data section
size is unknown, so the btf_type.size = 0 for
BTF_KIND_DATASEC. The loader can patch it during
loading time.
The in-session offseet of the var is only available
for static variables. For global variables, the
loader neeeds to assign the global variable symbol value in
symbol table to in-section offset.
The size of memory is used to specify the amount of the
memory a variable occupies. Typically, it equals to
the type size, but for certain structures, e.g.,
struct tt {
int a;
int b;
char c[];
};
static volatile struct tt s2 = {3, 4, "abcdefghi"};
The static variable s2 has size of 20.
Note that for BTF_KIND_DATASEC name, the section name
does not contain object name. The compiler does have
input module name. For example, two cases below:
. clang -target bpf -O2 -g -c test.c
The compiler knows the input file (module) is test.c
and can generate sec name like test.data/test.bss etc.
. clang -target bpf -O2 -g -emit-llvm -c test.c -o - |
llc -march=bpf -filetype=obj -o test.o
The llc compiler has the input file as stdin, and
would generate something like stdin.data/stdin.bss etc.
which does not really make sense.
For any user specificed section name, e.g.,
static volatile int a __attribute__((section("id1")));
static volatile const int b __attribute__((section("id2")));
The DataSec with name "id1" and "id2" does not contain
information whether the section is readonly or not.
The loader needs to check the corresponding elf section
flags for such information.
A simple example:
-bash-4.4$ cat t.c
int g1;
int g2 = 3;
const int g3 = 4;
static volatile int s1;
struct tt {
int a;
int b;
char c[];
};
static volatile struct tt s2 = {3, 4, "abcdefghi"};
static volatile const int s3 = 4;
int m __attribute__((section("maps"), used)) = 4;
int test() { return g1 + g2 + g3 + s1 + s2.a + s3 + m; }
-bash-4.4$ clang -target bpf -O2 -g -S t.c
Checking t.s, 4 BTF_KIND_VAR's are generated (s1, s2, s3 and m).
4 BTF_KIND_DATASEC's are generated with names
".data", ".bss", ".rodata" and "maps".
Signed-off-by: Yonghong Song <yhs at fb.com>
Differential Revision: https://reviews.llvm.org/D59441
Added:
llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll
llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll
llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll
- copied, changed from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll
- copied, changed from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll
- copied, changed from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll
- copied, changed from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll
- copied, changed from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll
Modified:
llvm/trunk/lib/Target/BPF/BTF.def
llvm/trunk/lib/Target/BPF/BTF.h
llvm/trunk/lib/Target/BPF/BTFDebug.cpp
llvm/trunk/lib/Target/BPF/BTFDebug.h
llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
Modified: llvm/trunk/lib/Target/BPF/BTF.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BTF.def?rev=356326&r1=356325&r2=356326&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BTF.def (original)
+++ llvm/trunk/lib/Target/BPF/BTF.def Sat Mar 16 08:36:31 2019
@@ -28,5 +28,7 @@ HANDLE_BTF_KIND(10, CONST)
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
Modified: llvm/trunk/lib/Target/BPF/BTF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BTF.h?rev=356326&r1=356325&r2=356326&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BTF.h (original)
+++ llvm/trunk/lib/Target/BPF/BTF.h Sat Mar 16 08:36:31 2019
@@ -55,6 +55,7 @@ enum {
BTFEnumSize = 8,
BTFMemberSize = 12,
BTFParamSize = 8,
+ BTFDataSecVarSize = 12,
SecFuncInfoSize = 8,
SecLineInfoSize = 8,
BPFFuncInfoSize = 8,
@@ -76,7 +77,7 @@ struct Header {
};
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 @@ struct CommonType {
/// "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 @@ struct CommonType {
// 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 @@ struct BTFParam {
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;
Modified: llvm/trunk/lib/Target/BPF/BTFDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BTFDebug.cpp?rev=356326&r1=356325&r2=356326&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BTFDebug.cpp (original)
+++ llvm/trunk/lib/Target/BPF/BTFDebug.cpp Sat Mar 16 08:36:31 2019
@@ -302,6 +302,45 @@ void BTFTypeFunc::completeType(BTFDebug
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 @@ BTFDebug::BTFDebug(AsmPrinter *AP)
addString("\0");
}
-void BTFDebug::addType(std::unique_ptr<BTFTypeBase> TypeEntry,
- const DIType *Ty) {
+uint32_t BTFDebug::addType(std::unique_ptr<BTFTypeBase> 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<BTFTypeBase> TypeEntry) {
@@ -336,7 +377,7 @@ uint32_t BTFDebug::addType(std::unique_p
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 @@ void BTFDebug::visitBasicType(const DIBa
// DIToIdMap for cross-type reference check.
auto TypeEntry = llvm::make_unique<BTFTypeInt>(
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 @@ void BTFDebug::visitSubroutineType(
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 @@ void BTFDebug::visitSubroutineType(
}
/// 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 @@ void BTFDebug::visitStructType(const DIC
auto TypeEntry =
llvm::make_unique<BTFTypeStruct>(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<DIDerivedType>(Element));
}
-void BTFDebug::visitArrayType(const DICompositeType *CTy) {
+void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
auto TypeEntry = llvm::make_unique<BTFTypeArray>(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 @@ void BTFDebug::visitArrayType(const DICo
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<BTFTypeEnum>(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<BTFTypeFwd>(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<BTFTypeDerived>(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<DIBasicType>(Ty))
- visitBasicType(BTy);
+ visitBasicType(BTy, TypeId);
else if (const auto *STy = dyn_cast<DISubroutineType>(Ty))
visitSubroutineType(STy, false, std::unordered_map<uint32_t, StringRef>(),
TypeId);
else if (const auto *CTy = dyn_cast<DICompositeType>(Ty))
- visitCompositeType(CTy);
+ visitCompositeType(CTy, TypeId);
else if (const auto *DTy = dyn_cast<DIDerivedType>(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 @@ void BTFDebug::beginInstruction(const Ma
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 @@ void BTFDebug::endModule() {
SmallVector<DIGlobalVariableExpression *, 1> 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<BTFKindVar>(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<BTFKindDataSec>(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);
Modified: llvm/trunk/lib/Target/BPF/BTFDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BTFDebug.h?rev=356326&r1=356325&r2=356326&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BTFDebug.h (original)
+++ llvm/trunk/lib/Target/BPF/BTFDebug.h Sat Mar 16 08:36:31 2019
@@ -153,6 +153,37 @@ public:
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<std::tuple<uint32_t, const MCSymbol *, uint32_t>> 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 @@ class BTFDebug : public DebugHandlerBase
std::unordered_map<uint32_t, std::vector<BTFFuncInfo>> FuncInfoTable;
std::unordered_map<uint32_t, std::vector<BTFLineInfo>> LineInfoTable;
StringMap<std::vector<std::string>> FileContent;
+ std::unordered_map<std::string, std::unique_ptr<BTFKindDataSec>>
+ DataSecEntries;
/// Add types to TypeEntries.
/// @{
/// Add types to TypeEntries and DIToIdMap.
- void addType(std::unique_ptr<BTFTypeBase> TypeEntry, const DIType *Ty);
+ uint32_t addType(std::unique_ptr<BTFTypeBase> TypeEntry, const DIType *Ty);
/// Add types to TypeEntries only and return type id.
uint32_t addType(std::unique_ptr<BTFTypeBase> TypeEntry);
/// @}
@@ -213,17 +246,20 @@ class BTFDebug : public DebugHandlerBase
/// 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<uint32_t, StringRef> &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 @@ class BTFDebug : public DebugHandlerBase
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();
Added: llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll?rev=356326&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll (added)
+++ llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec-readonly.ll Sat Mar 16 08:36:31 2019
@@ -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
+
+ at gv2 = dso_local local_unnamed_addr constant i32 5, section "maps", align 4, !dbg !0
+ at gv1 = dso_local local_unnamed_addr constant i32 0, section "maps", align 4, !dbg !6
+
+; CHECK: .section .BTF,"", at 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 "}
Added: llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll?rev=356326&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll (added)
+++ llvm/trunk/test/CodeGen/BPF/BTF/global-var-sec.ll Sat Mar 16 08:36:31 2019
@@ -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
+
+ at gv2 = dso_local local_unnamed_addr global i32 5, section "maps", align 4, !dbg !0
+ at gv1 = dso_local local_unnamed_addr global i32 0, section "maps", align 4, !dbg !6
+
+; CHECK: .section .BTF,"", at 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 "}
Copied: llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll (from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll?p2=llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll&p1=llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll&r1=356325&r2=356326&rev=356326&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited-sec.ll Sat Mar 16 08:36:31 2019
@@ -2,16 +2,16 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
-; static volatile char a;
+; static volatile char a __attribute__((section("maps"))) = 3;
; int foo() {
-; static volatile short b;
+; static volatile short b __attribute__((section("maps"))) = 4;
; return a + b;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
- at foo.b = internal global i16 0, align 2, !dbg !0
- at a = internal global i8 0, align 1, !dbg !10
+ at foo.b = internal global i16 4, section "maps", align 2, !dbg !0
+ at 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 {
@@ -29,9 +29,9 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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 "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" }
Copied: llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll (from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll?p2=llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll&p1=llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll&r1=356325&r2=356326&rev=356326&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-inited.ll Sat Mar 16 08:36:31 2019
@@ -2,16 +2,16 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
-; static volatile char a;
+; static volatile char a = 3;
; int foo() {
-; static volatile short b;
+; static volatile short b = 4;
; return a + b;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
- at foo.b = internal global i16 0, align 2, !dbg !0
- at a = internal global i8 0, align 1, !dbg !10
+ at foo.b = internal global i16 4, align 2, !dbg !0
+ at a = internal global i8 3, align 1, !dbg !10
; Function Attrs: norecurse nounwind
define dso_local i32 @foo() local_unnamed_addr #0 !dbg !2 {
@@ -29,9 +29,9 @@ define dso_local i32 @foo() local_unname
; 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 77
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
; CHECK-NEXT: .long 218103808 # 0xd000000
; CHECK-NEXT: .long 2
@@ -49,13 +49,30 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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 ".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" }
Copied: llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll (from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll?p2=llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll&p1=llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll&r1=356325&r2=356326&rev=356326&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly-sec.ll Sat Mar 16 08:36:31 2019
@@ -2,25 +2,25 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
-; static volatile char a;
+; static volatile const char __attribute__((section("maps"))) a;
; int foo() {
-; static volatile short b;
+; static volatile const short b __attribute__((section("maps"))) = 3;
; return a + b;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
- at foo.b = internal global i16 0, align 2, !dbg !0
- at a = internal global i8 0, align 1, !dbg !10
+ at foo.b = internal constant i16 3, section "maps", align 2, !dbg !0
+ at 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 !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
+ %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,"", at progbits
@@ -29,9 +29,9 @@ define dso_local i32 @foo() local_unname
; 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 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
@@ -42,20 +42,43 @@ define dso_local i32 @foo() local_unname
; 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 0 # BTF_KIND_CONST(id = 4)
+; CHECK-NEXT: .long 167772160 # 0xa000000
; CHECK-NEXT: .long 5
-; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 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 0 # BTF_KIND_VOLATILE(id = 6)
+; 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 7
-; CHECK-NEXT: .long 58 # BTF_KIND_INT(id = 7)
+; 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
@@ -67,17 +90,23 @@ define dso_local i32 @foo() local_unname
; 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 "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}
+!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: !14, isLocal: true, isDefinition: true)
+!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)
@@ -88,20 +117,22 @@ attributes #0 = { norecurse nounwind "co
!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)
+!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)
Copied: llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll (from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll?p2=llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll&p1=llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll&r1=356325&r2=356326&rev=356326&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-readonly.ll Sat Mar 16 08:36:31 2019
@@ -2,25 +2,25 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
-; static volatile char a;
+; static volatile const char a;
; int foo() {
-; static volatile short b;
+; static volatile const short b = 3;
; return a + b;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
- at foo.b = internal global i16 0, align 2, !dbg !0
- at a = internal global i8 0, align 1, !dbg !10
+ at foo.b = internal constant i16 3, align 2, !dbg !0
+ at 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 !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
+ %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,"", at progbits
@@ -29,9 +29,9 @@ define dso_local i32 @foo() local_unname
; 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 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
@@ -42,20 +42,43 @@ define dso_local i32 @foo() local_unname
; 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 0 # BTF_KIND_CONST(id = 4)
+; CHECK-NEXT: .long 167772160 # 0xa000000
; CHECK-NEXT: .long 5
-; CHECK-NEXT: .long 52 # BTF_KIND_INT(id = 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 0 # BTF_KIND_VOLATILE(id = 6)
+; 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 7
-; CHECK-NEXT: .long 58 # BTF_KIND_INT(id = 7)
+; 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
@@ -67,17 +90,23 @@ define dso_local i32 @foo() local_unname
; 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 ".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 = !{!16, !17, !18}
-!llvm.ident = !{!19}
+!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: !14, isLocal: true, isDefinition: true)
+!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)
@@ -88,20 +117,22 @@ attributes #0 = { norecurse nounwind "co
!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)
+!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)
Copied: llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll (from r356325, llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll?p2=llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll&p1=llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll&r1=356325&r2=356326&rev=356326&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-sec.ll Sat Mar 16 08:36:31 2019
@@ -2,16 +2,16 @@
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
; Source code:
-; static volatile char a;
+; static volatile char a __attribute__((section("maps")));
; int foo() {
-; static volatile short b;
+; static volatile short b __attribute__((section("maps")));
; return a + b;
; }
; Compilation flag:
; clang -target bpf -O2 -g -S -emit-llvm test.c
- at foo.b = internal global i16 0, align 2, !dbg !0
- at a = internal global i8 0, align 1, !dbg !10
+ at foo.b = internal global i16 0, section "maps", align 2, !dbg !0
+ at 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 {
@@ -29,9 +29,9 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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 "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" }
Added: llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll?rev=356326&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll (added)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var-zerolen-array.ll Sat Mar 16 08:36:31 2019
@@ -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
+
+ at 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,"", at 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)
Modified: llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll?rev=356326&r1=356325&r2=356326&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/BTF/static-var.ll Sat Mar 16 08:36:31 2019
@@ -29,9 +29,9 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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 @@ define dso_local i32 @foo() local_unname
; 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" }
More information about the llvm-commits
mailing list