[PATCH 1/3] ld/ELF: Move -z dynamic-undefined-weak flag handling to elf.em
hakan
hakan@envs.net
Wed Jul 16 18:59:17 GMT 2025
>> diff --git a/ld/lexsup.c b/ld/lexsup.c
>> index bde20465835..5f0c040e352 100644
>> --- a/ld/lexsup.c
>> +++ b/ld/lexsup.c
>> @@ -2267,6 +2267,9 @@ elf_shlib_list_options (FILE *file)
>> fprintf (file, _("\
>> -z nomemory-seal Don't mark oject to be memory sealed (default)\n"));
>> #endif
>> + fprintf (file, _("\
>> + -z dynamic-undefined-weak Make undefined weak symbols dynamic\n\
>> + -z nodynamic-undefined-weak Do not make undefined weak symbols dynamic\n"));
>
>Please add "(default)" to the default option.
>
Hi H.J.,
Thanks for the review.
To clarify: neither `-z dynamic-undefined-weak` nor `-z
nodynamic-undefined-weak` is the default. The default behavior is
backend-specific. Unless either flag is passed, no elflink-level
decision is made. This can be seen in `bfd/elflink.c`, function
`_bfd_elf_adjust_dynamic_symbol`:
3252 if (h->root.type == bfd_link_hash_undefweak) // this part gets changed in the following commit
3253 {
3254 if (eif->info->dynamic_undefined_weak == 0)
3255 (*bed->elf_backend_hide_symbol) (eif->info, h, true);
3256 else if (eif->info->dynamic_undefined_weak > 0
3257 && h->ref_regular
3258 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3259 && !bfd_hide_sym_by_version (eif->info->version_info,
3260 h->root.root.string))
3261 {
3262 if (!bfd_elf_link_record_dynamic_symbol (eif->info, h))
3263 {
3264 eif->failed = true;
3265 return false;
3266 }
3267 }
3268 }
The default value of `link_info.dynamic_undefined_weak` is -1, so
neither the hide path (line 3255) nor the dynamic promotion path
(lines 3256-3267) is executed.
Each backend currently implements its own undefined symbol promotion
logic (often retaining undefweaks) in `elf_<backend>_allocate_dynrelocs`.
However, that can be overriden by elflink in the above function, if flag
was passed.
Thoughts? Should we standardize on one of the two as the default,
or preserve current backend-specific behavior?
Best regards,
Hakan
More information about the Binutils
mailing list