GP-6479 improve DWARF's handling of stuff with a zeroed out address

Typically will be funcs or global vars that just have 0 for their lowpc
or the result of a expression that just hard codes DW_OP_addr 0.
This commit is contained in:
dev747368
2026-02-24 01:00:42 +00:00
parent 0dbd2a8ed3
commit 1b45dbd472
3 changed files with 18 additions and 0 deletions
@@ -366,6 +366,14 @@ public class DWARFFunction {
public boolean syncWithExistingGhidraFunction(boolean createIfMissing) {
try {
Program currentProgram = getProgram().getGhidraProgram();
if (!currentProgram.getMemory().getExecuteSet().contains(address)) {
// NOTE: if func's DIE specifies a lowpc == 0, the calculated address will be
// the program's imagebase. This typically can only be valid in .o files.
// If this binary is not a .o, and doesn't have executable segment at '0'
// (or where ever the binary was imported at), then the addr = 0 is probably
// just bad data that the toolchain put into the dwarf info.
return false; // dwarf function address info is probably bogus
}
function = currentProgram.getListing().getFunctionAt(address);
if (function != null) {
if (function.hasNoReturn() && !noReturn) {
@@ -388,6 +388,11 @@ public class DWARFFunctionImporter {
Namespace namespace = globalVar.name.getParentNamespace(currentProgram);
String name = globalVar.name.getName();
Address address = globalVar.getRamAddress();
if (prog.isZeroDataAddress(address)) {
// skip, its probably an incomplete DIE with a zero-d out location / address
// we can't create a bookmark with a warning since we don't have a good address.
return;
}
DataType dataType = globalVar.type;
SymbolTable symbolTable = currentProgram.getSymbolTable();
@@ -617,6 +617,11 @@ public class DWARFProgram implements Closeable {
.getAddress(offset + programBaseAddressFixup, true);
}
public boolean isZeroDataAddress(Address addr) {
Address realZero = getDataAddress(0);
return realZero.equals(addr);
}
public boolean stackGrowsNegative() {
return stackGrowsNegative;
}