llvm.org GIT mirror llvm / f24bfab
[yaml2obj] - Allow setting cutom Flags for implicit sections. With this patch we get ability to set any flags we want for implicit sections defined in YAML. Differential revision: https://reviews.llvm.org/D63136 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363367 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar a month ago
6 changed file(s) with 176 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
128128 SectionKind Kind;
129129 StringRef Name;
130130 ELF_SHT Type;
131 ELF_SHF Flags;
131 Optional Flags;
132132 llvm::yaml::Hex64 Address;
133133 StringRef Link;
134134 llvm::yaml::Hex64 AddressAlign;
899899 static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
900900 IO.mapOptional("Name", Section.Name, StringRef());
901901 IO.mapRequired("Type", Section.Type);
902 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
902 IO.mapOptional("Flags", Section.Flags);
903903 IO.mapOptional("Address", Section.Address, Hex64(0));
904904 IO.mapOptional("Link", Section.Link, StringRef());
905905 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
0 ## For implicit string table sections, the `Flags` field can also
1 ## be specified in YAML. Here we test the behavior in different cases.
2
3 ## When flags are not explicitly specified, yaml2obj assigns no flags
4 ## for .strtab and the SHF_ALLOC flag for .dynstr by default.
5
6 # RUN: yaml2obj --docnum=1 %s -o %t1
7 # RUN: llvm-readobj %t1 -S | FileCheck %s --check-prefix=CASE1
8
9 # CASE1: Name: .strtab
10 # CASE1-NEXT: Type: SHT_STRTAB
11 # CASE1-NEXT: Flags [
12 # CASE1-NEXT: ]
13 # CASE1: Name: .dynstr
14 # CASE1-NEXT: Type: SHT_STRTAB
15 # CASE1-NEXT: Flags [
16 # CASE1-NEXT: SHF_ALLOC
17 # CASE1-NEXT: ]
18
19 --- !ELF
20 FileHeader:
21 Class: ELFCLASS64
22 Data: ELFDATA2LSB
23 Type: ET_DYN
24 Machine: EM_X86_64
25 Sections:
26 - Name: .strtab
27 Type: SHT_STRTAB
28 - Name: .dynstr
29 Type: SHT_STRTAB
30
31 ## Check we can set arbitrary flags for .strtab/.dynstr.
32
33 # RUN: yaml2obj --docnum=2 %s -o %t2
34 # RUN: llvm-readobj %t2 -S | FileCheck %s --check-prefix=CASE2
35
36 # CASE2: Name: .strtab
37 # CASE2-NEXT: Type: SHT_STRTAB
38 # CASE2-NEXT: Flags [
39 # CASE2-NEXT: SHF_ALLOC
40 # CASE2-NEXT: SHF_STRINGS
41 # CASE2-NEXT: ]
42 # CASE2: Name: .dynstr
43 # CASE2-NEXT: Type: SHT_STRTAB
44 # CASE2-NEXT: Flags [
45 # CASE2-NEXT: SHF_STRINGS
46 # CASE2-NEXT: ]
47
48 --- !ELF
49 FileHeader:
50 Class: ELFCLASS64
51 Data: ELFDATA2LSB
52 Type: ET_DYN
53 Machine: EM_X86_64
54 Sections:
55 - Name: .strtab
56 Type: SHT_STRTAB
57 Flags: [ SHF_ALLOC, SHF_STRINGS ]
58 - Name: .dynstr
59 Type: SHT_STRTAB
60 Flags: [ SHF_STRINGS ]
61
62 ## Check no flags are set by default for .strtab when it is not
63 ## described in the YAML.
64
65 # RUN: yaml2obj --docnum=3 %s -o %t3
66 # RUN: llvm-readobj %t3 -S | FileCheck %s --check-prefix=CASE3
67
68 # CASE3: Name: .strtab
69 # CASE3-NEXT: Type: SHT_STRTAB
70 # CASE3-NEXT: Flags [
71 # CASE3-NEXT: ]
72
73 --- !ELF
74 FileHeader:
75 Class: ELFCLASS64
76 Data: ELFDATA2LSB
77 Type: ET_DYN
78 Machine: EM_X86_64
0 ## For implicit symbol table sections, the `Flags` field can also
1 ## be specified in YAML. Here we test the behavior in different cases.
2
3 ## When flags are not explicitly specified, yaml2obj assigns no flags
4 ## for .symtab and the SHF_ALLOC flag for .dynsym by default.
5
6 # RUN: yaml2obj --docnum=1 %s -o %t1
7 # RUN: llvm-readobj %t1 -S | FileCheck %s --check-prefix=CASE1
8
9 # CASE1: Name: .symtab
10 # CASE1-NEXT: Type: SHT_SYMTAB
11 # CASE1-NEXT: Flags [
12 # CASE1-NEXT: ]
13 # CASE1: Name: .dynsym
14 # CASE1-NEXT: Type: SHT_DYNSYM
15 # CASE1-NEXT: Flags [
16 # CASE1-NEXT: SHF_ALLOC
17 # CASE1-NEXT: ]
18
19 --- !ELF
20 FileHeader:
21 Class: ELFCLASS64
22 Data: ELFDATA2LSB
23 Type: ET_DYN
24 Machine: EM_X86_64
25 Sections:
26 - Name: .symtab
27 Type: SHT_SYMTAB
28 - Name: .dynsym
29 Type: SHT_SYMTAB
30
31 ## Check we can set arbitrary flags for .symtab/.dynsym.
32
33 # RUN: yaml2obj --docnum=2 %s -o %t2
34 # RUN: llvm-readobj %t2 -S | FileCheck %s --check-prefix=CASE2
35
36 # CASE2: Name: .symtab
37 # CASE2-NEXT: Type: SHT_SYMTAB
38 # CASE2-NEXT: Flags [
39 # CASE2-NEXT: SHF_ALLOC
40 # CASE2-NEXT: SHF_STRINGS
41 # CASE2-NEXT: ]
42 # CASE2: Name: .dynsym
43 # CASE2-NEXT: Type: SHT_DYNSYM
44 # CASE2-NEXT: Flags [
45 # CASE2-NEXT: SHF_STRINGS
46 # CASE2-NEXT: ]
47
48 --- !ELF
49 FileHeader:
50 Class: ELFCLASS64
51 Data: ELFDATA2LSB
52 Type: ET_DYN
53 Machine: EM_X86_64
54 Sections:
55 - Name: .symtab
56 Type: SHT_SYMTAB
57 Flags: [ SHF_ALLOC, SHF_STRINGS ]
58 - Name: .dynsym
59 Type: SHT_SYMTAB
60 Flags: [ SHF_STRINGS ]
61
62 ## Check no flags are set by default for .symtab when it is not
63 ## described in the YAML.
64
65 # RUN: yaml2obj --docnum=3 %s -o %t3
66 # RUN: llvm-readobj %t3 -S | FileCheck %s --check-prefix=CASE3
67
68 # CASE3: Name: .symtab
69 # CASE3-NEXT: Type: SHT_SYMTAB
70 # CASE3-NEXT: Flags [
71 # CASE3-NEXT: ]
72
73 --- !ELF
74 FileHeader:
75 Class: ELFCLASS64
76 Data: ELFDATA2LSB
77 Type: ET_DYN
78 Machine: EM_X86_64
328328 std::error_code ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr,
329329 ELFYAML::Section &S) {
330330 S.Type = Shdr->sh_type;
331 S.Flags = Shdr->sh_flags;
331 if (Shdr->sh_flags)
332 S.Flags = static_cast(Shdr->sh_flags);
332333 S.Address = Shdr->sh_addr;
333334 S.AddressAlign = Shdr->sh_addralign;
334335 if (Shdr->sh_entsize)
302302
303303 SHeader.sh_name = DotShStrtab.getOffset(SecName);
304304 SHeader.sh_type = Sec->Type;
305 SHeader.sh_flags = Sec->Flags;
305 if (Sec->Flags)
306 SHeader.sh_flags = *Sec->Flags;
306307 SHeader.sh_addr = Sec->Address;
307308 SHeader.sh_addralign = Sec->AddressAlign;
308309
423424 SHeader.sh_link = Link;
424425 }
425426
426 if (!IsStatic)
427 SHeader.sh_flags |= ELF::SHF_ALLOC;
427 if (YAMLSec && YAMLSec->Flags)
428 SHeader.sh_flags = *YAMLSec->Flags;
429 else if (!IsStatic)
430 SHeader.sh_flags = ELF::SHF_ALLOC;
428431
429432 // If the symbol table section is explicitly described in the YAML
430433 // then we should set the fields requested.
480483 if (YAMLSec && YAMLSec->EntSize)
481484 SHeader.sh_entsize = *YAMLSec->EntSize;
482485
486 if (YAMLSec && YAMLSec->Flags)
487 SHeader.sh_flags = *YAMLSec->Flags;
488 else if (Name == ".dynstr")
489 SHeader.sh_flags = ELF::SHF_ALLOC;
490
483491 // If .dynstr section is explicitly described in the YAML
484492 // then we want to use its section address.
485 if (Name == ".dynstr") {
486 if (YAMLSec)
487 SHeader.sh_addr = YAMLSec->Address;
488 // We assume that .dynstr is always allocatable.
489 SHeader.sh_flags |= ELF::SHF_ALLOC;
490 }
493 // TODO: Allow this for any explicitly described section.
494 if (YAMLSec && Name == ".dynstr")
495 SHeader.sh_addr = YAMLSec->Address;
491496 }
492497
493498 template