[llvm] ea0f66e - [obj2yaml][yaml2obj] - Stop recognizing SHT_MIPS_ABIFLAGS on non-MIPS targets.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 01:29:12 PDT 2020
Author: Georgii Rymar
Date: 2020-09-28T11:28:53+03:00
New Revision: ea0f66e84856519e08b255fd1010d7f07ad0dabd
URL: https://github.com/llvm/llvm-project/commit/ea0f66e84856519e08b255fd1010d7f07ad0dabd
DIFF: https://github.com/llvm/llvm-project/commit/ea0f66e84856519e08b255fd1010d7f07ad0dabd.diff
LOG: [obj2yaml][yaml2obj] - Stop recognizing SHT_MIPS_ABIFLAGS on non-MIPS targets.
Currently we are always recognizing the `SHT_MIPS_ABIFLAGS` section,
even on non-MIPS targets.
The problem of doing this is briefly discussed in D88228 which does the same for `SHT_ARM_EXIDX`:
"The problem is that `SHT_ARM_EXIDX` shares the value with `SHT_X86_64_UNWIND (0x70000001U)`.
We might have other machine specific conflicts, e.g.
`SHT_ARM_ATTRIBUTES` vs `SHT_MSP430_ATTRIBUTES` vs `SHT_RISCV_ATTRIBUTES (0x70000003U)`."
I think we should only recognize target specific sections when the machine type
matches. I.e. `SHT_MIPS_*` should be recognized only on `MIPS`, `SHT_ARM_*`
only on `ARM` etc.
This patch stops recognizing `SHT_MIPS_ABIFLAGS` on `non-MIPS` targets.
Note: I had to update `ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration`, because
otherwise test crashes, calling `llvm_unreachable`.
Differential revision: https://reviews.llvm.org/D88294
Added:
Modified:
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/obj2yaml/ELF/mips-abi-flags.yaml
llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 2ebea1176a6f..03799f4545d4 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -816,6 +816,7 @@ void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
IO.enumCase(Value, "MIPS5", 5);
IO.enumCase(Value, "MIPS32", 32);
IO.enumCase(Value, "MIPS64", 64);
+ IO.enumFallback<Hex32>(Value);
}
void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
@@ -1306,6 +1307,14 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
IO.mapRequired("Type", Type);
}
+ const auto &Obj = *static_cast<ELFYAML::Object *>(IO.getContext());
+ if (Obj.getMachine() == ELF::EM_MIPS && Type == ELF::SHT_MIPS_ABIFLAGS) {
+ if (!IO.outputting())
+ Section.reset(new ELFYAML::MipsABIFlags());
+ sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
+ return;
+ }
+
switch (Type) {
case ELF::SHT_DYNAMIC:
if (!IO.outputting())
@@ -1348,11 +1357,6 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
Section.reset(new ELFYAML::GnuHashSection());
sectionMapping(IO, *cast<ELFYAML::GnuHashSection>(Section.get()));
break;
- case ELF::SHT_MIPS_ABIFLAGS:
- if (!IO.outputting())
- Section.reset(new ELFYAML::MipsABIFlags());
- sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
- break;
case ELF::SHT_GNU_verdef:
if (!IO.outputting())
Section.reset(new ELFYAML::VerdefSection());
diff --git a/llvm/test/tools/obj2yaml/ELF/mips-abi-flags.yaml b/llvm/test/tools/obj2yaml/ELF/mips-abi-flags.yaml
index e51e1c214ce7..02fcff52fb38 100644
--- a/llvm/test/tools/obj2yaml/ELF/mips-abi-flags.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/mips-abi-flags.yaml
@@ -39,3 +39,35 @@ Sections:
CPR2Size: REG_NONE
Flags1: [ ODDSPREG ]
Flags2: 0x0
+
+## Check how we dump the SHT_MIPS_ABIFLAGS (0x7000002a) section when
+## the machine type is not EM_MIPS. It is dumped as a regular
+## section of an unknown type.
+
+# RUN: yaml2obj %s --docnum=2 -DMACHINE=EM_NONE -o %t2.notmips
+# RUN: obj2yaml %t2.notmips | FileCheck %s --check-prefix=NOT-MIPS
+
+# RUN: yaml2obj %s --docnum=2 -DMACHINE=EM_MIPS -o %t2.mips
+# RUN: obj2yaml %t2.mips | FileCheck %s --check-prefix=MIPS
+
+# MIPS: - Name: .MIPS.abiflags
+# MIPS-NEXT: Type: SHT_MIPS_ABIFLAGS
+# MIPS-NEXT: ISA: 0x00000000
+# MIPS-NEXT: ...
+
+# NOT-MIPS: - Name: .MIPS.abiflags
+# NOT-MIPS-NEXT: Type: 0x7000002A
+# NOT-MIPS-NEXT: Content: '000000000000000000000000000000000000000000000000'
+# NOT-MIPS-NEXT: ...
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: [[MACHINE]]
+Sections:
+ - Name: .MIPS.abiflags
+ Type: SHT_PROGBITS
+ ShType: 0x7000002a ## SHT_MIPS_ABIFLAGS.
+ Size: 0x18
diff --git a/llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml b/llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml
index b635e7161502..749914b5d8de 100644
--- a/llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml
@@ -27,7 +27,7 @@ FileHeader:
Class: ELFCLASS64
Data: ELFDATA2MSB
Type: ET_REL
- Machine: EM_MIPS
+ Machine: [[MACHINE=EM_MIPS]]
Sections:
- Name: .MIPS.abiflags
Type: SHT_MIPS_ABIFLAGS
@@ -43,3 +43,10 @@ Sections:
CPR2Size: REG_NONE
Flags1: [ ODDSPREG ]
Flags2: 0x0
+
+## Check we don't recognize the SHT_MIPS_ABIFLAGS section for non-MIPS targets.
+
+# RUN: not yaml2obj %s -DMACHINE=EM_NONE 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ERR: error: invalid hex32 number
+# ERR-NEXT: Type: SHT_MIPS_ABIFLAGS
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 75f63795cb08..c70a49363aa9 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -460,6 +460,10 @@ ELFDumper<ELFT>::dumpSections() {
auto GetDumper = [this](unsigned Type)
-> std::function<Expected<ELFYAML::Chunk *>(const Elf_Shdr *)> {
+ if (Obj.getHeader().e_machine == ELF::EM_MIPS &&
+ Type == ELF::SHT_MIPS_ABIFLAGS)
+ return [this](const Elf_Shdr *S) { return dumpMipsABIFlags(S); };
+
switch (Type) {
case ELF::SHT_DYNAMIC:
return [this](const Elf_Shdr *S) { return dumpDynamicSection(S); };
@@ -472,8 +476,6 @@ ELFDumper<ELFT>::dumpSections() {
return [this](const Elf_Shdr *S) { return dumpRelrSection(S); };
case ELF::SHT_GROUP:
return [this](const Elf_Shdr *S) { return dumpGroup(S); };
- case ELF::SHT_MIPS_ABIFLAGS:
- return [this](const Elf_Shdr *S) { return dumpMipsABIFlags(S); };
case ELF::SHT_NOBITS:
return [this](const Elf_Shdr *S) { return dumpNoBitsSection(S); };
case ELF::SHT_NOTE:
More information about the llvm-commits
mailing list