[PATCH 1/3] ld/ELF: Move -z dynamic-undefined-weak flag handling to elf.em
Hakan Candar
hakan@envs.net
Sun Aug 31 10:35:14 GMT 2025
Jan Beulich <jbeulich@suse.com> wrote:
>On 16.07.2025 18:03, Hakan Candar wrote:
>> The -z [no]dynamic-undefined-weak flag was previously handled through
>> emulparams scripts, only wired into select backends like x86 and PPC.
>>
>> This patch moves its handling into elf.em so that it applies uniformly
>> across all ELF backends, removing the need for per-target boilerplate.
>>
>> This change does not alter behavior for targets that already used the
>> flag, but enables proper support on targets that previously ignored or
>> warned on it (e.g., AArch64, RISC-V, MIPS).
>>
>> ld/
>> * emultempl/elf.em: Add -z dynamic-undefined-weak flag handling.
>> * emulparams/dynamic_undefined_weak.sh: Delete.
>> * emulparams/elf32_x86_64.sh: Remove source line.
>> * emulparams/elf32ppccommon.sh: Likewise.
>> * emulparams/elf_i386.sh: Likewise.
>> * emulparams/elf_i386_be.sh: Likewise.
>> * emulparams/elf_i386_ldso.sh: Likewise.
>> * emulparams/elf_i386_vxworks.sh: Likewise.
>> * emulparams/elf_iamcu.sh: Likewise.
>> * emulparams/elf_x86_64.sh: Likewise.
>> * ld.texi: Clarify that '-z dynamic-undefined-weak' is now accepted
>> for all ELF targets, though some backends may not fully support it.
>> * lexsup.c (elf_shlib_list_options): Document '-z dynamic-undefined-weak'
>> and '-z nodynamic-undefined-weak' options in help output.
>> * NEWS: Mention the new, centralized behaviour.
>>
>> ld/testsuite/
>> * ld-undefined/weak-undef.exp: Enable validation of
>> undefined symbol retention for AArch64, RISC-V, and MIPS by
>> setting appropriate assembler flags.
>
>How are these testsuite changes related to the purpose of the patch?
>
Since the option handling was moved into the ELF emulation layer, it now
applies uniformly across all ELF backends. Enabling the tests on
AArch64, RISC-V, and MIPS ensures we actually exercise the new common
code path. Previously those backends ignored or warned on the flag, so
the test cases had no effect there. This makes the coverage consistent
with x86 and PPC, which already validated the behavior.
>> --- a/ld/NEWS
>> +++ b/ld/NEWS
>> @@ -2,6 +2,13 @@
>>
>> Changes in 2.45:
>>
>> +* The -z [no]dynamic-undefined-weak option is now handled centrally in the
>> + ELF emulation code and is accepted on all ELF targets. This removes the
>> + need for per-target wiring.
>> +
>> + Some backends may not yet fully respect this centralized
>> + logic due to backend-specific conditionals.
>> +
>> * On s390 64-bit (s390x), generate SFrame stack trace information (.sframe)
>> for the linker generated .plt section. Enabled by default. Can be disabled
>> using linker option --no-ld-generated-unwind-info.
>
>This needs to move out of the 2.45 section.
>
Noted.
>> --- a/ld/emultempl/elf.em
>> +++ b/ld/emultempl/elf.em
>> @@ -1115,6 +1115,13 @@ fragment <<EOF
>> link_info.textrel_check = textrel_check_none;
>> EOF
>>
>> +fragment <<EOF
>> + else if (strcmp (optarg, "dynamic-undefined-weak") == 0)
>> + link_info.dynamic_undefined_weak = true;
>> + else if (strcmp (optarg, "nodynamic-undefined-weak") == 0)
>> + link_info.dynamic_undefined_weak = false;
>> +EOF
>
>Make part of the previous "fragment" invocation?
>
Noted.
>Jan
Regards,
Hakan
More information about the Binutils
mailing list