Skip to content
Snippets Groups Projects
Commit 9db62b28 authored by Alessandro Di Federico's avatar Alessandro Di Federico
Browse files

Handle `.bss`-only data segment

This commit fixes an assertion triggered by the fact that a segment
includes exclusively zero-initialized data (i.e., size on file is 0,
memory size is not). In this case LLVM detects the fact that the global
variable associated to the segment is composed exclusively composed by
0s and uses a `ConstantAggregateZero` as an initializer instead of a
`ConstantDataArray`.

Currently the solution is ignore that data, however, in the future it
might be beneficial to be able to read data from `.bss`, even if we just
have zeros there.

Thanks to Thorbjoern Schulz for reporting this bug.
parent 4c868901
No related branches found
No related tags found
No related merge requests found
......@@ -328,6 +328,12 @@ JumpTargetManager::readRawValue(uint64_t Address,
// Note: we also consider writeable memory areas because, despite being
// modifiable, can contain useful information
if (Segment.contains(Address, Size) && Segment.IsReadable) {
// TODO: we ignore .bss here, it might be beneficial to take it into
// account in certain situations
const Constant *Initializer = Segment.Variable->getInitializer();
if (isa<ConstantAggregateZero>(Initializer))
continue;
auto *Array = cast<ConstantDataArray>(Segment.Variable->getInitializer());
StringRef RawData = Array->getRawDataValues();
const unsigned char *RawDataPtr = RawData.bytes_begin();
......@@ -501,7 +507,11 @@ void JumpTargetManager::harvestGlobalData() {
registerJT(LandingPad, GlobalData);
for (auto& Segment : Binary.segments()) {
auto *Data = cast<ConstantDataArray>(Segment.Variable->getInitializer());
const Constant *Initializer = Segment.Variable->getInitializer();
if (isa<ConstantAggregateZero>(Initializer))
continue;
auto *Data = cast<ConstantDataArray>(Initializer);
uint64_t StartVirtualAddress = Segment.StartVirtualAddress;
const unsigned char *DataStart = Data->getRawDataValues().bytes_begin();
const unsigned char *DataEnd = Data->getRawDataValues().bytes_end();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment