Skip to content
Snippets Groups Projects
Commit 65a6828b authored by George Rimar's avatar George Rimar
Browse files

[yaml2obj] - Add a support for changing EntSize.

I was trying to add a test case for LLD and found that it
is impossible to set sh_entsize via yaml.
The patch implements the missing part.

Differential revision: https://reviews.llvm.org/D50235

llvm-svn: 339113
parent d51f702f
No related branches found
No related tags found
No related merge requests found
...@@ -123,6 +123,7 @@ struct Section { ...@@ -123,6 +123,7 @@ struct Section {
StringRef Link; StringRef Link;
StringRef Info; StringRef Info;
llvm::yaml::Hex64 AddressAlign; llvm::yaml::Hex64 AddressAlign;
Optional<llvm::yaml::Hex64> EntSize;
Section(SectionKind Kind) : Kind(Kind) {} Section(SectionKind Kind) : Kind(Kind) {}
virtual ~Section(); virtual ~Section();
......
...@@ -816,6 +816,7 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { ...@@ -816,6 +816,7 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
IO.mapOptional("Address", Section.Address, Hex64(0)); IO.mapOptional("Address", Section.Address, Hex64(0));
IO.mapOptional("Link", Section.Link, StringRef()); IO.mapOptional("Link", Section.Link, StringRef());
IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
IO.mapOptional("EntSize", Section.EntSize);
IO.mapOptional("Info", Section.Info, StringRef()); IO.mapOptional("Info", Section.Info, StringRef());
} }
......
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj -sections %t | FileCheck %s
!ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
OSABI: ELFOSABI_FREEBSD
Type: ET_REL
Machine: EM_X86_64
Sections:
- Type: SHT_PROGBITS
Name: .strings
Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x04
Content: "FFFFFFFFFFFFFFFF"
EntSize: 0x1
- Name: .mydynamic
Type: SHT_DYNAMIC
EntSize: 0x0
## Check we were able to set entry size for .strings and .mydynamic
# CHECK: Name: .strings
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_ALLOC
# CHECK-NEXT: SHF_MERGE
# CHECK-NEXT: SHF_STRINGS
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size:
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment:
# CHECK-NEXT: EntrySize: 1
# CHECK-NEXT: }
# CHECK: Name: .mydynamic
# CHECK-NEXT: Type: SHT_DYNAMIC
# CHECK-NEXT: Flags [
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size:
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment:
# CHECK-NEXT: EntrySize: 0
# CHECK-NEXT: }
...@@ -461,7 +461,9 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader, ...@@ -461,7 +461,9 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
Section.Content.writeAsBinary(OS); Section.Content.writeAsBinary(OS);
for (auto i = Section.Content.binary_size(); i < Section.Size; ++i) for (auto i = Section.Content.binary_size(); i < Section.Size; ++i)
OS.write(0); OS.write(0);
if (Section.Type == llvm::ELF::SHT_RELR) if (Section.EntSize)
SHeader.sh_entsize = *Section.EntSize;
else if (Section.Type == llvm::ELF::SHT_RELR)
SHeader.sh_entsize = sizeof(Elf_Relr); SHeader.sh_entsize = sizeof(Elf_Relr);
else if (Section.Type == llvm::ELF::SHT_DYNAMIC) else if (Section.Type == llvm::ELF::SHT_DYNAMIC)
SHeader.sh_entsize = sizeof(Elf_Dyn); SHeader.sh_entsize = sizeof(Elf_Dyn);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment