[lld] r259951 - ELF: Simplify readEntryLength.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 5 15:24:06 PST 2016


Author: ruiu
Date: Fri Feb  5 17:24:05 2016
New Revision: 259951

URL: http://llvm.org/viewvc/llvm-project?rev=259951&view=rev
Log:
ELF: Simplify readEntryLength.

I removed "CIE/FIE size is too large" error because that was not
checking for correct error conditions. [UINT_MAX - 4, UINT_MAX) is
a correct range as a size of a CIE/FDE record. It's just that the
size cannot be larger than the section size.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/test/ELF/invalid-cie-length.s
    lld/trunk/test/ELF/invalid-cie-length3.s
    lld/trunk/test/ELF/invalid-cie-length4.s
    lld/trunk/test/ELF/invalid-cie-length5.s

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=259951&r1=259950&r2=259951&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Feb  5 17:24:05 2016
@@ -966,26 +966,26 @@ uint8_t EHOutputSection<ELFT>::getFdeEnc
 template <class ELFT>
 static typename ELFFile<ELFT>::uintX_t readEntryLength(ArrayRef<uint8_t> D) {
   const endianness E = ELFT::TargetEndianness;
-
   if (D.size() < 4)
-    fatal("Truncated CIE/FDE length");
-  uint64_t Len = read32<E>(D.data());
-  if (Len < UINT32_MAX) {
-    if (Len > (UINT32_MAX - 4))
-      fatal("CIE/FIE size is too large");
-    if (Len + 4 > D.size())
+    fatal("CIE/FDE too small");
+
+  // First 4 bytes of CIE/FDE is the size of the record.
+  // If it is 0xFFFFFFFF, the next 8 bytes contain the size instead.
+  uint64_t V = read32<E>(D.data());
+  if (V < UINT32_MAX) {
+    uint64_t Len = V + 4;
+    if (Len > D.size())
       fatal("CIE/FIE ends past the end of the section");
-    return Len + 4;
+    return Len;
   }
 
   if (D.size() < 12)
-    fatal("Truncated CIE/FDE length");
-  Len = read64<E>(D.data() + 4);
-  if (Len > (UINT64_MAX - 12))
-    fatal("CIE/FIE size is too large");
-  if (Len + 12 > D.size())
+    fatal("CIE/FDE too small");
+  V = read64<E>(D.data() + 4);
+  uint64_t Len = V + 12;
+  if (Len < V || D.size() < Len)
     fatal("CIE/FIE ends past the end of the section");
-  return Len + 12;
+  return Len;
 }
 
 template <class ELFT>

Modified: lld/trunk/test/ELF/invalid-cie-length.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-cie-length.s?rev=259951&r1=259950&r2=259951&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid-cie-length.s (original)
+++ lld/trunk/test/ELF/invalid-cie-length.s Fri Feb  5 17:24:05 2016
@@ -6,4 +6,4 @@
         .section .eh_frame
         .byte 0
 
-// CHECK: Truncated CIE/FDE length
+// CHECK: CIE/FDE too small

Modified: lld/trunk/test/ELF/invalid-cie-length3.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-cie-length3.s?rev=259951&r1=259950&r2=259951&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid-cie-length3.s (original)
+++ lld/trunk/test/ELF/invalid-cie-length3.s Fri Feb  5 17:24:05 2016
@@ -6,4 +6,4 @@
  .section .eh_frame
  .long 0xFFFFFFFC
 
-// CHECK: CIE/FIE size is too large
+// CHECK: CIE/FIE ends past the end of the section

Modified: lld/trunk/test/ELF/invalid-cie-length4.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-cie-length4.s?rev=259951&r1=259950&r2=259951&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid-cie-length4.s (original)
+++ lld/trunk/test/ELF/invalid-cie-length4.s Fri Feb  5 17:24:05 2016
@@ -7,4 +7,4 @@
  .long 0xFFFFFFFF
  .byte 0
 
-// CHECK: Truncated CIE/FDE length
+// CHECK: CIE/FDE too small

Modified: lld/trunk/test/ELF/invalid-cie-length5.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-cie-length5.s?rev=259951&r1=259950&r2=259951&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid-cie-length5.s (original)
+++ lld/trunk/test/ELF/invalid-cie-length5.s Fri Feb  5 17:24:05 2016
@@ -7,4 +7,4 @@
  .long 0xFFFFFFFF
  .quad 0xFFFFFFFFFFFFFFF4
 
-// CHECK: CIE/FIE size is too large
+// CHECK: CIE/FIE ends past the end of the section




More information about the llvm-commits mailing list