From 0da3f75f668d7413993695b4123084b797e3e252 Mon Sep 17 00:00:00 2001 From: Henri Chain Date: Wed, 16 Sep 2026 15:43:44 +0200 Subject: [PATCH] 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. --- .../app/util/opinion/UnixAoutProgramLoader.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/UnixAoutProgramLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/UnixAoutProgramLoader.java index fc7fc65c00..987b83d8db 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/UnixAoutProgramLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/UnixAoutProgramLoader.java @@ -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 {