[llvm] r339113 - [yaml2obj] - Add a support for changing EntSize.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 7 01:11:38 PDT 2018
Author: grimar
Date: Tue Aug 7 01:11:38 2018
New Revision: 339113
URL: http://llvm.org/viewvc/llvm-project?rev=339113&view=rev
Log:
[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
Added:
llvm/trunk/test/tools/yaml2obj/elf-ent-size.yaml
Modified:
llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Modified: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h?rev=339113&r1=339112&r2=339113&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Tue Aug 7 01:11:38 2018
@@ -123,6 +123,7 @@ struct Section {
StringRef Link;
StringRef Info;
llvm::yaml::Hex64 AddressAlign;
+ Optional<llvm::yaml::Hex64> EntSize;
Section(SectionKind Kind) : Kind(Kind) {}
virtual ~Section();
Modified: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFYAML.cpp?rev=339113&r1=339112&r2=339113&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Tue Aug 7 01:11:38 2018
@@ -816,6 +816,7 @@ static void commonSectionMapping(IO &IO,
IO.mapOptional("Address", Section.Address, Hex64(0));
IO.mapOptional("Link", Section.Link, StringRef());
IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
+ IO.mapOptional("EntSize", Section.EntSize);
IO.mapOptional("Info", Section.Info, StringRef());
}
Added: llvm/trunk/test/tools/yaml2obj/elf-ent-size.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-ent-size.yaml?rev=339113&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-ent-size.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/elf-ent-size.yaml Tue Aug 7 01:11:38 2018
@@ -0,0 +1,50 @@
+# 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: }
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=339113&r1=339112&r2=339113&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Tue Aug 7 01:11:38 2018
@@ -461,7 +461,9 @@ ELFState<ELFT>::writeSectionContent(Elf_
Section.Content.writeAsBinary(OS);
for (auto i = Section.Content.binary_size(); i < Section.Size; ++i)
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);
else if (Section.Type == llvm::ELF::SHT_DYNAMIC)
SHeader.sh_entsize = sizeof(Elf_Dyn);
More information about the llvm-commits
mailing list