mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 15:41:46 +00:00
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. llvm-svn: 336631
This commit is contained in:
parent
6e912c24d1
commit
2a3036fb1d
@ -2446,16 +2446,18 @@ GdbIndexSection::GdbIndexSection(std::vector<GdbIndexChunk> &&C)
|
||||
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 *Buf) {
|
||||
// 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;
|
||||
|
@ -688,7 +688,7 @@ class GdbIndexSection final : public SyntheticSection {
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user