[lld] r284376 - [ELF] - Don't crash on multiple SHT_MIPS_REGINFO/SHT_MIPS_ABIFLAGS sections.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 04:31:47 PDT 2016
Author: grimar
Date: Mon Oct 17 06:31:46 2016
New Revision: 284376
URL: http://llvm.org/viewvc/llvm-project?rev=284376&view=rev
Log:
[ELF] - Don't crash on multiple SHT_MIPS_REGINFO/SHT_MIPS_ABIFLAGS sections.
In continue of D25555, this patch fixes possible crash when
we have multiple SHT_MIPS_REGINFO or SHT_MIPS_ABIFLAGS sections.
yaml2obj was used to produce such objects.
Differential revision: https://reviews.llvm.org/D25609
Added:
lld/trunk/test/ELF/invalid/mips-multiple-abiflags.test
lld/trunk/test/ELF/invalid/mips-multiple-reginfo.test
Modified:
lld/trunk/ELF/InputFiles.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=284376&r1=284375&r2=284376&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Oct 17 06:31:46 2016
@@ -321,6 +321,9 @@ elf::ObjectFile<ELFT>::createInputSectio
// they can be used to reason about object compatibility.
return &InputSection<ELFT>::Discarded;
case SHT_MIPS_REGINFO:
+ if (MipsReginfo)
+ fatal(getFilename(this) +
+ ": multiple SHT_MIPS_REGINFO sections are not allowed");
MipsReginfo.reset(new MipsReginfoInputSection<ELFT>(this, &Sec, Name));
return MipsReginfo.get();
case SHT_MIPS_OPTIONS:
@@ -330,6 +333,9 @@ elf::ObjectFile<ELFT>::createInputSectio
MipsOptions.reset(new MipsOptionsInputSection<ELFT>(this, &Sec, Name));
return MipsOptions.get();
case SHT_MIPS_ABIFLAGS:
+ if (MipsAbiFlags)
+ fatal(getFilename(this) +
+ ": multiple SHT_MIPS_ABIFLAGS sections are not allowed");
MipsAbiFlags.reset(new MipsAbiFlagsInputSection<ELFT>(this, &Sec, Name));
return MipsAbiFlags.get();
case SHT_RELA:
Added: lld/trunk/test/ELF/invalid/mips-multiple-abiflags.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/mips-multiple-abiflags.test?rev=284376&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/mips-multiple-abiflags.test (added)
+++ lld/trunk/test/ELF/invalid/mips-multiple-abiflags.test Mon Oct 17 06:31:46 2016
@@ -0,0 +1,21 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .foo1
+ Type: SHT_MIPS_ABIFLAGS
+ ISA: MIPS64
+
+ - Name: .foo2
+ Type: SHT_MIPS_ABIFLAGS
+ ISA: MIPS64
+
+# CHECK: multiple SHT_MIPS_ABIFLAGS sections are not allowed
Added: lld/trunk/test/ELF/invalid/mips-multiple-reginfo.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/mips-multiple-reginfo.test?rev=284376&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/mips-multiple-reginfo.test (added)
+++ lld/trunk/test/ELF/invalid/mips-multiple-reginfo.test Mon Oct 17 06:31:46 2016
@@ -0,0 +1,25 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .foo1
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "000000000000000000000000000000000000000000000000"
+
+ - Name: .foo2
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "000000000000000000000000000000000000000000000000"
+
+# CHECK: multiple SHT_MIPS_REGINFO sections are not allowed
More information about the llvm-commits
mailing list