[PATCH v2] elf: Set has_local_dynsyms for forced local symbol

Maciej W. Rozycki macro@orcam.me.uk
Fri Jan 16 00:04:02 GMT 2026


On Thu, 15 Jan 2026, H.J. Lu wrote:

> > Since there are dynamic symbols only if there are dynamic sections,
> > assert local dynamic symbol counts only if there are dynamic
> > sections.
> >
> 
> Here is the v2 patch to set has_local_dynsyms to true in
> bfd_elf_link_record_dynamic_symbol for forced local symbol
> instead.

 Thank you both for the report and the attempted fixes.  This v2 improves 
test results for the `mips-linux' target:

 		=== ld Summary ===
 
-# of expected passes		2076
+# of expected passes		2084
 # of unexpected failures	36
 # of expected failures		36
 # of known failures		1
-# of untested testcases		20
-# of unsupported tests		295
+# of untested testcases		2
+# of unsupported tests		306

(as it turns out `run_ld_link_exec_tests' insists for some reason to only 
run executables natively even if the board description file provides for 
remote execution and the completion status change between UNTESTED and 
UNSUPPORTED is easy to miss).  But also the new test fails for numerous 
bare-metal targets:

mips-elf  +FAIL: ld-mips-elf/pr33793
mips-rtems  +FAIL: ld-mips-elf/pr33793
mips64vr-elf  +FAIL: ld-mips-elf/pr33793
mips64vr4300-elf  +FAIL: ld-mips-elf/pr33793
mips64vr4300el-elf  +FAIL: ld-mips-elf/pr33793
mips64vrel-elf  +FAIL: ld-mips-elf/pr33793
mipsel-elf  +FAIL: ld-mips-elf/pr33793
mipsel-ps2-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r2-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r2el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r3-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r3el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r5-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r5el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r6-elf  +FAIL: ld-mips-elf/pr33793
mipsisa32r6el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r2-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r2el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r3-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r3el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r5-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r5el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r6-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64r6el-elf  +FAIL: ld-mips-elf/pr33793
mipsisa64sb1-elf  +FAIL: ld-mips-elf/pr33793
mipsr5900el-elf  +FAIL: ld-mips-elf/pr33793
tx39-elf  +FAIL: ld-mips-elf/pr33793

e.g.:

.../ld/ld-new: warning: cannot find entry symbol _start; defaulting to 00400018
succeeded with: <.../ld/ld-new: warning: cannot find entry symbol _start; defaulting to 00400018>, no expected output
FAIL: ld-mips-elf/pr33793

I suggest specifying the entry point explicitly in the test case.

 As to the fix itself after some experimentation this v2 appears correct 
to me.  Local dynamic symbols are explicitly permitted by the MIPS psABI:

"The dynamic symbol table, like all ELF symbol tables, is divided into 
local and global parts.  The global part of the dynamic symbol table is 
further divided into two parts: symbols that do not have GOT entries 
associated with them and symbols that do have GOT entries associated with 
them.  The part of the dynamic symbol table with GOT entries is called the 
"global offset table mapped" part or "GOT mapped" part.  Symbols with GOT 
entries have a one-to-one mapping with the global part of the GOT."

though they seem to make no sense to me as they can't ever be pre-empted 
and therefore no GOT or dynreloc entry will ever refer them.  Based on a 
small sample of binaries, mainly DSOs, I can see section symbols leaking 
occasionally to the dynsym table.  It is harmless but wasteful, so might 
be worth looking into sometime.

 In this case the state is transient anyway as the output is static and no 
dynamic structures are output after all.

 Please fix the test case as described above and otherwise this seems to 
me good to go in, although obviously I can't approve the generic change.

References:

[1] "SYSTEM V APPLICATION BINARY INTERFACE, MIPS RISC Processor
    Supplement, 3rd Edition", Chapter "Program Loading", p. 5-13

  Maciej


More information about the Binutils mailing list