[llvm] bd7daf5 - [yaml2obj] - Don't crash when `FileHeader` declares an empty `Flags` key in specific situations.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 06:09:54 PDT 2020
Author: Georgii Rymar
Date: 2020-08-18T16:09:28+03:00
New Revision: bd7daf5ceb92db00d3fc5d1ce8d4f74dcd03ebb9
URL: https://github.com/llvm/llvm-project/commit/bd7daf5ceb92db00d3fc5d1ce8d4f74dcd03ebb9
DIFF: https://github.com/llvm/llvm-project/commit/bd7daf5ceb92db00d3fc5d1ce8d4f74dcd03ebb9.diff
LOG: [yaml2obj] - Don't crash when `FileHeader` declares an empty `Flags` key in specific situations.
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.
Differential revision: https://reviews.llvm.org/D86138
Added:
llvm/test/tools/yaml2obj/ELF/eflags.yaml
Modified:
llvm/lib/ObjectYAML/ELFYAML.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 319e37022c85a..e5d5e6a01bc6b 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -434,10 +434,8 @@ void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
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
diff --git a/llvm/test/tools/yaml2obj/ELF/eflags.yaml b/llvm/test/tools/yaml2obj/ELF/eflags.yaml
new file mode 100644
index 0000000000000..8b90a2b2c9445
--- /dev/null
+++ b/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: [ ]
More information about the llvm-commits
mailing list