diff options
author | Fangrui Song <maskray@google.com> | 2018-10-12 17:41:12 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2018-10-12 17:41:12 +0000 |
commit | 19b8fa5c5a401c2b466c09bb2de645bb6844bb6b (patch) | |
tree | 91f4233632131a250a0d06278582d4fbfd8d5c21 /llvm | |
parent | 60422354509e189bb95c2af728a5313bc02b279c (diff) | |
download | bcm5719-llvm-19b8fa5c5a401c2b466c09bb2de645bb6844bb6b.tar.gz bcm5719-llvm-19b8fa5c5a401c2b466c09bb2de645bb6844bb6b.zip |
[BPF] Don't include linux/types.h and fix style
llvm-svn: 344381
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/MC/MCBTFContext.h | 255 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp | 280 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h | 16 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfFile.h | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCBTFContext.cpp | 48 | ||||
-rw-r--r-- | llvm/lib/MC/MCDwarf2BTF.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/MC/MCDwarf2BTF.h | 11 |
7 files changed, 309 insertions, 322 deletions
diff --git a/llvm/include/llvm/MC/MCBTFContext.h b/llvm/include/llvm/MC/MCBTFContext.h index fd9edbcf7a8..43103273acb 100644 --- a/llvm/include/llvm/MC/MCBTFContext.h +++ b/llvm/include/llvm/MC/MCBTFContext.h @@ -15,10 +15,16 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/Support/raw_ostream.h" -#include <linux/types.h> #include <map> #include <vector> +typedef __signed__ char __s8; +typedef unsigned char __u8; +typedef __signed__ short __s16; +typedef unsigned short __u16; +typedef __signed__ int __s32; +typedef unsigned int __u32; + #define BTF_MAGIC 0xeB9F #define BTF_VERSION 1 @@ -36,53 +42,53 @@ struct btf_header { }; /* Max # of type identifier */ -#define BTF_MAX_TYPE 0x0000ffff +#define BTF_MAX_TYPE 0x0000ffff /* Max offset into the string section */ -#define BTF_MAX_NAME_OFFSET 0x0000ffff +#define BTF_MAX_NAME_OFFSET 0x0000ffff /* Max # of struct/union/enum members or func args */ -#define BTF_MAX_VLEN 0xffff +#define BTF_MAX_VLEN 0xffff struct btf_type { - __u32 name_off; - /* "info" bits arrangement - * bits 0-15: vlen (e.g. # of struct's members) - * bits 16-23: unused - * bits 24-27: kind (e.g. int, ptr, array...etc) - * bits 28-31: unused - */ - __u32 info; - /* "size" is used by INT, ENUM, STRUCT and UNION. - * "size" tells the size of the type it is describing. - * - * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, - * FUNC and FUNC_PROTO. - * "type" is a type_id referring to another type. - */ - union { - __u32 size; - __u32 type; - }; + __u32 name_off; + /* "info" bits arrangement + * bits 0-15: vlen (e.g. # of struct's members) + * bits 16-23: unused + * bits 24-27: kind (e.g. int, ptr, array...etc) + * bits 28-31: unused + */ + __u32 info; + /* "size" is used by INT, ENUM, STRUCT and UNION. + * "size" tells the size of the type it is describing. + * + * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, + * FUNC and FUNC_PROTO. + * "type" is a type_id referring to another type. + */ + union { + __u32 size; + __u32 type; + }; }; -#define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f) -#define BTF_INFO_VLEN(info) ((info) & 0xffff) - -#define BTF_KIND_UNKN 0 /* Unknown */ -#define BTF_KIND_INT 1 /* Integer */ -#define BTF_KIND_PTR 2 /* Pointer */ -#define BTF_KIND_ARRAY 3 /* Array */ -#define BTF_KIND_STRUCT 4 /* Struct */ -#define BTF_KIND_UNION 5 /* Union */ -#define BTF_KIND_ENUM 6 /* Enumeration */ -#define BTF_KIND_FWD 7 /* Forward */ -#define BTF_KIND_TYPEDEF 8 /* Typedef */ -#define BTF_KIND_VOLATILE 9 /* Volatile */ -#define BTF_KIND_CONST 10 /* Const */ -#define BTF_KIND_RESTRICT 11 /* Restrict */ -#define BTF_KIND_FUNC 12 /* Function */ -#define BTF_KIND_FUNC_PROTO 13 /* Function Prototype */ -#define BTF_KIND_MAX 13 -#define NR_BTF_KINDS 14 +#define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f) +#define BTF_INFO_VLEN(info) ((info)&0xffff) + +#define BTF_KIND_UNKN 0 /* Unknown */ +#define BTF_KIND_INT 1 /* Integer */ +#define BTF_KIND_PTR 2 /* Pointer */ +#define BTF_KIND_ARRAY 3 /* Array */ +#define BTF_KIND_STRUCT 4 /* Struct */ +#define BTF_KIND_UNION 5 /* Union */ +#define BTF_KIND_ENUM 6 /* Enumeration */ +#define BTF_KIND_FWD 7 /* Forward */ +#define BTF_KIND_TYPEDEF 8 /* Typedef */ +#define BTF_KIND_VOLATILE 9 /* Volatile */ +#define BTF_KIND_CONST 10 /* Const */ +#define BTF_KIND_RESTRICT 11 /* Restrict */ +#define BTF_KIND_FUNC 12 /* Function */ +#define BTF_KIND_FUNC_PROTO 13 /* Function Prototype */ +#define BTF_KIND_MAX 13 +#define NR_BTF_KINDS 14 /* For some specific BTF_KIND, "struct btf_type" is immediately * followed by extra data. @@ -91,29 +97,29 @@ struct btf_type { /* BTF_KIND_INT is followed by a u32 and the following * is the 32 bits arrangement: */ -#define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) -#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) -#define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff) +#define BTF_INT_ENCODING(VAL) (((VAL)&0x0f000000) >> 24) +#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) +#define BTF_INT_BITS(VAL) ((VAL)&0x000000ff) /* Attributes stored in the BTF_INT_ENCODING */ -#define BTF_INT_SIGNED (1 << 0) -#define BTF_INT_CHAR (1 << 1) -#define BTF_INT_BOOL (1 << 2) +#define BTF_INT_SIGNED (1 << 0) +#define BTF_INT_CHAR (1 << 1) +#define BTF_INT_BOOL (1 << 2) /* BTF_KIND_ENUM is followed by multiple "struct btf_enum". * The exact number of btf_enum is stored in the vlen (of the * info in "struct btf_type"). */ struct btf_enum { - __u32 name_off; - __s32 val; + __u32 name_off; + __s32 val; }; /* BTF_KIND_ARRAY is followed by one "struct btf_array" */ struct btf_array { - __u32 type; - __u32 index_type; - __u32 nelems; + __u32 type; + __u32 index_type; + __u32 nelems; }; /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed @@ -122,64 +128,57 @@ struct btf_array { * "struct btf_type"). */ struct btf_member { - __u32 name_off; - __u32 type; - __u32 offset; /* offset in bits */ + __u32 name_off; + __u32 type; + __u32 offset; /* offset in bits */ }; /* .BTF.ext section contains func_info and line_info. */ struct btf_ext_header { - __u16 magic; - __u8 version; - __u8 flags; - __u32 hdr_len; - - __u32 func_info_off; - __u32 func_info_len; - __u32 line_info_off; - __u32 line_info_len; + __u16 magic; + __u8 version; + __u8 flags; + __u32 hdr_len; + + __u32 func_info_off; + __u32 func_info_len; + __u32 line_info_off; + __u32 line_info_len; }; struct bpf_func_info { - __u32 insn_offset; - __u32 type_id; + __u32 insn_offset; + __u32 type_id; }; struct btf_sec_func_info { - __u32 sec_name_off; - __u32 num_func_info; + __u32 sec_name_off; + __u32 num_func_info; }; struct bpf_line_info { - __u32 insn_offset; - __u32 file_name_off; - __u32 line_off; - __u32 line_col; /* line num: line_col >> 10, col num: line_col & 0x3ff */ + __u32 insn_offset; + __u32 file_name_off; + __u32 line_off; + __u32 line_col; /* line num: line_col >> 10, col num: line_col & 0x3ff */ }; struct btf_sec_line_info { - __u32 sec_name_off; - __u32 num_line_info; + __u32 sec_name_off; + __u32 num_line_info; }; namespace llvm { const char *const btf_kind_str[NR_BTF_KINDS] = { - [BTF_KIND_UNKN] = "UNKNOWN", - [BTF_KIND_INT] = "INT", - [BTF_KIND_PTR] = "PTR", - [BTF_KIND_ARRAY] = "ARRAY", - [BTF_KIND_STRUCT] = "STRUCT", - [BTF_KIND_UNION] = "UNION", - [BTF_KIND_ENUM] = "ENUM", - [BTF_KIND_FWD] = "FWD", - [BTF_KIND_TYPEDEF] = "TYPEDEF", - [BTF_KIND_VOLATILE] = "VOLATILE", - [BTF_KIND_CONST] = "CONST", - [BTF_KIND_RESTRICT] = "RESTRICT", - [BTF_KIND_FUNC] = "FUNC", - [BTF_KIND_FUNC_PROTO] = "FUNC_PROTO", + [BTF_KIND_UNKN] = "UNKNOWN", [BTF_KIND_INT] = "INT", + [BTF_KIND_PTR] = "PTR", [BTF_KIND_ARRAY] = "ARRAY", + [BTF_KIND_STRUCT] = "STRUCT", [BTF_KIND_UNION] = "UNION", + [BTF_KIND_ENUM] = "ENUM", [BTF_KIND_FWD] = "FWD", + [BTF_KIND_TYPEDEF] = "TYPEDEF", [BTF_KIND_VOLATILE] = "VOLATILE", + [BTF_KIND_CONST] = "CONST", [BTF_KIND_RESTRICT] = "RESTRICT", + [BTF_KIND_FUNC] = "FUNC", [BTF_KIND_FUNC_PROTO] = "FUNC_PROTO", }; class MCBTFContext; @@ -191,12 +190,11 @@ class MCObjectStreamer; // BTF_KIND_TYPEDEF, BTF_KIND_RESTRICT, and BTF_KIND_FWD class BTFTypeEntry { protected: - size_t Id; /* type index in the BTF list, started from 1 */ + size_t Id; /* type index in the BTF list, started from 1 */ struct btf_type BTFType; public: - BTFTypeEntry(size_t id, struct btf_type &type) : - Id(id), BTFType(type) {} + BTFTypeEntry(size_t id, struct btf_type &type) : Id(id), BTFType(type) {} virtual ~BTFTypeEntry(); unsigned char getKind() { return BTF_INFO_KIND(BTFType.info); } void setId(size_t Id) { this->Id = Id; } @@ -206,19 +204,19 @@ public: unsigned getTypeIndex() { return BTFType.type; } unsigned getNameOff() { return BTFType.name_off; } virtual size_t getSize() { return sizeof(struct btf_type); } - virtual void print(raw_ostream &s, MCBTFContext& BTFContext); + virtual void print(raw_ostream &s, MCBTFContext &BTFContext); virtual void emitData(MCObjectStreamer *MCOS); }; // BTF_KIND_INT class BTFTypeEntryInt : public BTFTypeEntry { - unsigned IntVal; // encoding, offset, bits + unsigned IntVal; // encoding, offset, bits public: - BTFTypeEntryInt(size_t id, struct btf_type &type, unsigned intval) : - BTFTypeEntry(id, type), IntVal(intval) {} + BTFTypeEntryInt(size_t id, struct btf_type &type, unsigned intval) + : BTFTypeEntry(id, type), IntVal(intval) {} size_t getSize() { return BTFTypeEntry::getSize() + sizeof(unsigned); } - void print(raw_ostream &s, MCBTFContext& BTFContext); + void print(raw_ostream &s, MCBTFContext &BTFContext); void emitData(MCObjectStreamer *MCOS); }; @@ -228,13 +226,13 @@ class BTFTypeEntryEnum : public BTFTypeEntry { public: BTFTypeEntryEnum(size_t id, struct btf_type &type, - std::vector<struct btf_enum> &values) : - BTFTypeEntry(id, type), EnumValues(values) {} + std::vector<struct btf_enum> &values) + : BTFTypeEntry(id, type), EnumValues(values) {} size_t getSize() { return BTFTypeEntry::getSize() + - BTF_INFO_VLEN(BTFType.info) * sizeof(struct btf_enum); + BTF_INFO_VLEN(BTFType.info) * sizeof(struct btf_enum); } - void print(raw_ostream &s, MCBTFContext& BTFContext); + void print(raw_ostream &s, MCBTFContext &BTFContext); void emitData(MCObjectStreamer *MCOS); }; @@ -244,12 +242,12 @@ class BTFTypeEntryArray : public BTFTypeEntry { public: BTFTypeEntryArray(size_t id, struct btf_type &type, - struct btf_array &arrayinfo) : - BTFTypeEntry(id, type), ArrayInfo(arrayinfo) {} + struct btf_array &arrayinfo) + : BTFTypeEntry(id, type), ArrayInfo(arrayinfo) {} size_t getSize() { - return BTFTypeEntry::getSize() + sizeof(struct btf_array); + return BTFTypeEntry::getSize() + sizeof(struct btf_array); } - void print(raw_ostream &s, MCBTFContext& BTFContext); + void print(raw_ostream &s, MCBTFContext &BTFContext); void emitData(MCObjectStreamer *MCOS); }; @@ -259,13 +257,13 @@ class BTFTypeEntryStruct : public BTFTypeEntry { public: BTFTypeEntryStruct(size_t id, struct btf_type &type, - std::vector<struct btf_member> &members) : - BTFTypeEntry(id, type), Members(members) {} + std::vector<struct btf_member> &members) + : BTFTypeEntry(id, type), Members(members) {} size_t getSize() { return BTFTypeEntry::getSize() + - BTF_INFO_VLEN(BTFType.info) * sizeof(struct btf_member); + BTF_INFO_VLEN(BTFType.info) * sizeof(struct btf_member); } - void print(raw_ostream &s, MCBTFContext& BTFContext); + void print(raw_ostream &s, MCBTFContext &BTFContext); void emitData(MCObjectStreamer *MCOS); }; @@ -275,22 +273,22 @@ class BTFTypeEntryFunc : public BTFTypeEntry { public: BTFTypeEntryFunc(size_t id, struct btf_type &type, - std::vector<unsigned> ¶ms) : - BTFTypeEntry(id, type), Parameters(params) {} + std::vector<unsigned> ¶ms) + : BTFTypeEntry(id, type), Parameters(params) {} size_t getSize() { return BTFTypeEntry::getSize() + - BTF_INFO_VLEN(BTFType.info) * sizeof(unsigned); + BTF_INFO_VLEN(BTFType.info) * sizeof(unsigned); } - void print(raw_ostream &s, MCBTFContext& BTFContext); + void print(raw_ostream &s, MCBTFContext &BTFContext); void emitData(MCObjectStreamer *MCOS); }; class BTFStringTable { - size_t Size; // total size in bytes + size_t Size; // total size in bytes std::map<size_t, unsigned> OffsetToIdMap; std::vector<std::string> Table; - public: +public: BTFStringTable() : Size(0) {} size_t getSize() { return Size; } std::vector<std::string> &getTable() { return Table; } @@ -312,22 +310,21 @@ class BTFStringTable { } void showTable(raw_ostream &OS) { for (auto OffsetM : OffsetToIdMap) - OS << OffsetM.first << " : " << Table[OffsetM.second] - << "\n"; + OS << OffsetM.first << " : " << Table[OffsetM.second] << "\n"; } }; -struct BTFFuncInfo { - const MCSymbol *Label; - unsigned int TypeId; +struct BTFFuncInfo { + const MCSymbol *Label; + unsigned int TypeId; }; -struct BTFLineInfo { - MCSymbol *Label; - unsigned int FileNameOff; - unsigned int LineOff; - unsigned int LineNum; - unsigned int ColumnNum; +struct BTFLineInfo { + MCSymbol *Label; + unsigned int FileNameOff; + unsigned int LineOff; + unsigned int LineNum; + unsigned int ColumnNum; }; class MCBTFContext { @@ -344,15 +341,13 @@ class MCBTFContext { friend class BTFTypeEntryFunc; public: - void dump(raw_ostream& OS); + void dump(raw_ostream &OS); void emitAll(MCObjectStreamer *MCOS); void emitCommonHeader(MCObjectStreamer *MCOS); void emitBTFSection(MCObjectStreamer *MCOS); void emitBTFExtSection(MCObjectStreamer *MCOS); - size_t addString(std::string S) { - return StringTable.addString(S); - } + size_t addString(std::string S) { return StringTable.addString(S); } void addTypeEntry(std::unique_ptr<BTFTypeEntry> Entry); void addFuncInfo(unsigned SecNameOff, BTFFuncInfo Info) { FuncInfoTable[SecNameOff].push_back(Info); diff --git a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp index 8b16e389963..44484c2ae05 100644 --- a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "DwarfUnit.h" #include "Dwarf2BTF.h" +#include "DwarfUnit.h" #include "llvm/MC/MCBTFContext.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSectionELF.h" @@ -17,47 +17,47 @@ namespace llvm { Die2BTFEntry::~Die2BTFEntry() {} -unsigned char Die2BTFEntry::getDieKind(const DIE & Die) { +unsigned char Die2BTFEntry::getDieKind(const DIE &Die) { auto Tag = Die.getTag(); switch (Tag) { - case dwarf::DW_TAG_base_type: - if (getBaseTypeEncoding(Die) == BTF_INVALID_ENCODING) - return BTF_KIND_UNKN; - return BTF_KIND_INT; - case dwarf::DW_TAG_const_type: - return BTF_KIND_CONST; - case dwarf::DW_TAG_pointer_type: - return BTF_KIND_PTR; - case dwarf::DW_TAG_restrict_type: - return BTF_KIND_RESTRICT; - case dwarf::DW_TAG_volatile_type: - return BTF_KIND_VOLATILE; - case dwarf::DW_TAG_typedef: - return BTF_KIND_TYPEDEF; - case dwarf::DW_TAG_structure_type: - case dwarf::DW_TAG_class_type: - if (Die.findAttribute(dwarf::DW_AT_declaration).getType() - != DIEValue::isNone) - return BTF_KIND_FWD; - else - return BTF_KIND_STRUCT; - case dwarf::DW_TAG_union_type: - if (Die.findAttribute(dwarf::DW_AT_declaration).getType() - != DIEValue::isNone) - return BTF_KIND_FWD; - else - return BTF_KIND_UNION; - case dwarf::DW_TAG_enumeration_type: - return BTF_KIND_ENUM; - case dwarf::DW_TAG_array_type: - return BTF_KIND_ARRAY; - case dwarf::DW_TAG_subprogram: - return BTF_KIND_FUNC; - case dwarf::DW_TAG_subroutine_type: - return BTF_KIND_FUNC_PROTO; - default: - break; + case dwarf::DW_TAG_base_type: + if (getBaseTypeEncoding(Die) == BTF_INVALID_ENCODING) + return BTF_KIND_UNKN; + return BTF_KIND_INT; + case dwarf::DW_TAG_const_type: + return BTF_KIND_CONST; + case dwarf::DW_TAG_pointer_type: + return BTF_KIND_PTR; + case dwarf::DW_TAG_restrict_type: + return BTF_KIND_RESTRICT; + case dwarf::DW_TAG_volatile_type: + return BTF_KIND_VOLATILE; + case dwarf::DW_TAG_typedef: + return BTF_KIND_TYPEDEF; + case dwarf::DW_TAG_structure_type: + case dwarf::DW_TAG_class_type: + if (Die.findAttribute(dwarf::DW_AT_declaration).getType() != + DIEValue::isNone) + return BTF_KIND_FWD; + else + return BTF_KIND_STRUCT; + case dwarf::DW_TAG_union_type: + if (Die.findAttribute(dwarf::DW_AT_declaration).getType() != + DIEValue::isNone) + return BTF_KIND_FWD; + else + return BTF_KIND_UNION; + case dwarf::DW_TAG_enumeration_type: + return BTF_KIND_ENUM; + case dwarf::DW_TAG_array_type: + return BTF_KIND_ARRAY; + case dwarf::DW_TAG_subprogram: + return BTF_KIND_FUNC; + case dwarf::DW_TAG_subroutine_type: + return BTF_KIND_FUNC_PROTO; + default: + break; } return BTF_KIND_UNKN; @@ -67,27 +67,27 @@ std::unique_ptr<Die2BTFEntry> Die2BTFEntry::dieToBTFTypeEntry(const DIE &Die) { unsigned char Kind = getDieKind(Die); switch (Kind) { - case BTF_KIND_INT: - return make_unique<Die2BTFEntryInt>(Die); - case BTF_KIND_PTR: - case BTF_KIND_TYPEDEF: - case BTF_KIND_VOLATILE: - case BTF_KIND_CONST: - case BTF_KIND_RESTRICT: - case BTF_KIND_FWD: - return make_unique<Die2BTFEntry>(Die); - case BTF_KIND_ARRAY: - return make_unique<Die2BTFEntryArray>(Die); - case BTF_KIND_STRUCT: - case BTF_KIND_UNION: - return make_unique<Die2BTFEntryStruct>(Die); - case BTF_KIND_ENUM: - return make_unique<Die2BTFEntryEnum>(Die); - case BTF_KIND_FUNC: - case BTF_KIND_FUNC_PROTO: - return make_unique<Die2BTFEntryFunc>(Die); - default: - break; + case BTF_KIND_INT: + return make_unique<Die2BTFEntryInt>(Die); + case BTF_KIND_PTR: + case BTF_KIND_TYPEDEF: + case BTF_KIND_VOLATILE: + case BTF_KIND_CONST: + case BTF_KIND_RESTRICT: + case BTF_KIND_FWD: + return make_unique<Die2BTFEntry>(Die); + case BTF_KIND_ARRAY: + return make_unique<Die2BTFEntryArray>(Die); + case BTF_KIND_STRUCT: + case BTF_KIND_UNION: + return make_unique<Die2BTFEntryStruct>(Die); + case BTF_KIND_ENUM: + return make_unique<Die2BTFEntryEnum>(Die); + case BTF_KIND_FUNC: + case BTF_KIND_FUNC_PROTO: + return make_unique<Die2BTFEntryFunc>(Die); + default: + break; } return nullptr; } @@ -96,20 +96,19 @@ bool Die2BTFEntry::shouldSkipDie(const DIE &Die) { auto Tag = Die.getTag(); switch (Tag) { - case dwarf::DW_TAG_const_type: - case dwarf::DW_TAG_pointer_type: - case dwarf::DW_TAG_restrict_type: - case dwarf::DW_TAG_typedef: - case dwarf::DW_TAG_volatile_type: - { - auto TypeV = Die.findAttribute(dwarf::DW_AT_type); - if (TypeV.getType() == DIEValue::isNone) - return false; - auto &TypeDie = TypeV.getDIEEntry().getEntry(); - return Die2BTFEntry::shouldSkipDie(TypeDie); - } - default: - return getDieKind(Die) == BTF_KIND_UNKN; + case dwarf::DW_TAG_const_type: + case dwarf::DW_TAG_pointer_type: + case dwarf::DW_TAG_restrict_type: + case dwarf::DW_TAG_typedef: + case dwarf::DW_TAG_volatile_type: { + auto TypeV = Die.findAttribute(dwarf::DW_AT_type); + if (TypeV.getType() == DIEValue::isNone) + return false; + auto &TypeDie = TypeV.getDIEEntry().getEntry(); + return Die2BTFEntry::shouldSkipDie(TypeDie); + } + default: + return getDieKind(Die) == BTF_KIND_UNKN; } return true; } @@ -120,26 +119,26 @@ unsigned char Die2BTFEntry::getBaseTypeEncoding(const DIE &Die) { return BTF_INVALID_ENCODING; switch (V.getDIEInteger().getValue()) { - case dwarf::DW_ATE_boolean: - return BTF_INT_BOOL; - case dwarf::DW_ATE_signed: - return BTF_INT_SIGNED; - case dwarf::DW_ATE_signed_char: - return BTF_INT_CHAR; - case dwarf::DW_ATE_unsigned: - return 0; - case dwarf::DW_ATE_unsigned_char: - return BTF_INT_CHAR; - case dwarf::DW_ATE_imaginary_float: - case dwarf::DW_ATE_packed_decimal: - case dwarf::DW_ATE_numeric_string: - case dwarf::DW_ATE_edited: - case dwarf::DW_ATE_signed_fixed: - case dwarf::DW_ATE_address: - case dwarf::DW_ATE_complex_float: - case dwarf::DW_ATE_float: - default: - break; + case dwarf::DW_ATE_boolean: + return BTF_INT_BOOL; + case dwarf::DW_ATE_signed: + return BTF_INT_SIGNED; + case dwarf::DW_ATE_signed_char: + return BTF_INT_CHAR; + case dwarf::DW_ATE_unsigned: + return 0; + case dwarf::DW_ATE_unsigned_char: + return BTF_INT_CHAR; + case dwarf::DW_ATE_imaginary_float: + case dwarf::DW_ATE_packed_decimal: + case dwarf::DW_ATE_numeric_string: + case dwarf::DW_ATE_edited: + case dwarf::DW_ATE_signed_fixed: + case dwarf::DW_ATE_address: + case dwarf::DW_ATE_complex_float: + case dwarf::DW_ATE_float: + default: + break; } return BTF_INVALID_ENCODING; } @@ -148,53 +147,53 @@ Die2BTFEntry::Die2BTFEntry(const DIE &Die) : Die(Die) { unsigned char Kind = getDieKind(Die); switch (Kind) { - case BTF_KIND_CONST: - case BTF_KIND_FWD: - case BTF_KIND_PTR: - case BTF_KIND_RESTRICT: - case BTF_KIND_TYPEDEF: - case BTF_KIND_VOLATILE: - break; - default: - assert("Invalid Die passed into BTFTypeEntry()"); - break; + case BTF_KIND_CONST: + case BTF_KIND_FWD: + case BTF_KIND_PTR: + case BTF_KIND_RESTRICT: + case BTF_KIND_TYPEDEF: + case BTF_KIND_VOLATILE: + break; + default: + assert("Invalid Die passed into BTFTypeEntry()"); + break; } BTFType.info = (Kind & 0xf) << 24; } void Die2BTFEntry::completeData(class Dwarf2BTF &Dwarf2BTF) { - auto TypeV = Die.findAttribute(dwarf::DW_AT_type); - if (TypeV.getType() == DIEValue::isNone) { - BTFType.type = 0; - } else { - auto &TypeDie = TypeV.getDIEEntry().getEntry(); - auto Type = Dwarf2BTF.getTypeIndex(TypeDie); - BTFType.type = Type; - } + auto TypeV = Die.findAttribute(dwarf::DW_AT_type); + if (TypeV.getType() == DIEValue::isNone) { + BTFType.type = 0; + } else { + auto &TypeDie = TypeV.getDIEEntry().getEntry(); + auto Type = Dwarf2BTF.getTypeIndex(TypeDie); + BTFType.type = Type; + } - unsigned char Kind = getDieKind(Die); - if (Kind != BTF_KIND_FWD) { - BTFType.name_off = 0; - } else { - auto NameV = Die.findAttribute(dwarf::DW_AT_name); - auto Str = NameV.getDIEString().getString(); - BTFType.name_off = Dwarf2BTF.addBTFString(Str); - } + unsigned char Kind = getDieKind(Die); + if (Kind != BTF_KIND_FWD) { + BTFType.name_off = 0; + } else { + auto NameV = Die.findAttribute(dwarf::DW_AT_name); + auto Str = NameV.getDIEString().getString(); + BTFType.name_off = Dwarf2BTF.addBTFString(Str); + } - auto typeEntry = make_unique<BTFTypeEntry>(Id, BTFType); - Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); + auto typeEntry = make_unique<BTFTypeEntry>(Id, BTFType); + Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); } Die2BTFEntryInt::Die2BTFEntryInt(const DIE &Die) : Die2BTFEntry(Die) { unsigned char Kind = getDieKind(Die); switch (Kind) { - case BTF_KIND_INT: - break; - default: - assert("Invalid Die passed into BTFTypeEntryInt()"); - break; + case BTF_KIND_INT: + break; + default: + assert("Invalid Die passed into BTFTypeEntryInt()"); + break; } // handle BTF_INT_ENCODING in IntVal @@ -212,7 +211,7 @@ Die2BTFEntryInt::Die2BTFEntryInt(const DIE &Die) : Die2BTFEntry(Die) { V = Die.findAttribute(dwarf::DW_AT_byte_size); __u32 Size = V.getDIEInteger().getValue() & 0xffffffff; -// handle BTF_INT_BITS in IntVal + // handle BTF_INT_BITS in IntVal V = Die.findAttribute(dwarf::DW_AT_bit_size); if (V.getType() == DIEValue::isInteger) IntVal |= V.getDIEInteger().getValue() & 0xff; @@ -225,14 +224,14 @@ Die2BTFEntryInt::Die2BTFEntryInt(const DIE &Die) : Die2BTFEntry(Die) { } void Die2BTFEntryInt::completeData(class Dwarf2BTF &Dwarf2BTF) { - auto NameV = Die.findAttribute(dwarf::DW_AT_name); - auto TypeV = Die.findAttribute(dwarf::DW_AT_type); - auto Str = NameV.getDIEString().getString(); + auto NameV = Die.findAttribute(dwarf::DW_AT_name); + auto TypeV = Die.findAttribute(dwarf::DW_AT_type); + auto Str = NameV.getDIEString().getString(); - BTFType.name_off = Dwarf2BTF.addBTFString(Str); + BTFType.name_off = Dwarf2BTF.addBTFString(Str); - auto typeEntry = make_unique<BTFTypeEntryInt>(Id, BTFType, IntVal); - Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); + auto typeEntry = make_unique<BTFTypeEntryInt>(Id, BTFType, IntVal); + Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); } Die2BTFEntryEnum::Die2BTFEntryEnum(const DIE &Die) : Die2BTFEntry(Die) { @@ -275,8 +274,7 @@ void Die2BTFEntryEnum::completeData(class Dwarf2BTF &Dwarf2BTF) { Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); } -Die2BTFEntryArray::Die2BTFEntryArray(const DIE &Die) : - Die2BTFEntry(Die) { +Die2BTFEntryArray::Die2BTFEntryArray(const DIE &Die) : Die2BTFEntry(Die) { BTFType.info = (BTF_KIND_ARRAY << 24); BTFType.size = 0; } @@ -289,7 +287,8 @@ void Die2BTFEntryArray::completeData(class Dwarf2BTF &Dwarf2BTF) { Str = NameV.getDIEString().getString(); BTFType.name_off = Dwarf2BTF.addBTFString(Str); - auto &ArrayTypeDie = Die.findAttribute(dwarf::DW_AT_type).getDIEEntry().getEntry(); + auto &ArrayTypeDie = + Die.findAttribute(dwarf::DW_AT_type).getDIEEntry().getEntry(); ArrayInfo.type = Dwarf2BTF.getTypeIndex(ArrayTypeDie); // The number of elements should count all subranges @@ -342,7 +341,6 @@ void Die2BTFEntryStruct::completeData(class Dwarf2BTF &Dwarf2BTF) { } else BTFType.name_off = 0; - for (auto &ChildDie : Die.children()) { if (ChildDie.getTag() != dwarf::DW_TAG_member) continue; @@ -456,7 +454,7 @@ void Die2BTFEntryFunc::completeData(class Dwarf2BTF &Dwarf2BTF) { } Dwarf2BTF::Dwarf2BTF(MCContext &Context, bool IsLittleEndian) - : OuterCtx(Context), IsLE(IsLittleEndian) { + : OuterCtx(Context), IsLE(IsLittleEndian) { BTFContext = make_unique<MCBTFContext>(); } @@ -470,7 +468,7 @@ void Dwarf2BTF::addTypeEntry(const DIE &Die) { auto TypeEntry = Die2BTFEntry::dieToBTFTypeEntry(Die); if (TypeEntry != nullptr) { TypeEntry->setId(TypeEntries.size() + 1); - DieToIdMap[const_cast<DIE*>(&Die)] = TypeEntry->getId(); + DieToIdMap[const_cast<DIE *>(&Die)] = TypeEntry->getId(); TypeEntries.push_back(std::move(TypeEntry)); } } @@ -500,4 +498,4 @@ void Dwarf2BTF::finish() { OuterCtx.setBTFContext(std::move(BTFContext)); } -} +} // namespace llvm diff --git a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h index 125441d37b3..a472d68ed7e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h +++ b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h @@ -26,7 +26,7 @@ class MCBTFContext; class Die2BTFEntry { protected: const DIE &Die; - size_t Id; /* type index in the BTF list, started from 1 */ + size_t Id; /* type index in the BTF list, started from 1 */ struct btf_type BTFType; public: @@ -54,7 +54,7 @@ public: // BTF_KIND_INT class Die2BTFEntryInt : public Die2BTFEntry { - __u32 IntVal; // encoding, offset, bits + __u32 IntVal; // encoding, offset, bits public: Die2BTFEntryInt(const DIE &Die); @@ -99,7 +99,7 @@ public: class Dwarf2BTF { std::vector<std::unique_ptr<Die2BTFEntry>> TypeEntries; - std::map<DIE*, size_t> DieToIdMap; + std::map<DIE *, size_t> DieToIdMap; std::unique_ptr<MCBTFContext> BTFContext; MCContext &OuterCtx; bool IsLE; @@ -110,14 +110,12 @@ public: void addDwarfCU(DwarfUnit *TheU); void finish(); __u32 getTypeIndex(DIE &Die) { - DIE *DiePtr = const_cast<DIE*>(&Die); + DIE *DiePtr = const_cast<DIE *>(&Die); assert((DieToIdMap.find(DiePtr) != DieToIdMap.end()) && "Die not added to in the BTFContext"); return DieToIdMap[DiePtr]; } - size_t addBTFString(std::string S) { - return BTFContext->addString(S); - } + size_t addBTFString(std::string S) { return BTFContext->addString(S); } void addBTFTypeEntry(std::unique_ptr<BTFTypeEntry> Entry); void addBTFFuncInfo(unsigned SecNameOff, BTFFuncInfo FuncInfo) { BTFContext->addFuncInfo(SecNameOff, FuncInfo); @@ -126,10 +124,10 @@ public: private: void addTypeEntry(const DIE &Die); bool alreadyAdded(DIE &Die) { - return DieToIdMap.find(const_cast<DIE*>(&Die)) != DieToIdMap.end(); + return DieToIdMap.find(const_cast<DIE *>(&Die)) != DieToIdMap.end(); } void completeData(); }; -} +} // namespace llvm #endif diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h index 9aafe2613f6..114f98f725d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h @@ -137,9 +137,7 @@ public: return ScopeVariables; } - DenseMap<LexicalScope *, LabelList> &getScopeLabels() { - return ScopeLabels; - } + DenseMap<LexicalScope *, LabelList> &getScopeLabels() { return ScopeLabels; } DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { return AbstractSPDies; diff --git a/llvm/lib/MC/MCBTFContext.cpp b/llvm/lib/MC/MCBTFContext.cpp index d1c30dd0b88..cb121c41552 100644 --- a/llvm/lib/MC/MCBTFContext.cpp +++ b/llvm/lib/MC/MCBTFContext.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCContext.h" #include "llvm/MC/MCBTFContext.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCObjectStreamer.h" #include <cstdlib> @@ -22,7 +22,7 @@ using namespace llvm; BTFTypeEntry::~BTFTypeEntry() {} void MCBTFContext::addTypeEntry(std::unique_ptr<BTFTypeEntry> Entry) { - TypeEntries.push_back(std::move(Entry)); + TypeEntries.push_back(std::move(Entry)); } void MCBTFContext::dump(raw_ostream &OS) { @@ -39,8 +39,7 @@ void MCBTFContext::dump(raw_ostream &OS) { for (auto &FuncSec : FuncInfoTable) { OS << "sec_name_off=" << FuncSec.first << "\n"; for (auto &FuncInfo : FuncSec.second) { - OS << "\tinsn_offset=<Omitted> type_id=" - << FuncInfo.TypeId << "\n"; + OS << "\tinsn_offset=<Omitted> type_id=" << FuncInfo.TypeId << "\n"; } } @@ -48,12 +47,9 @@ void MCBTFContext::dump(raw_ostream &OS) { for (auto &LineSec : LineInfoTable) { OS << "sec_name_off=" << LineSec.first << "\n"; for (auto &LineInfo : LineSec.second) { - OS << "\tinsn_offset=<Omitted> file_name_off=" - << LineInfo.FileNameOff - << " line_off=" << LineInfo.LineOff - << " line_num=" << LineInfo.LineNum - << " column_num=" << LineInfo.ColumnNum - << "\n"; + OS << "\tinsn_offset=<Omitted> file_name_off=" << LineInfo.FileNameOff + << " line_off=" << LineInfo.LineOff << " line_num=" << LineInfo.LineNum + << " column_num=" << LineInfo.ColumnNum << "\n"; } } } @@ -83,7 +79,7 @@ void MCBTFContext::emitBTFSection(MCObjectStreamer *MCOS) { MCOS->EmitIntValue(str_len, 4); // emit type table - for (auto &TypeEntry: TypeEntries) + for (auto &TypeEntry : TypeEntries) TypeEntry->emitData(MCOS); // emit string table @@ -146,9 +142,8 @@ void MCBTFContext::emitAll(MCObjectStreamer *MCOS) { emitBTFExtSection(MCOS); } -void BTFTypeEntry::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { - OS << "[" << Id << "] " - << btf_kind_str[BTF_INFO_KIND(BTFType.info)] +void BTFTypeEntry::print(raw_ostream &OS, MCBTFContext &MCBTFContext) { + OS << "[" << Id << "] " << btf_kind_str[BTF_INFO_KIND(BTFType.info)] << " name_off=" << BTFType.name_off << " info=" << format("0x%08lx", BTFType.info) << " size/type=" << BTFType.size << "\n"; @@ -160,7 +155,7 @@ void BTFTypeEntry::emitData(MCObjectStreamer *MCOS) { MCOS->EmitIntValue(BTFType.size, 4); } -void BTFTypeEntryInt::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { +void BTFTypeEntryInt::print(raw_ostream &OS, MCBTFContext &MCBTFContext) { BTFTypeEntry::print(OS, MCBTFContext); OS << "\tdesc=" << format("0x%08lx", IntVal) << "\n"; } @@ -170,12 +165,12 @@ void BTFTypeEntryInt::emitData(MCObjectStreamer *MCOS) { MCOS->EmitIntValue(IntVal, 4); } -void BTFTypeEntryEnum::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { - BTFTypeEntry::print(OS, MCBTFContext); +void BTFTypeEntryEnum::print(raw_ostream &OS, MCBTFContext &MCBTFContext) { + BTFTypeEntry::print(OS, MCBTFContext); for (size_t i = 0; i < BTF_INFO_VLEN(BTFType.info); i++) { auto &EnumValue = EnumValues[i]; - OS << "\tname_off=" << EnumValue.name_off - << " value=" << EnumValue.val << "\n"; + OS << "\tname_off=" << EnumValue.name_off << " value=" << EnumValue.val + << "\n"; } } @@ -187,7 +182,7 @@ void BTFTypeEntryEnum::emitData(MCObjectStreamer *MCOS) { } } -void BTFTypeEntryArray::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { +void BTFTypeEntryArray::print(raw_ostream &OS, MCBTFContext &MCBTFContext) { BTFTypeEntry::print(OS, MCBTFContext); OS << "\telem_type=" << format("0x%08lx", ArrayInfo.type) << " index_type=" << format("0x%08lx", ArrayInfo.index_type) @@ -201,12 +196,11 @@ void BTFTypeEntryArray::emitData(MCObjectStreamer *MCOS) { MCOS->EmitIntValue(ArrayInfo.nelems, 4); } -void BTFTypeEntryStruct::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { +void BTFTypeEntryStruct::print(raw_ostream &OS, MCBTFContext &MCBTFContext) { BTFTypeEntry::print(OS, MCBTFContext); - for (size_t i = 0; i < BTF_INFO_VLEN(BTFType.info); i++) { + for (size_t i = 0; i < BTF_INFO_VLEN(BTFType.info); i++) { auto &Member = Members[i]; - OS << "\tname_off=" << Member.name_off - << " type=" << Member.type + OS << "\tname_off=" << Member.name_off << " type=" << Member.type << " bit_offset=" << Member.offset << "\n"; } } @@ -220,9 +214,9 @@ void BTFTypeEntryStruct::emitData(MCObjectStreamer *MCOS) { } } -void BTFTypeEntryFunc::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { +void BTFTypeEntryFunc::print(raw_ostream &OS, MCBTFContext &MCBTFContext) { BTFTypeEntry::print(OS, MCBTFContext); - for (size_t i = 0; i < BTF_INFO_VLEN(BTFType.info); i++) { + for (size_t i = 0; i < BTF_INFO_VLEN(BTFType.info); i++) { auto Parameter = Parameters[i]; OS << "\tparam_type=" << Parameter << "\n"; } @@ -230,6 +224,6 @@ void BTFTypeEntryFunc::print(raw_ostream &OS, MCBTFContext& MCBTFContext) { void BTFTypeEntryFunc::emitData(MCObjectStreamer *MCOS) { BTFTypeEntry::emitData(MCOS); - for (auto &Parameter: Parameters) + for (auto &Parameter : Parameters) MCOS->EmitIntValue(Parameter, 4); } diff --git a/llvm/lib/MC/MCDwarf2BTF.cpp b/llvm/lib/MC/MCDwarf2BTF.cpp index 08a70e6f318..9809a2153ec 100644 --- a/llvm/lib/MC/MCDwarf2BTF.cpp +++ b/llvm/lib/MC/MCDwarf2BTF.cpp @@ -10,11 +10,11 @@ #include "MCDwarf2BTF.h" #include "llvm/ADT/SmallVector.h" #include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCBTFContext.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCObjectStreamer.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSectionELF.h" -#include "llvm/MC/MCBTFContext.h" #include "llvm/Support/Endian.h" #include "llvm/Support/EndianStream.h" #include <fstream> @@ -22,7 +22,7 @@ using namespace llvm; void MCDwarf2BTF::addFiles(MCObjectStreamer *MCOS, std::string &FileName, - std::vector<FileContent> &Files) { + std::vector<FileContent> &Files) { std::vector<std::string> Content; std::ifstream Inputfile(FileName); @@ -34,9 +34,10 @@ void MCDwarf2BTF::addFiles(MCObjectStreamer *MCOS, std::string &FileName, Files.push_back(FileContent(FileName, Content)); } -void MCDwarf2BTF::addLines(MCObjectStreamer *MCOS, StringRef &SectionName, - std::vector<FileContent> &Files, - const MCLineSection::MCDwarfLineEntryCollection &LineEntries) { +void MCDwarf2BTF::addLines( + MCObjectStreamer *MCOS, StringRef &SectionName, + std::vector<FileContent> &Files, + const MCLineSection::MCDwarfLineEntryCollection &LineEntries) { MCContext &Context = MCOS->getContext(); auto &BTFCxt = Context.getBTFContext(); @@ -84,9 +85,11 @@ void MCDwarf2BTF::addDwarfLineInfo(MCObjectStreamer *MCOS) { FileName = Dirs[File.DirIndex - 1] + "/" + File.Name; MCDwarf2BTF::addFiles(MCOS, FileName, Files); } - for (const auto &LineSec: CUIDTablePair.second.getMCLineSections().getMCLineEntries()) { + for (const auto &LineSec : + CUIDTablePair.second.getMCLineSections().getMCLineEntries()) { MCSection *Section = LineSec.first; - const MCLineSection::MCDwarfLineEntryCollection &LineEntries = LineSec.second; + const MCLineSection::MCDwarfLineEntryCollection &LineEntries = + LineSec.second; StringRef SectionName; if (MCSectionELF *SectionELF = dyn_cast<MCSectionELF>(Section)) diff --git a/llvm/lib/MC/MCDwarf2BTF.h b/llvm/lib/MC/MCDwarf2BTF.h index 22d1b7741a5..69983374a09 100644 --- a/llvm/lib/MC/MCDwarf2BTF.h +++ b/llvm/lib/MC/MCDwarf2BTF.h @@ -18,12 +18,13 @@ using FileContent = std::pair<std::string, std::vector<std::string>>; class MCDwarf2BTF { public: static void addFiles(MCObjectStreamer *MCOS, std::string &FileName, - std::vector<FileContent> &Files); - static void addLines(MCObjectStreamer *MCOS, StringRef &SectionName, - std::vector<FileContent> &Files, - const MCLineSection::MCDwarfLineEntryCollection &LineEntries); + std::vector<FileContent> &Files); + static void + addLines(MCObjectStreamer *MCOS, StringRef &SectionName, + std::vector<FileContent> &Files, + const MCLineSection::MCDwarfLineEntryCollection &LineEntries); static void addDwarfLineInfo(MCObjectStreamer *MCOS); }; -} +} // namespace llvm #endif |