llvm.org GIT mirror llvm / 746c778
[yaml2obj][ELF] Add support for symbol indexes greater than SHN_LORESERVE Right now Symbols must be either undefined or defined in a specific section. Some symbols have section indexes like SHN_ABS however. This change adds support for outputting symbols that have such section indexes. Patch by Jake Ehrlich Differential Revision: https://reviews.llvm.org/D37391 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312745 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 2 years ago
5 changed file(s) with 104 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4949 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)
5050 // Just use 64, since it can hold 32-bit values too.
5151 LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
52 LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN)
5253 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
5354 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)
5455 LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)
8889 StringRef Name;
8990 ELF_STT Type;
9091 StringRef Section;
92 Optional Index;
9193 llvm::yaml::Hex64 Value;
9294 llvm::yaml::Hex64 Size;
9395 uint8_t Other;
266268 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
267269 };
268270
271 template <> struct ScalarEnumerationTraits {
272 static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value);
273 };
274
269275 template <>
270276 struct ScalarEnumerationTraits {
271277 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
333339 template <>
334340 struct MappingTraits {
335341 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
342 static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
336343 };
337344
338345 template <>
476476 #undef BCase
477477 }
478478
479 void ScalarEnumerationTraits::enumeration(
480 IO &IO, ELFYAML::ELF_SHN &Value) {
481 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
482 ECase(SHN_UNDEF);
483 ECase(SHN_LORESERVE);
484 ECase(SHN_LOPROC);
485 ECase(SHN_HIPROC);
486 ECase(SHN_LOOS);
487 ECase(SHN_HIOS);
488 ECase(SHN_ABS);
489 ECase(SHN_COMMON);
490 ECase(SHN_XINDEX);
491 ECase(SHN_HIRESERVE);
492 ECase(SHN_HEXAGON_SCOMMON);
493 ECase(SHN_HEXAGON_SCOMMON_1);
494 ECase(SHN_HEXAGON_SCOMMON_2);
495 ECase(SHN_HEXAGON_SCOMMON_4);
496 ECase(SHN_HEXAGON_SCOMMON_8);
497 #undef ECase
498 IO.enumFallback(Value);
499 }
500
479501 void ScalarEnumerationTraits::enumeration(
480502 IO &IO, ELFYAML::ELF_STT &Value) {
481503 #define ECase(X) IO.enumCase(Value, #X, ELF::X)
700722 IO.mapOptional("Name", Symbol.Name, StringRef());
701723 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
702724 IO.mapOptional("Section", Symbol.Section, StringRef());
725 IO.mapOptional("Index", Symbol.Index);
703726 IO.mapOptional("Value", Symbol.Value, Hex64(0));
704727 IO.mapOptional("Size", Symbol.Size, Hex64(0));
705728
706729 MappingNormalization Keys(IO, Symbol.Other);
707730 IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
708731 IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
732 }
733
734 StringRef MappingTraits::validate(IO &IO,
735 ELFYAML::Symbol &Symbol) {
736 if (Symbol.Index && Symbol.Section.data()) {
737 return "Index and Section cannot both be specified for Symbol";
738 }
739 if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
740 return "Large indexes are not supported";
741 }
742 if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
743 return "Use a section name to define which section a symbol is defined in";
744 }
745 return StringRef();
709746 }
710747
711748 void MappingTraits::mapping(
0 # This test insures that the user cannot have both an Index and a Section field.
1 # RUN: not yaml2obj %s
2
3 !ELF
4 FileHeader:
5 Class: ELFCLASS64
6 Data: ELFDATA2LSB
7 Type: ET_EXEC
8 Machine: EM_X86_64
9 Sections:
10 - Name: .text
11 Type: SHT_PROGBITS
12 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
13 Address: 0x1000
14 AddressAlign: 0x0000000000000010
15 Content: "0000000000000000"
16 Symbols:
17 Global:
18 - Name: _start
19 Section: .text
20 Index: SHN_ABS
0 # RUN: yaml2obj %s > %t
1 # RUN: llvm-readobj -symbols %t | FileCheck %s
2
3 !ELF
4 FileHeader:
5 Class: ELFCLASS64
6 Data: ELFDATA2LSB
7 Type: ET_EXEC
8 Machine: EM_X86_64
9 Symbols:
10 Global:
11 - Name: test
12 Index: SHN_ABS
13 Value: 0x1234
14
15 #CHECK: Symbols [
16 #CHECK-NEXT: Symbol {
17 #CHECK-NEXT: Name: (0)
18 #CHECK-NEXT: Value: 0x0
19 #CHECK-NEXT: Size: 0
20 #CHECK-NEXT: Binding: Local (0x0)
21 #CHECK-NEXT: Type: None (0x0)
22 #CHECK-NEXT: Other: 0
23 #CHECK-NEXT: Section: Undefined (0x0)
24 #CHECK-NEXT: }
25 #CHECK-NEXT: Symbol {
26 #CHECK-NEXT: Name: test (1)
27 #CHECK-NEXT: Value: 0x1234
28 #CHECK-NEXT: Size: 0
29 #CHECK-NEXT: Binding: Global (0x1)
30 #CHECK-NEXT: Type: None (0x0)
31 #CHECK-NEXT: Other: 0
32 #CHECK-NEXT: Section: Absolute (0xFFF1)
33 #CHECK-NEXT: }
34 #CHECK-NEXT:]
408408 exit(1);
409409 }
410410 Symbol.st_shndx = Index;
411 } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
411 } else if (Sym.Index) {
412 Symbol.st_shndx = *Sym.Index;
413 }
414 // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
412415 Symbol.st_value = Sym.Value;
413416 Symbol.st_other = Sym.Other;
414417 Symbol.st_size = Sym.Size;