[lld] r336631 - Report an error for an extremely large .gdb_index section.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 9 18:22:25 PDT 2018
Author: ruiu
Date: Mon Jul 9 18:22:25 2018
New Revision: 336631
URL: http://llvm.org/viewvc/llvm-project?rev=336631&view=rev
Log:
Report an error for an extremely large .gdb_index section.
I believe the only way to test this functionality is to create extremely
large object files and attempt to create a .gdb_index that is greater
than 4 GiB. But I think that's too much for most environments and buildbots,
so I'm commiting this without a test that actually triggers the new
error condition.
Modified:
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=336631&r1=336630&r2=336631&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Jul 9 18:22:25 2018
@@ -2446,16 +2446,18 @@ GdbIndexSection::GdbIndexSection(std::ve
SymtabOffset = CuTypesOffset + getAddressAreaSize(Chunks) * 20;
ConstantPoolOffset = SymtabOffset + GdbSymtab.size() * 8;
- size_t Off = 0;
for (ArrayRef<uint32_t> Vec : CuVectors) {
- CuVectorOffsets.push_back(Off);
- Off += (Vec.size() + 1) * 4;
+ CuVectorOffsets.push_back(CuVectorsPoolSize);
+ CuVectorsPoolSize += (Vec.size() + 1) * 4;
}
- StringPoolOffset = ConstantPoolOffset + Off;
-}
-size_t GdbIndexSection::getSize() const {
- return StringPoolOffset + StringPoolSize;
+ uint64_t PoolSize = CuVectorsPoolSize + StringPoolSize;
+ TotalSize = ConstantPoolOffset + PoolSize;
+
+ // Length fields in the .gdb_index section are only 4 byte long,
+ // so the section cannot contain very large contents.
+ if (ConstantPoolOffset > UINT32_MAX || PoolSize > UINT32_MAX)
+ error(".gdb_index section too large");
}
void GdbIndexSection::writeTo(uint8_t *Buf) {
@@ -2491,7 +2493,7 @@ void GdbIndexSection::writeTo(uint8_t *B
// Write the symbol table.
for (GdbSymbol *Sym : GdbSymtab) {
if (Sym) {
- write32le(Buf, Sym->NameOffset + StringPoolOffset - ConstantPoolOffset);
+ write32le(Buf, CuVectorsPoolSize + Sym->NameOffset);
write32le(Buf + 4, CuVectorOffsets[Sym->CuVectorIndex]);
}
Buf += 8;
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=336631&r1=336630&r2=336631&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Mon Jul 9 18:22:25 2018
@@ -688,7 +688,7 @@ class GdbIndexSection final : public Syn
public:
GdbIndexSection(std::vector<GdbIndexChunk> &&Chunks);
void writeTo(uint8_t *Buf) override;
- size_t getSize() const override;
+ size_t getSize() const override { return TotalSize; }
bool empty() const override;
private:
@@ -709,12 +709,13 @@ private:
// object and used to build different areas of gdb index.
std::vector<GdbIndexChunk> Chunks;
- static constexpr uint32_t CuListOffset = 24;
- uint32_t CuTypesOffset;
- uint32_t SymtabOffset;
- uint32_t ConstantPoolOffset;
- uint32_t StringPoolOffset;
- uint32_t StringPoolSize;
+ uint64_t CuListOffset = 24;
+ uint64_t CuTypesOffset;
+ uint64_t SymtabOffset;
+ uint64_t ConstantPoolOffset;
+ uint64_t CuVectorsPoolSize = 0;
+ uint64_t StringPoolSize;
+ uint64_t TotalSize;
std::vector<size_t> CuVectorOffsets;
};
More information about the llvm-commits
mailing list