summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/BinaryFormat/DynamicTags.def1
-rw-r--r--llvm/lib/ObjectYAML/ELFYAML.cpp33
-rw-r--r--llvm/test/tools/obj2yaml/dynamic-section-arch-tags.test272
3 files changed, 302 insertions, 4 deletions
diff --git a/llvm/include/llvm/BinaryFormat/DynamicTags.def b/llvm/include/llvm/BinaryFormat/DynamicTags.def
index 2e15cc30fca..3f9b7b80b61 100644
--- a/llvm/include/llvm/BinaryFormat/DynamicTags.def
+++ b/llvm/include/llvm/BinaryFormat/DynamicTags.def
@@ -201,6 +201,7 @@ DYNAMIC_TAG(FILTER, 0x7FFFFFFF) // Shared object to get values from
#ifdef DYNAMIC_TAG_MARKER_DEFINED
#undef DYNAMIC_TAG_MARKER
+#undef DYNAMIC_TAG_MARKER_DEFINED
#endif
#ifdef MIPS_DYNAMIC_TAG_DEFINED
#undef MIPS_DYNAMIC_TAG
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index b2b69d5c30e..352048b8de8 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -662,19 +662,44 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
void ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG>::enumeration(
IO &IO, ELFYAML::ELF_DYNTAG &Value) {
- assert(IO.getContext() && "The IO context is not initialized");
+ const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
+ assert(Object && "The IO context is not initialized");
-// TODO: For simplicity we do not handle target specific flags. They are
-// still supported and will be shown as a raw numeric values in the output.
+// Disable architecture specific tags by default. We might enable them below.
#define MIPS_DYNAMIC_TAG(name, value)
#define HEXAGON_DYNAMIC_TAG(name, value)
#define PPC64_DYNAMIC_TAG(name, value)
-// Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
+// Ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
#define DYNAMIC_TAG_MARKER(name, value)
#define STRINGIFY(X) (#X)
#define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
+ switch (Object->Header.Machine) {
+ case ELF::EM_MIPS:
+#undef MIPS_DYNAMIC_TAG
+#define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
+#include "llvm/BinaryFormat/DynamicTags.def"
+#undef MIPS_DYNAMIC_TAG
+#define MIPS_DYNAMIC_TAG(name, value)
+ break;
+ case ELF::EM_HEXAGON:
+#undef HEXAGON_DYNAMIC_TAG
+#define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
#include "llvm/BinaryFormat/DynamicTags.def"
+#undef HEXAGON_DYNAMIC_TAG
+#define HEXAGON_DYNAMIC_TAG(name, value)
+ break;
+ case ELF::EM_PPC64:
+#undef PPC64_DYNAMIC_TAG
+#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
+#include "llvm/BinaryFormat/DynamicTags.def"
+#undef PPC64_DYNAMIC_TAG
+#define PPC64_DYNAMIC_TAG(name, value)
+ break;
+ default:
+#include "llvm/BinaryFormat/DynamicTags.def"
+ break;
+ }
#undef MIPS_DYNAMIC_TAG
#undef HEXAGON_DYNAMIC_TAG
diff --git a/llvm/test/tools/obj2yaml/dynamic-section-arch-tags.test b/llvm/test/tools/obj2yaml/dynamic-section-arch-tags.test
new file mode 100644
index 00000000000..bc932371266
--- /dev/null
+++ b/llvm/test/tools/obj2yaml/dynamic-section-arch-tags.test
@@ -0,0 +1,272 @@
+## Check we can use obj2yaml to yamalize the object
+## containing architecture specific dynamic tags.
+
+## Check we can handle MIPS specific tags.
+# RUN: yaml2obj -docnum=1 %s -o %t1
+# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=MIPS
+
+# MIPS: - Tag: DT_MIPS_RLD_VERSION
+# MIPS-NEXT: Value: 0x0000000000000001
+# MIPS-NEXT: - Tag: DT_MIPS_TIME_STAMP
+# MIPS-NEXT: Value: 0x0000000000000002
+# MIPS-NEXT: - Tag: DT_MIPS_ICHECKSUM
+# MIPS-NEXT: Value: 0x0000000000000003
+# MIPS-NEXT: - Tag: DT_MIPS_IVERSION
+# MIPS-NEXT: Value: 0x0000000000000004
+# MIPS-NEXT: - Tag: DT_MIPS_FLAGS
+# MIPS-NEXT: Value: 0x0000000000000005
+# MIPS-NEXT: - Tag: DT_MIPS_BASE_ADDRESS
+# MIPS-NEXT: Value: 0x0000000000000006
+# MIPS-NEXT: - Tag: DT_MIPS_MSYM
+# MIPS-NEXT: Value: 0x0000000000000007
+# MIPS-NEXT: - Tag: DT_MIPS_CONFLICT
+# MIPS-NEXT: Value: 0x0000000000000008
+# MIPS-NEXT: - Tag: DT_MIPS_LIBLIST
+# MIPS-NEXT: Value: 0x0000000000000009
+# MIPS-NEXT: - Tag: DT_MIPS_LOCAL_GOTNO
+# MIPS-NEXT: Value: 0x000000000000000A
+# MIPS-NEXT: - Tag: DT_MIPS_CONFLICTNO
+# MIPS-NEXT: Value: 0x000000000000000B
+# MIPS-NEXT: - Tag: DT_MIPS_LIBLISTNO
+# MIPS-NEXT: Value: 0x000000000000000C
+# MIPS-NEXT: - Tag: DT_MIPS_SYMTABNO
+# MIPS-NEXT: Value: 0x000000000000000D
+# MIPS-NEXT: - Tag: DT_MIPS_UNREFEXTNO
+# MIPS-NEXT: Value: 0x000000000000000E
+# MIPS-NEXT: - Tag: DT_MIPS_GOTSYM
+# MIPS-NEXT: Value: 0x000000000000000F
+# MIPS-NEXT: - Tag: DT_MIPS_HIPAGENO
+# MIPS-NEXT: Value: 0x0000000000000010
+# MIPS-NEXT: - Tag: DT_MIPS_RLD_MAP
+# MIPS-NEXT: Value: 0x0000000000000011
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASS
+# MIPS-NEXT: Value: 0x0000000000000012
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASS_NO
+# MIPS-NEXT: Value: 0x0000000000000013
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_INSTANCE
+# MIPS-NEXT: Value: 0x0000000000000014
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_INSTANCE_NO
+# MIPS-NEXT: Value: 0x0000000000000015
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_RELOC
+# MIPS-NEXT: Value: 0x0000000000000016
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_RELOC_NO
+# MIPS-NEXT: Value: 0x0000000000000017
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_SYM
+# MIPS-NEXT: Value: 0x0000000000000018
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_SYM_NO
+# MIPS-NEXT: Value: 0x0000000000000019
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASSSYM
+# MIPS-NEXT: Value: 0x000000000000001A
+# MIPS-NEXT: - Tag: DT_MIPS_DELTA_CLASSSYM_NO
+# MIPS-NEXT: Value: 0x000000000000001B
+# MIPS-NEXT: - Tag: DT_MIPS_CXX_FLAGS
+# MIPS-NEXT: Value: 0x000000000000001C
+# MIPS-NEXT: - Tag: DT_MIPS_PIXIE_INIT
+# MIPS-NEXT: Value: 0x000000000000001D
+# MIPS-NEXT: - Tag: DT_MIPS_SYMBOL_LIB
+# MIPS-NEXT: Value: 0x000000000000001E
+# MIPS-NEXT: - Tag: DT_MIPS_LOCALPAGE_GOTIDX
+# MIPS-NEXT: Value: 0x000000000000001F
+# MIPS-NEXT: - Tag: DT_MIPS_LOCAL_GOTIDX
+# MIPS-NEXT: Value: 0x0000000000000020
+# MIPS-NEXT: - Tag: DT_MIPS_HIDDEN_GOTIDX
+# MIPS-NEXT: Value: 0x0000000000000021
+# MIPS-NEXT: - Tag: DT_MIPS_PROTECTED_GOTIDX
+# MIPS-NEXT: Value: 0x0000000000000022
+# MIPS-NEXT: - Tag: DT_MIPS_OPTIONS
+# MIPS-NEXT: Value: 0x0000000000000023
+# MIPS-NEXT: - Tag: DT_MIPS_INTERFACE
+# MIPS-NEXT: Value: 0x0000000000000024
+# MIPS-NEXT: - Tag: DT_MIPS_DYNSTR_ALIGN
+# MIPS-NEXT: Value: 0x0000000000000025
+# MIPS-NEXT: - Tag: DT_MIPS_INTERFACE_SIZE
+# MIPS-NEXT: Value: 0x0000000000000026
+# MIPS-NEXT: - Tag: DT_MIPS_RLD_TEXT_RESOLVE_ADDR
+# MIPS-NEXT: Value: 0x0000000000000027
+# MIPS-NEXT: - Tag: DT_MIPS_PERF_SUFFIX
+# MIPS-NEXT: Value: 0x0000000000000028
+# MIPS-NEXT: - Tag: DT_MIPS_COMPACT_SIZE
+# MIPS-NEXT: Value: 0x0000000000000029
+# MIPS-NEXT: - Tag: DT_MIPS_GP_VALUE
+# MIPS-NEXT: Value: 0x000000000000002A
+# MIPS-NEXT: - Tag: DT_MIPS_AUX_DYNAMIC
+# MIPS-NEXT: Value: 0x000000000000002B
+# MIPS-NEXT: - Tag: DT_MIPS_PLTGOT
+# MIPS-NEXT: Value: 0x000000000000002C
+# MIPS-NEXT: - Tag: DT_MIPS_RWPLT
+# MIPS-NEXT: Value: 0x000000000000002D
+# MIPS-NEXT: - Tag: DT_MIPS_RLD_MAP_REL
+# MIPS-NEXT: Value: 0x000000000000002E
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+Sections:
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Entries:
+ - Tag: DT_MIPS_RLD_VERSION
+ Value: 0x0000000000000001
+ - Tag: DT_MIPS_TIME_STAMP
+ Value: 0x0000000000000002
+ - Tag: DT_MIPS_ICHECKSUM
+ Value: 0x0000000000000003
+ - Tag: DT_MIPS_IVERSION
+ Value: 0x0000000000000004
+ - Tag: DT_MIPS_FLAGS
+ Value: 0x0000000000000005
+ - Tag: DT_MIPS_BASE_ADDRESS
+ Value: 0x0000000000000006
+ - Tag: DT_MIPS_MSYM
+ Value: 0x0000000000000007
+ - Tag: DT_MIPS_CONFLICT
+ Value: 0x0000000000000008
+ - Tag: DT_MIPS_LIBLIST
+ Value: 0x0000000000000009
+ - Tag: DT_MIPS_LOCAL_GOTNO
+ Value: 0x000000000000000A
+ - Tag: DT_MIPS_CONFLICTNO
+ Value: 0x000000000000000B
+ - Tag: DT_MIPS_LIBLISTNO
+ Value: 0x000000000000000C
+ - Tag: DT_MIPS_SYMTABNO
+ Value: 0x000000000000000D
+ - Tag: DT_MIPS_UNREFEXTNO
+ Value: 0x000000000000000E
+ - Tag: DT_MIPS_GOTSYM
+ Value: 0x000000000000000F
+ - Tag: DT_MIPS_HIPAGENO
+ Value: 0x0000000000000010
+ - Tag: DT_MIPS_RLD_MAP
+ Value: 0x0000000000000011
+ - Tag: DT_MIPS_DELTA_CLASS
+ Value: 0x0000000000000012
+ - Tag: DT_MIPS_DELTA_CLASS_NO
+ Value: 0x0000000000000013
+ - Tag: DT_MIPS_DELTA_INSTANCE
+ Value: 0x0000000000000014
+ - Tag: DT_MIPS_DELTA_INSTANCE_NO
+ Value: 0x0000000000000015
+ - Tag: DT_MIPS_DELTA_RELOC
+ Value: 0x0000000000000016
+ - Tag: DT_MIPS_DELTA_RELOC_NO
+ Value: 0x0000000000000017
+ - Tag: DT_MIPS_DELTA_SYM
+ Value: 0x0000000000000018
+ - Tag: DT_MIPS_DELTA_SYM_NO
+ Value: 0x0000000000000019
+ - Tag: DT_MIPS_DELTA_CLASSSYM
+ Value: 0x000000000000001A
+ - Tag: DT_MIPS_DELTA_CLASSSYM_NO
+ Value: 0x000000000000001B
+ - Tag: DT_MIPS_CXX_FLAGS
+ Value: 0x000000000000001C
+ - Tag: DT_MIPS_PIXIE_INIT
+ Value: 0x000000000000001D
+ - Tag: DT_MIPS_SYMBOL_LIB
+ Value: 0x000000000000001E
+ - Tag: DT_MIPS_LOCALPAGE_GOTIDX
+ Value: 0x000000000000001F
+ - Tag: DT_MIPS_LOCAL_GOTIDX
+ Value: 0x0000000000000020
+ - Tag: DT_MIPS_HIDDEN_GOTIDX
+ Value: 0x0000000000000021
+ - Tag: DT_MIPS_PROTECTED_GOTIDX
+ Value: 0x0000000000000022
+ - Tag: DT_MIPS_OPTIONS
+ Value: 0x0000000000000023
+ - Tag: DT_MIPS_INTERFACE
+ Value: 0x0000000000000024
+ - Tag: DT_MIPS_DYNSTR_ALIGN
+ Value: 0x0000000000000025
+ - Tag: DT_MIPS_INTERFACE_SIZE
+ Value: 0x0000000000000026
+ - Tag: DT_MIPS_RLD_TEXT_RESOLVE_ADDR
+ Value: 0x0000000000000027
+ - Tag: DT_MIPS_PERF_SUFFIX
+ Value: 0x0000000000000028
+ - Tag: DT_MIPS_COMPACT_SIZE
+ Value: 0x0000000000000029
+ - Tag: DT_MIPS_GP_VALUE
+ Value: 0x000000000000002A
+ - Tag: DT_MIPS_AUX_DYNAMIC
+ Value: 0x000000000000002B
+ - Tag: DT_MIPS_PLTGOT
+ Value: 0x000000000000002C
+ - Tag: DT_MIPS_RWPLT
+ Value: 0x000000000000002D
+ - Tag: DT_MIPS_RLD_MAP_REL
+ Value: 0x000000000000002E
+
+## Check we can handle Hexagon specific tags.
+# RUN: yaml2obj -docnum=2 %s -o %t2
+# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=HEXAGON
+
+# HEXAGON: - Tag: DT_HEXAGON_SYMSZ
+# HEXAGON-NEXT: Value: 0x0000000000000001
+# HEXAGON-NEXT: - Tag: DT_HEXAGON_VER
+# HEXAGON-NEXT: Value: 0x0000000000000002
+# HEXAGON-NEXT: - Tag: DT_HEXAGON_PLT
+# HEXAGON-NEXT: Value: 0x0000000000000003
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_HEXAGON
+Sections:
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Entries:
+ - Tag: DT_HEXAGON_SYMSZ
+ Value: 0x0000000000000001
+ - Tag: DT_HEXAGON_VER
+ Value: 0x0000000000000002
+ - Tag: DT_HEXAGON_PLT
+ Value: 0x0000000000000003
+
+## Check we can handle PPC64 specific tags.
+# RUN: yaml2obj -docnum=3 %s -o %t3
+# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=EM_PPC64
+
+# EM_PPC64: - Tag: DT_PPC64_GLINK
+# EM_PPC64-NEXT: Value: 0x0000000000000001
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_PPC64
+Sections:
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Entries:
+ - Tag: DT_PPC64_GLINK
+ Value: 0x0000000000000001
+
+## Check we can't use a tag from a different architecture,
+## even if it has the same numeric value as a valid tag.
+## Here for EM_PPC64 we are trying to use DT_HEXAGON_SYMSZ
+## instead of DT_PPC64_GLINK. They both have value of 0x70000000.
+
+# RUN: not yaml2obj -docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERR
+# ERR: error: invalid hex64 number
+# ERR-NEXT: - Tag: DT_HEXAGON_SYMSZ
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_PPC64
+Sections:
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Entries:
+ - Tag: DT_HEXAGON_SYMSZ
+ Value: 0x0000000000000001
OpenPOWER on IntegriCloud