[PATCH] D90019: [yaml2obj] - Add a way to override the sh_addralign field of a section.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 03:04:15 PDT 2020
This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.
Closed by commit rG2d59ed4e62a9: [yaml2obj] - Add a way to override the sh_addralign field of a section. (authored by grimar).
Changed prior to commit:
https://reviews.llvm.org/D90019?vs=300237&id=300929#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90019/new/
https://reviews.llvm.org/D90019
Files:
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/yaml2obj/ELF/override-shaddralign.yaml
Index: llvm/test/tools/yaml2obj/ELF/override-shaddralign.yaml
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/ELF/override-shaddralign.yaml
@@ -0,0 +1,30 @@
+## Check we are able to set a custom sh_addralign field for different sections
+## and that doing this does not affect the output size.
+
+## Test that we are able to override the sh_addralign section
+## field with use of the "ShAddrAlign" key.
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf --sections %t | FileCheck %s --check-prefix=CHECK
+
+# CHECK: Section Headers:
+# CHECK-NEXT: [Nr] Name {{.*}} Off Size ES Flg Lk Inf Al
+# CHECK-NEXT: [ 0] {{.*}} 000000 000000 00 0 0 0
+# CHECK-NEXT: [ 1] .foo {{.*}} 000080 000000 00 0 0 1229782938247303441
+# CHECK-NEXT: [ 2] .bar {{.*}} 000100 000000 00 0 0 2459565876494606882
+# CHECK-NEXT: [ 3] .strtab {{.*}} 000100 000001 00 0 0 1
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ AddressAlign: 0x80
+ ShAddrAlign: 0x1111111111111111
+ - Name: .bar
+ Type: SHT_PROGBITS
+ AddressAlign: 0x100
+ ShAddrAlign: 0x2222222222222222
Index: llvm/lib/ObjectYAML/ELFYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFYAML.cpp
+++ llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1113,9 +1113,9 @@
// are producing YAML, because yaml2obj sets appropriate values for them
// automatically when they are not explicitly defined.
assert(!IO.outputting() ||
- (!Section.ShOffset.hasValue() && !Section.ShSize.hasValue() &&
- !Section.ShName.hasValue() && !Section.ShFlags.hasValue() &&
- !Section.ShType.hasValue()));
+ (!Section.ShOffset && !Section.ShSize && !Section.ShName &&
+ !Section.ShFlags && !Section.ShType && !Section.ShAddrAlign));
+ IO.mapOptional("ShAddrAlign", Section.ShAddrAlign);
IO.mapOptional("ShName", Section.ShName);
IO.mapOptional("ShOffset", Section.ShOffset);
IO.mapOptional("ShSize", Section.ShSize);
Index: llvm/lib/ObjectYAML/ELFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -552,6 +552,8 @@
static void overrideFields(ELFYAML::Section *From, typename ELFT::Shdr &To) {
if (!From)
return;
+ if (From->ShAddrAlign)
+ To.sh_addralign = *From->ShAddrAlign;
if (From->ShFlags)
To.sh_flags = *From->ShFlags;
if (From->ShName)
Index: llvm/include/llvm/ObjectYAML/ELFYAML.h
===================================================================
--- llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -203,6 +203,9 @@
// The following members are used to override section fields which is
// useful for creating invalid objects.
+ // This can be used to override the sh_addralign field.
+ Optional<llvm::yaml::Hex64> ShAddrAlign;
+
// This can be used to override the offset stored in the sh_name field.
// It does not affect the name stored in the string table.
Optional<llvm::yaml::Hex64> ShName;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90019.300929.patch
Type: text/x-patch
Size: 3272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201027/f5dd250f/attachment.bin>
More information about the llvm-commits
mailing list