llvm.org GIT mirror llvm / 301f3b0
[yaml2obj/obj2yaml] - Make RawContentSection::Info Optional<> This allows to customize this field for "implicit" sections properly. Differential revision: https://reviews.llvm.org/D63487 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363777 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 26 days ago
8 changed file(s) with 159 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
152152 struct RawContentSection : Section {
153153 Optional Content;
154154 Optional Size;
155 llvm::yaml::Hex64 Info;
155 Optional Info;
156156
157157 RawContentSection() : Section(SectionKind::RawContent) {}
158158
916916 commonSectionMapping(IO, Section);
917917 IO.mapOptional("Content", Section.Content);
918918 IO.mapOptional("Size", Section.Size);
919 IO.mapOptional("Info", Section.Info, Hex64(0));
919 IO.mapOptional("Info", Section.Info);
920920 }
921921
922922 static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
0 ## Check that obj2yaml does not write a section Info
1 ## field in the case when it has a value of zero.
2
3 # RUN: yaml2obj %s -o %t
4 # RUN: obj2yaml %t | FileCheck %s
5
6 # CHECK: Sections:
7 # CHECK-NEXT: - Name: .foo
8 # CHECK-NEXT: Type: SHT_PROGBITS
9 # CHECK-NEXT: - Name: .bar
10 # CHECK-NEXT: Type: SHT_PROGBITS
11 # CHECK-NEXT: Info: 0x0000000000000001
12
13 --- !ELF
14 FileHeader:
15 Class: ELFCLASS64
16 Data: ELFDATA2LSB
17 Type: ET_DYN
18 Machine: EM_X86_64
19 Sections:
20 - Name: .foo
21 Type: SHT_PROGBITS
22 - Name: .bar
23 Type: SHT_PROGBITS
24 Info: 1
7777 # CASE4-NEXT: Offset: 0x180
7878 # CASE4-NEXT: Size: 2
7979 # CASE4-NEXT: Link: 0
80 # CASE4-NEXT: Info: 0
80 # CASE4-NEXT: Info: 1
8181 # CASE4-NEXT: AddressAlignment: 0
8282 # CASE4-NEXT: EntrySize: 24
8383 # CASE4-NEXT: SectionData (
109109 # CASE5-NEXT: Offset: 0x180
110110 # CASE5-NEXT: Size: 5
111111 # CASE5-NEXT: Link: 0
112 # CASE5-NEXT: Info: 0
112 # CASE5-NEXT: Info: 1
113113 # CASE5-NEXT: AddressAlignment: 0
114114 # CASE5-NEXT: EntrySize: 24
115115 # CASE5-NEXT: SectionData (
143143 # CASE6-NEXT: Offset: 0x180
144144 # CASE6-NEXT: Size: 4
145145 # CASE6-NEXT: Link: 0
146 # CASE6-NEXT: Info: 0
146 # CASE6-NEXT: Info: 1
147147 # CASE6-NEXT: AddressAlignment: 0
148148 # CASE6-NEXT: EntrySize: 24
149149 # CASE6-NEXT: SectionData (
177177 # CASE7-NEXT: Offset: 0x180
178178 # CASE7-NEXT: Size: 2
179179 # CASE7-NEXT: Link: 0
180 # CASE7-NEXT: Info: 0
180 # CASE7-NEXT: Info: 1
181181 # CASE7-NEXT: AddressAlignment: 0
182182 # CASE7-NEXT: EntrySize: 24
183183 # CASE7-NEXT: SectionData (
0 ## Check the values of sh_info fields set by default for
1 ## explicitly listed .dynstr, .dynsym, .strtab and .symtab
2 ## sections.
3 ##
4 ## For symbol table sections, sh_info has a value which is
5 ## one greater than the symbol table index of the last
6 ## local symbol.
7 ##
8 ## sh_info isn't set for string table sections.
9
10 # RUN: yaml2obj --docnum=1 %s -o %t
11 # RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE1
12
13 # CASE1: Name: .symtab
14 # CASE1: Info:
15 # CASE1-SAME: 2
16 # CASE1: Name: .strtab
17 # CASE1: Info:
18 # CASE1-SAME: 0
19 # CASE1: Name: .dynsym
20 # CASE1: Info:
21 # CASE1-SAME: 1
22 # CASE1: Name: .dynstr
23 # CASE1: Info:
24 # CASE1-SAME: 0
25
26 --- !ELF
27 FileHeader:
28 Class: ELFCLASS64
29 Data: ELFDATA2LSB
30 Type: ET_DYN
31 Machine: EM_X86_64
32 Sections:
33 - Name: .symtab
34 Type: SHT_SYMTAB
35 - Name: .strtab
36 Type: SHT_STRTAB
37 - Name: .dynsym
38 Type: SHT_DYNSYM
39 - Name: .dynstr
40 Type: SHT_STRTAB
41 Symbols:
42 - Name: local
43 - Name: global1
44 Binding: STB_GLOBAL
45 DynamicSymbols:
46 - Name: global2
47 Binding: STB_GLOBAL
48
49 ## In the case when these sections are not defined in YAML, the
50 ## behavior is the same as when we define them, but do not set the Info.
51
52 # RUN: yaml2obj --docnum=2 %s -o %t
53 # RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE1
54
55 --- !ELF
56 FileHeader:
57 Class: ELFCLASS64
58 Data: ELFDATA2LSB
59 Type: ET_DYN
60 Machine: EM_X86_64
61 Symbols:
62 - Name: local
63 - Name: global1
64 Binding: STB_GLOBAL
65 DynamicSymbols:
66 - Name: global2
67 Binding: STB_GLOBAL
68
69 ## Check we are able to set any sh_info explicitly.
70
71 # RUN: yaml2obj --docnum=3 %s -o %t
72 # RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE2
73
74 # CASE2: Name: .dynstr
75 # CASE2: Info:
76 # CASE2-SAME: 10
77 # CASE2: Name: .dynsym
78 # CASE2: Info:
79 # CASE2-SAME: 11
80 # CASE2: Name: .strtab
81 # CASE2: Info:
82 # CASE2-SAME: 12
83 # CASE2: Name: .symtab
84 # CASE2: Info:
85 # CASE2-SAME: 13
86
87 --- !ELF
88 FileHeader:
89 Class: ELFCLASS64
90 Data: ELFDATA2LSB
91 Type: ET_DYN
92 Machine: EM_X86_64
93 Sections:
94 - Name: .dynstr
95 Type: SHT_STRTAB
96 Info: 10
97 - Name: .dynsym
98 Type: SHT_DYNSYM
99 Info: 11
100 - Name: .strtab
101 Type: SHT_STRTAB
102 Info: 12
103 - Name: .symtab
104 Type: SHT_SYMTAB
105 Info: 13
106 Symbols:
107 - Name: local
108 - Name: global1
109 Binding: STB_GLOBAL
110 DynamicSymbols:
111 - Name: global2
112 Binding: STB_GLOBAL
7272 # CASE4-NEXT: Offset: 0x140
7373 # CASE4-NEXT: Size: 2
7474 # CASE4-NEXT: Link: 2
75 # CASE4-NEXT: Info: 0
75 # CASE4-NEXT: Info: 1
7676 # CASE4-NEXT: AddressAlignment: 0
7777 # CASE4-NEXT: EntrySize: 24
7878 # CASE4-NEXT: SectionData (
103103 # CASE5-NEXT: Offset: 0x140
104104 # CASE5-NEXT: Size: 5
105105 # CASE5-NEXT: Link: 2
106 # CASE5-NEXT: Info: 0
106 # CASE5-NEXT: Info: 1
107107 # CASE5-NEXT: AddressAlignment: 0
108108 # CASE5-NEXT: EntrySize: 24
109109 # CASE5-NEXT: SectionData (
136136 # CASE6-NEXT: Offset: 0x140
137137 # CASE6-NEXT: Size: 4
138138 # CASE6-NEXT: Link: 2
139 # CASE6-NEXT: Info: 0
139 # CASE6-NEXT: Info: 1
140140 # CASE6-NEXT: AddressAlignment: 0
141141 # CASE6-NEXT: EntrySize: 24
142142 # CASE6-NEXT: SectionData (
169169 # CASE7-NEXT: Offset: 0x140
170170 # CASE7-NEXT: Size: 2
171171 # CASE7-NEXT: Link: 2
172 # CASE7-NEXT: Info: 0
172 # CASE7-NEXT: Info: 1
173173 # CASE7-NEXT: AddressAlignment: 0
174174 # CASE7-NEXT: EntrySize: 24
175175 # CASE7-NEXT: SectionData (
441441 ArrayRef Content = *ContentOrErr;
442442 if (!Content.empty())
443443 S->Content = yaml::BinaryRef(Content);
444 S->Info = Shdr->sh_info;
444 if (Shdr->sh_info)
445 S->Info = static_cast(Shdr->sh_info);
445446 return S.release();
446447 }
447448
435435
436436 // If the symbol table section is explicitly described in the YAML
437437 // then we should set the fields requested.
438 SHeader.sh_info =
439 RawSec ? (unsigned)RawSec->Info : findFirstNonGlobal(Symbols) + 1;
438 SHeader.sh_info = (RawSec && RawSec->Info) ? (unsigned)(*RawSec->Info)
439 : findFirstNonGlobal(Symbols) + 1;
440440 SHeader.sh_entsize = (YAMLSec && YAMLSec->EntSize)
441441 ? (uint64_t)(*YAMLSec->EntSize)
442442 : sizeof(Elf_Sym);
486486
487487 if (YAMLSec && YAMLSec->EntSize)
488488 SHeader.sh_entsize = *YAMLSec->EntSize;
489
490 if (RawSec && RawSec->Info)
491 SHeader.sh_info = *RawSec->Info;
489492
490493 if (YAMLSec && YAMLSec->Flags)
491494 SHeader.sh_flags = *YAMLSec->Flags;
623626 SHeader.sh_entsize = sizeof(Elf_Relr);
624627 else
625628 SHeader.sh_entsize = 0;
626 SHeader.sh_info = Section.Info;
629
630 if (Section.Info)
631 SHeader.sh_info = *Section.Info;
632
627633 return true;
628634 }
629635