llvm.org GIT mirror llvm / 14c3bba
Add llvm::object::getELFSectionTypeName(). This is motivated by https://reviews.llvm.org/D32488 where I am trying to add printing of the section type for incompatible sections to LLD error messages. This patch allows us to use the same code in llvm-readobj and LLD instead of duplicating the function inside LLD. Patch by Alexander Richardson! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301921 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
4 changed file(s) with 69 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
3131 namespace object {
3232
3333 StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type);
34 StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type);
3435
3536 // Subclasses of ELFFile may need this for template instantiation
3637 inline std::pair
1212 using namespace llvm;
1313 using namespace object;
1414
15 #define ELF_RELOC(name, value) \
16 case ELF::name: \
17 return #name; \
15 #define STRINGIFY_ENUM_CASE(ns, name) \
16 case ns::name: \
17 return #name;
18
19 #define ELF_RELOC(name, value) STRINGIFY_ENUM_CASE(ELF, name)
1820
1921 StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
2022 uint32_t Type) {
140142 }
141143
142144 #undef ELF_RELOC
145
146 StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
147 switch (Machine) {
148 case ELF::EM_ARM:
149 switch (Type) {
150 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_EXIDX);
151 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_PREEMPTMAP);
152 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_ATTRIBUTES);
153 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_DEBUGOVERLAY);
154 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_OVERLAYSECTION);
155 }
156 break;
157 case ELF::EM_HEXAGON:
158 switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
159 break;
160 case ELF::EM_X86_64:
161 switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_X86_64_UNWIND); }
162 break;
163 case ELF::EM_MIPS:
164 case ELF::EM_MIPS_RS3_LE:
165 switch (Type) {
166 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_REGINFO);
167 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_OPTIONS);
168 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_ABIFLAGS);
169 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_DWARF);
170 }
171 break;
172 default:
173 break;
174 }
175
176 switch (Type) {
177 STRINGIFY_ENUM_CASE(ELF, SHT_NULL);
178 STRINGIFY_ENUM_CASE(ELF, SHT_PROGBITS);
179 STRINGIFY_ENUM_CASE(ELF, SHT_SYMTAB);
180 STRINGIFY_ENUM_CASE(ELF, SHT_STRTAB);
181 STRINGIFY_ENUM_CASE(ELF, SHT_RELA);
182 STRINGIFY_ENUM_CASE(ELF, SHT_HASH);
183 STRINGIFY_ENUM_CASE(ELF, SHT_DYNAMIC);
184 STRINGIFY_ENUM_CASE(ELF, SHT_NOTE);
185 STRINGIFY_ENUM_CASE(ELF, SHT_NOBITS);
186 STRINGIFY_ENUM_CASE(ELF, SHT_REL);
187 STRINGIFY_ENUM_CASE(ELF, SHT_SHLIB);
188 STRINGIFY_ENUM_CASE(ELF, SHT_DYNSYM);
189 STRINGIFY_ENUM_CASE(ELF, SHT_INIT_ARRAY);
190 STRINGIFY_ENUM_CASE(ELF, SHT_FINI_ARRAY);
191 STRINGIFY_ENUM_CASE(ELF, SHT_PREINIT_ARRAY);
192 STRINGIFY_ENUM_CASE(ELF, SHT_GROUP);
193 STRINGIFY_ENUM_CASE(ELF, SHT_SYMTAB_SHNDX);
194 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES);
195 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);
196 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef);
197 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verneed);
198 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_versym);
199 default:
200 return "Unknown";
201 }
202 }
77
88 // OBJ: Section {
99 // OBJ: Name: .sec
10 // OBJ-NEXT: Type: (0x7FFFFFFF)
10 // OBJ-NEXT: Type: Unknown (0x7FFFFFFF)
1111 // OBJ: }
1212
1313 // ASM: unsupported type 0x7fffffff for section .sec
982982 { "AMDGPU_HSA_METADATA", ELF::STT_AMDGPU_HSA_METADATA }
983983 };
984984
985 static const char *getElfSectionType(unsigned Arch, unsigned Type) {
986 switch (Arch) {
987 case ELF::EM_ARM:
988 switch (Type) {
989 LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_EXIDX);
990 LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_PREEMPTMAP);
991 LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_ATTRIBUTES);
992 LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_DEBUGOVERLAY);
993 LLVM_READOBJ_ENUM_CASE(ELF, SHT_ARM_OVERLAYSECTION);
994 }
995 case ELF::EM_HEXAGON:
996 switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
997 case ELF::EM_X86_64:
998 switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, SHT_X86_64_UNWIND); }
999 case ELF::EM_MIPS:
1000 case ELF::EM_MIPS_RS3_LE:
1001 switch (Type) {
1002 LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_REGINFO);
1003 LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_OPTIONS);
1004 LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_ABIFLAGS);
1005 LLVM_READOBJ_ENUM_CASE(ELF, SHT_MIPS_DWARF);
1006 }
1007 }
1008
1009 switch (Type) {
1010 LLVM_READOBJ_ENUM_CASE(ELF, SHT_NULL );
1011 LLVM_READOBJ_ENUM_CASE(ELF, SHT_PROGBITS );
1012 LLVM_READOBJ_ENUM_CASE(ELF, SHT_SYMTAB );
1013 LLVM_READOBJ_ENUM_CASE(ELF, SHT_STRTAB );
1014 LLVM_READOBJ_ENUM_CASE(ELF, SHT_RELA );
1015 LLVM_READOBJ_ENUM_CASE(ELF, SHT_HASH );
1016 LLVM_READOBJ_ENUM_CASE(ELF, SHT_DYNAMIC );
1017 LLVM_READOBJ_ENUM_CASE(ELF, SHT_NOTE );
1018 LLVM_READOBJ_ENUM_CASE(ELF, SHT_NOBITS );
1019 LLVM_READOBJ_ENUM_CASE(ELF, SHT_REL );
1020 LLVM_READOBJ_ENUM_CASE(ELF, SHT_SHLIB );
1021 LLVM_READOBJ_ENUM_CASE(ELF, SHT_DYNSYM );
1022 LLVM_READOBJ_ENUM_CASE(ELF, SHT_INIT_ARRAY );
1023 LLVM_READOBJ_ENUM_CASE(ELF, SHT_FINI_ARRAY );
1024 LLVM_READOBJ_ENUM_CASE(ELF, SHT_PREINIT_ARRAY );
1025 LLVM_READOBJ_ENUM_CASE(ELF, SHT_GROUP );
1026 LLVM_READOBJ_ENUM_CASE(ELF, SHT_SYMTAB_SHNDX );
1027 LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES );
1028 LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_HASH );
1029 LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_verdef );
1030 LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_verneed );
1031 LLVM_READOBJ_ENUM_CASE(ELF, SHT_GNU_versym );
1032 default: return "";
1033 }
1034 }
1035
1036985 static const char *getGroupType(uint32_t Flag) {
1037986 if (Flag & ELF::GRP_COMDAT)
1038987 return "COMDAT";
36343583 DictScope SectionD(W, "Section");
36353584 W.printNumber("Index", SectionIndex);
36363585 W.printNumber("Name", Name, Sec.sh_name);
3637 W.printHex("Type",
3638 getElfSectionType(Obj->getHeader()->e_machine, Sec.sh_type),
3639 Sec.sh_type);
3586 W.printHex(
3587 "Type",
3588 object::getELFSectionTypeName(Obj->getHeader()->e_machine, Sec.sh_type),
3589 Sec.sh_type);
36403590 std::vector> SectionFlags(std::begin(ElfSectionFlags),
36413591 std::end(ElfSectionFlags));
36423592 switch (Obj->getHeader()->e_machine) {