[lld] r229441 - [Mips] Show error if MIPS_REGINFO section has invalid size

Simon Atanasyan simon at atanasyan.com
Mon Feb 16 13:52:35 PST 2015


Author: atanasyan
Date: Mon Feb 16 15:52:35 2015
New Revision: 229441

URL: http://llvm.org/viewvc/llvm-project?rev=229441&view=rev
Log:
[Mips] Show error if MIPS_REGINFO section has invalid size

Added:
    lld/trunk/test/elf/Mips/invalid-reginfo.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=229441&r1=229440&r2=229441&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Mon Feb 16 15:52:35 2015
@@ -158,10 +158,10 @@ private:
         return ec;
 
       ArrayRef<uint8_t> raw = contents.get();
+      if (raw.size() != sizeof(Elf_RegInfo))
+        return make_dynamic_error_code(
+            StringRef("Invalid size of MIPS_REGINFO section"));
 
-      // FIXME (simon): Show error in case of invalid section size.
-      assert(raw.size() == sizeof(Elf_RegInfo) &&
-             "Invalid size of RegInfo section");
       _gp0 = reinterpret_cast<const Elf_RegInfo *>(raw.data())->ri_gp_value;
     }
     return std::error_code();

Added: lld/trunk/test/elf/Mips/invalid-reginfo.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/invalid-reginfo.test?rev=229441&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/invalid-reginfo.test (added)
+++ lld/trunk/test/elf/Mips/invalid-reginfo.test Mon Feb 16 15:52:35 2015
@@ -0,0 +1,28 @@
+# Check that LLD shows an error if .reginfo section has invalid size
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -o %t.exe %t.o 2>&1 | FileCheck %s
+
+# CHECK: Invalid size of MIPS_REGINFO section
+
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_MIPS
+  Flags:           [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  0x04
+    Size:          0x04
+  - Name:          .reginfo
+    Type:          SHT_MIPS_REGINFO
+    Flags:         [ SHF_ALLOC ]
+    AddressAlign:  0x01
+    Size:          0x25
+Symbols:
+  Global:
+    - Name:        main
+      Section:     .text





More information about the llvm-commits mailing list