[lld] 5e643cd - [ELF] --gdb-index: error if constant pool size exceeds UINT32_MAX

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 31 21:10:10 PDT 2022


Author: Fangrui Song
Date: 2022-08-31T21:10:01-07:00
New Revision: 5e643cd7b79278073177d237ebadb34f1219965d

URL: https://github.com/llvm/llvm-project/commit/5e643cd7b79278073177d237ebadb34f1219965d
DIFF: https://github.com/llvm/llvm-project/commit/5e643cd7b79278073177d237ebadb34f1219965d.diff

LOG: [ELF] --gdb-index: error if constant pool size exceeds UINT32_MAX

If so, the last symbol's name_offset likely exceeds 0xffffffff and is not
supported by the format
(https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html#Index-Section-Format).
I have seen an internal oversized executable with such a corrupted .gdb_index

Added: 
    

Modified: 
    lld/ELF/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index eb9272e41fd8..f4093524772a 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2844,6 +2844,10 @@ createSymbols(
     sym.nameOff = off;
     off += sym.name.size() + 1;
   }
+  // If off overflows, the last symbol's nameOff likely overflows.
+  if (!isUInt<32>(off))
+    errorOrWarn("--gdb-index: constant pool size (" + Twine(off) +
+                ") exceeds UINT32_MAX");
 
   return {ret, off};
 }


        


More information about the llvm-commits mailing list