[PATCH v1] LoongArch: Fix relaxation alignment with ld -r (PR 33236)
mengqinggang
mengqinggang@loongson.cn
Thu Jun 11 01:55:52 GMT 2026
Thanks for your feedback. I will make changes based on your advice.
在 2026/6/11 06:50, Alan Modra 写道:
> On Mon, Jun 08, 2026 at 02:24:01PM +0800, mengqinggang wrote:
>>> diff --git a/ld/ldlang.c b/ld/ldlang.c
>>> index 48dd33a49bb..8c3c287a3a0 100644
>>> --- a/ld/ldlang.c
>>> +++ b/ld/ldlang.c
>>> @@ -5769,6 +5769,10 @@ size_input_section
>>> {
>>> bfd_size_type alignment_needed;
>>> + bool synthesize_align = bfd_link_relocatable (&link_info)
>>> + && (i->flags & SEC_CODE) != 0
>>> + && bfd_get_arch (i->owner) == bfd_arch_loongarch;
>>> +
>>> /* Align this section first to the input sections requirement,
>>> then to the output section's requirement. If this alignment
>>> is greater than any seen before, then record it too. Perform
>>> @@ -5788,7 +5792,9 @@ size_input_section
>>> alignment_needed = align_power (dot, i->alignment_power) - dot;
>>> - if (alignment_needed != 0)
>>> + /* If synthesized ALIGN may be needed, add one align section
>>> + and one align relocation and disable the default handling. */
>>> + if (alignment_needed != 0 && ! synthesize_align)
>>> {
>>> insert_pad (this_ptr, fill, TO_SIZE (alignment_needed), o, dot);
>>> dot += alignment_needed;
> Architecture specific code isn't supposed to be in ldlang.c. Yes, I
> know there is a bfd_arch_tic54x test in there. I don't like that one
> either.
>
> I haven't looked too deeply into what your patch does, but I think you
> should be able to stop ldlang.c:size_input_section padding by changing
> the input section alignment_power in add_align_section (and tweak
> loongarch_add_align_relocs to not use the sec->alignment_power but
> instead align_sec->size).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20260611/103bf933/attachment.htm>
More information about the Binutils
mailing list