[PATCH] D86138: [yaml2obj] - Don't crash when `FileHeader` declares an empty `Flags` key in specific situations.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 05:58:12 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
grimar requested review of this revision.

We currently call the `llvm_unreachable` for the following YAML:

  --- !ELF
  FileHeader:
    Class:   ELFCLASS32
    Data:    ELFDATA2LSB
    Type:    ET_REL
    Machine: EM_NONE
    Flags:   [ ]

it happens because the `Flags` key is present, though `EM_NONE` is a
machine type that has no known `EF_*` values and we call `llvm_unreachable` by mistake.


https://reviews.llvm.org/D86138

Files:
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/test/tools/yaml2obj/ELF/eflags.yaml


Index: llvm/test/tools/yaml2obj/ELF/eflags.yaml
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/ELF/eflags.yaml
@@ -0,0 +1,16 @@
+## Check how the 'Flags' key can be used to encode e_flags field values.
+
+## Check we are able to produce no flags for EM_NONE. EM_NONE is an arbitrary
+## e_machine type that has no EF_* values defined for it.
+# RUN: yaml2obj %s -o %t-no-flags
+# RUN: llvm-readelf --file-headers %t-no-flags | FileCheck %s --check-prefix=NOFLAGS
+
+# NOFLAGS: Flags: 0x0{{$}}
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_NONE
+  Flags:   [ ]
Index: llvm/lib/ObjectYAML/ELFYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFYAML.cpp
+++ llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -434,10 +434,8 @@
     BCase(EF_AMDGPU_XNACK);
     BCase(EF_AMDGPU_SRAM_ECC);
     break;
-  case ELF::EM_X86_64:
-    break;
   default:
-    llvm_unreachable("Unsupported architecture");
+    break;
   }
 #undef BCase
 #undef BCaseMask


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86138.286262.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200818/a4eca5e1/attachment.bin>


More information about the llvm-commits mailing list