Place a.out symbols at their image address

loadSymbols adds n_value to the start of the block the symbol belongs to, but
n_value is an address (see https://man.freebsd.org/cgi/man.cgi?a.out(5) ),
not an offset into its segment, so we need to subtract the segment's base.

In most cases `determineTextAddr` is 0, so they are the same for the .text
segment, which is why function symbols still loaded fine. But for the
.data and .bss segments they don't, so their symbol locations ended up shifted.
This commit is contained in:
Henri Chain
2026-09-16 15:43:44 +02:00
committed by Ryan Kurtz
parent ad0f0231d6
commit 0da3f75f66

View File

@@ -252,19 +252,20 @@ public class UnixAoutProgramLoader {
for (UnixAoutSymbol symbol : symtab) {
Address address = null;
long blockOffset = 0;
MemoryBlock block = null;
switch (symbol.type) {
case N_TEXT:
address = textBlock != null ? textBlock.getStart().add(symbol.value) : null;
blockOffset = symbol.value - header.getTextAddr();
block = textBlock;
break;
case N_DATA:
address = dataBlock != null ? dataBlock.getStart().add(symbol.value) : null;
blockOffset = symbol.value - header.getDataAddr();
block = dataBlock;
break;
case N_BSS:
address = bssBlock != null ? bssBlock.getStart().add(symbol.value) : null;
blockOffset = symbol.value - header.getBssAddr();
block = bssBlock;
break;
case N_UNDF:
@@ -290,10 +291,14 @@ public class UnixAoutProgramLoader {
break;
}
if (address == null || block == null) {
if (block == null) {
continue;
}
if (address == null) {
address = block.getStart().add(blockOffset);
}
switch (symbol.kind) {
case AUX_FUNC:
try {