[PATCH] D67657: [yaml2obj/obj2yaml] - Do not trigger llvm_unreachable when dumping/parsing relocations and e_machine is unsupported.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 02:17:09 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d69967f4411: [yaml2obj/obj2yaml] - Do not trigger llvm_unreachable when dumping/parsing… (authored by grimar).
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D67657?vs=220492&id=220984#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67657/new/

https://reviews.llvm.org/D67657

Files:
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml
  llvm/test/tools/yaml2obj/relocation-unsupported-machine.yaml


Index: llvm/test/tools/yaml2obj/relocation-unsupported-machine.yaml
===================================================================
--- /dev/null
+++ llvm/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
Index: llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml
===================================================================
--- /dev/null
+++ llvm/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
Index: llvm/lib/ObjectYAML/ELFYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFYAML.cpp
+++ llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -655,7 +655,8 @@
 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
     break;
   default:
-    llvm_unreachable("Unsupported architecture");
+    // Nothing to do.
+    break;
   }
 #undef ELF_RELOC
   IO.enumFallback<Hex32>(Value);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67657.220984.patch
Type: text/x-patch
Size: 2751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190920/0ec326d2/attachment.bin>


More information about the llvm-commits mailing list