From 31eec06d967c69a3b38610d08277630a7ff16e91 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 20 Sep 2019 09:15:36 +0000 Subject: [PATCH] [yaml2obj/obj2yaml] - Do not trigger llvm_unreachable when dumping/parsing relocations and e_machine is unsupported. Currently when e_machine is set to something that is not supported by YAML lib, then tools fail with llvm_unreachable. In this patch I allow them to handle relocations in this case. It can be used to dump and create objects for broken or unsupported targets. Differential revision: https://reviews.llvm.org/D67657 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372377 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ObjectYAML/ELFYAML.cpp | 3 +- .../obj2yaml/relocation-unsupported-machine.yaml | 38 ++++++++++++++++++++++ .../yaml2obj/relocation-unsupported-machine.yaml | 24 ++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/tools/obj2yaml/relocation-unsupported-machine.yaml create mode 100644 test/tools/yaml2obj/relocation-unsupported-machine.yaml diff --git a/lib/ObjectYAML/ELFYAML.cpp b/lib/ObjectYAML/ELFYAML.cpp index 5d16f0bd074..161224b0bb7 100644 --- a/lib/ObjectYAML/ELFYAML.cpp +++ b/lib/ObjectYAML/ELFYAML.cpp @@ -655,7 +655,8 @@ void ScalarEnumerationTraits::enumeration( #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def" break; default: - llvm_unreachable("Unsupported architecture"); + // Nothing to do. + break; } #undef ELF_RELOC IO.enumFallback(Value); diff --git a/test/tools/obj2yaml/relocation-unsupported-machine.yaml b/test/tools/obj2yaml/relocation-unsupported-machine.yaml new file mode 100644 index 00000000000..e55420f07b3 --- /dev/null +++ b/test/tools/obj2yaml/relocation-unsupported-machine.yaml @@ -0,0 +1,38 @@ +## Show that obj2yaml is able to dump relocations when `e_machine` is unknown. + +# RUN: yaml2obj %s -o %t1 +# RUN: obj2yaml %t1 | FileCheck %s + +# CHECK: --- !ELF +# CHECK-NEXT: FileHeader: +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2MSB +# CHECK-NEXT: Type: ET_REL +# CHECK-NEXT: Machine: 0x1234 +# CHECK-NEXT: Sections: +# CHECK-NEXT: - Name: .rela.text +# CHECK-NEXT: Type: SHT_RELA +# CHECK-NEXT: Link: .symtab +# CHECK-NEXT: EntSize: 0x0000000000000018 +# CHECK-NEXT: Relocations: +# CHECK-NEXT: - Offset: 0x0000000000000001 +# CHECK-NEXT: Symbol: '' +# CHECK-NEXT: Type: 0x00000002 +# CHECK-NEXT: - Offset: 0x0000000000000003 +# CHECK-NEXT: Symbol: '' +# CHECK-NEXT: Type: 0x00000004 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: 0x1234 +Sections: + - Name: .rela.text + Type: SHT_RELA + Relocations: + - Offset: 0x1 + Type: 0x2 + - Offset: 0x3 + Type: 0x4 diff --git a/test/tools/yaml2obj/relocation-unsupported-machine.yaml b/test/tools/yaml2obj/relocation-unsupported-machine.yaml new file mode 100644 index 00000000000..3943e64d14e --- /dev/null +++ b/test/tools/yaml2obj/relocation-unsupported-machine.yaml @@ -0,0 +1,24 @@ +## Show that yaml2obj is able to write relocations for an unknown e_machine properly. + +# RUN: yaml2obj %s -o %t1 +# RUN: llvm-readelf %t1 --relocations | FileCheck %s + +# CHECK: Relocation section '.rela.text' at offset 0x40 contains 2 entries: +# CHECK: Offset Info Type Symbol's Value Symbol's Name + Addend +# CHECK-NEXT: 0000000000000001 0000000000000002 Unknown 0 +# CHECK-NEXT: 0000000000000003 0000000000000004 Unknown 0 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2MSB + Type: ET_REL + Machine: 0x1234 +Sections: + - Name: .rela.text + Type: SHT_RELA + Relocations: + - Offset: 0x1 + Type: 0x2 + - Offset: 0x3 + Type: 0x4 -- 2.11.4.GIT