llvm.org GIT mirror llvm / 5f896ac
[yaml2obj] - Allow setting custom sh_info for RawContentSection sections. This is for tweaking SHT_SYMTAB sections. Their sh_info contains the (number of symbols + 1) usually. But for creating invalid inputs for test cases it would be convenient to allow explicitly override this field from YAML. Differential revision: https://reviews.llvm.org/D58779 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355193 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 7 months ago
7 changed file(s) with 98 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
152152 struct RawContentSection : Section {
153153 yaml::BinaryRef Content;
154154 llvm::yaml::Hex64 Size;
155 llvm::yaml::Hex64 Info;
155156
156157 RawContentSection() : Section(SectionKind::RawContent) {}
157158
886886 commonSectionMapping(IO, Section);
887887 IO.mapOptional("Content", Section.Content);
888888 IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
889 IO.mapOptional("Info", Section.Info, Hex64(0));
889890 }
890891
891892 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
0 # RUN: yaml2obj %s -o %t
1 # RUN: obj2yaml %t | FileCheck %s
2
3 ## Check obj2yaml is able to dump sh_info field of a section.
4
5 # CHECK: - Name: .test
6 # CHECK-NEXT: Type: SHT_PROGBITS
7 # CHECK-NEXT: Content: ''
8 # CHECK-NEXT: Info: 0x000000000000002A
9
10 --- !ELF
11 FileHeader:
12 Class: ELFCLASS64
13 Data: ELFDATA2LSB
14 Type: ET_REL
15 Machine: EM_X86_64
16 Sections:
17 - Name: .test
18 Type: SHT_PROGBITS
19 Info: 42
0 ## Check we are able to set sh_info field for SHT_SYMTAB sections.
1 # RUN: yaml2obj %s -o %t
2 # RUN: llvm-readobj -sections %t | FileCheck %s
3
4 # CHECK: Name: .symtab
5 # CHECK-NEXT: Type: SHT_SYMTAB
6 # CHECK-NEXT: Flags [
7 # CHECK-NEXT: ]
8 # CHECK-NEXT: Address:
9 # CHECK-NEXT: Offset:
10 # CHECK-NEXT: Size:
11 # CHECK-NEXT: Link:
12 # CHECK-NEXT: Info: 42
13 # CHECK: Name: .dynsym
14 # CHECK-NEXT: Type: SHT_DYNSYM
15 # CHECK-NEXT: Flags [
16 # CHECK-NEXT: SHF_ALLOC
17 # CHECK-NEXT: ]
18 # CHECK-NEXT: Address:
19 # CHECK-NEXT: Offset:
20 # CHECK-NEXT: Size:
21 # CHECK-NEXT: Link:
22 # CHECK-NEXT: Info: 26
23
24 --- !ELF
25 FileHeader:
26 Class: ELFCLASS64
27 Data: ELFDATA2LSB
28 Type: ET_REL
29 Machine: EM_X86_64
30 Sections:
31 - Name: .symtab
32 Info: 42
33 Type: SHT_SYMTAB
34 - Name: .dynsym
35 Info: 26
36 Type: SHT_SYMTAB
37 Symbols:
38 Global:
39 - Name: foo
40 DynamicSymbols:
41 Global:
42 - Name: bar
0 ## Check we dont crash when .symtab has type different from SHT_SYMTAB.
1 # RUN: yaml2obj %s -o %t
2 # RUN: llvm-readobj -sections %t | FileCheck %s
3
4 ## TODO: the output is still SHT_SYMTAB because we do not yet
5 ## support changing it.
6 # CHECK: Name: .symtab
7 # CHECK-NEXT: Type: SHT_SYMTAB
8
9 --- !ELF
10 FileHeader:
11 Class: ELFCLASS64
12 Data: ELFDATA2LSB
13 Type: ET_REL
14 Machine: EM_X86_64
15 Sections:
16 - Name: .symtab
17 Type: SHT_DYNAMIC
18 Symbols:
19 Global:
20 - Name: foo
457457 return errorToErrorCode(ContentOrErr.takeError());
458458 S->Content = yaml::BinaryRef(ContentOrErr.get());
459459 S->Size = S->Content.binary_size();
460 S->Info = Shdr->sh_info;
460461
461462 return S.release();
462463 }
340340 SHeader.sh_entsize = sizeof(Elf_Sym);
341341 SHeader.sh_addralign = 8;
342342
343 // If .dynsym section is explicitly described in the YAML
344 // then we want to use its section address.
345 if (!IsStatic) {
346 // Take section index and ignore the SHT_NULL section.
347 unsigned SecNdx = getDotDynSymSecNo() - 1;
348 if (SecNdx < Doc.Sections.size())
349 SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
343 // Get the section index ignoring the SHT_NULL section.
344 unsigned SecNdx =
345 IsStatic ? getDotSymTabSecNo() - 1 : getDotDynSymSecNo() - 1;
346 // If the symbol table section is explicitly described in the YAML
347 // then we should set the fields requested.
348 if (SecNdx < Doc.Sections.size()) {
349 ELFYAML::Section *Sec = Doc.Sections[SecNdx].get();
350 SHeader.sh_addr = Sec->Address;
351 if (auto S = dyn_cast(Sec))
352 SHeader.sh_info = S->Info;
350353 }
351354
352355 std::vector Syms;
502505 else
503506 SHeader.sh_entsize = 0;
504507 SHeader.sh_size = Section.Size;
508 SHeader.sh_info = Section.Info;
505509 }
506510
507511 static bool isMips64EL(const ELFYAML::Object &Doc) {