Headless -noanalysis: decompiler resolves call names via ELF relocations, but ReferenceManager has no references for them
Ghidra version: 12.0.4 (also observed to be relevant on similarly-recent headless builds) OS: Linux (x86_64)
Description
When a relocatable ELF object file (e.g. an unstripped Linux kernel module .ko, x86-64) is imported into headless Ghidra with -noanalysis, DecompInterface.decompileFunction() on a named function succeeds and correctly resolves the names of functions it calls elsewhere in the same file — presumably via the ELF relocation entries / symbol table the loader already parsed at import time.
However, ReferenceManager.getReferencesTo() for those same call targets returns no results at all, even for calls that the decompiler output just showed by name a moment earlier, and even when queried from a fresh -process invocation against the saved project (i.e. not a stale-cache issue).
This is a confusing combination for headless scripting: it's easy to conclude a program is "sufficiently analyzed" because decompilation looks complete and correctly annotated, while a script relying on getReferencesTo()/getReferencesFrom() (e.g. a simple "find callers of X" script) silently returns nothing, with no warning that references were never actually computed/stored.
Steps to reproduce
analyzeHeadless <proj_dir> <proj_name> -import some_module.ko -noanalysis -scriptPath . -postScript decompile_one.java funcAdecompile_one.javausesDecompInterfaceto decompilefuncA, which (per the disassembly) callsfuncBdirectly (call funcB, resolved via an ELF relocation/local symbol, not a PLT/GOT indirection). The decompiler output correctly showsfuncB(...)by name.
- In the same script (or a follow-up
-processrun against the saved project, no re-import), call:for (Reference r : currentProgram.getReferenceManager().getReferencesTo(funcBSymbol.getAddress())) { println("caller: " + r.getFromAddress()); } - Observed: zero references printed, despite
funcA's decompiled body clearly showing the call tofuncB. - Re-running the same
-importwithout-noanalysis(full auto-analysis) and repeating step 2 correctly listsfuncAas a caller offuncB.
Expected behavior (or at least, expected documentation)
Either:
-noanalysisimports should not leave the decompiler able to resolve call names whileReferenceManagerremains completely empty for those same calls (i.e. either both should reflect the "unanalyzed" state, or references for statically-resolvable direct calls from relocations should be recorded at import time), or- if this is intentional (references are only ever populated by an explicit analysis pass, regardless of what the loader/decompiler can resolve on their own), it would help headless-scripting users a lot to have this called out explicitly in the
-noanalysisflag's help text / the Headless Analyzer documentation, since the failure mode is a silent empty result set rather than an error.
Happy to attach a minimal synthetic .ko/.o reproducer if useful — the one I hit this on is a proprietary third-party kernel module I can't share, but the behavior reproduced identically on a from-scratch -import of the same file, so it isn't specific to that binary.
Source: NationalSecurityAgency/ghidra