[PATCH v2 7/7] Fix the calculation of the function length
Evgeny Karpov
Evgeny.Karpov@microsoft.com
Sun Jul 27 17:41:15 GMT 2025
Thu Jul 24 2025
Richard Earnshaw (lists) <Richard.Earnshaw@arm.com> wrote:
>> diff --git a/gas/config/obj-coff-seh.c b/gas/config/obj-coff-seh.c
>> index 75b45b8d4dd..b05153bfe81 100644
>> --- a/gas/config/obj-coff-seh.c
>> +++ b/gas/config/obj-coff-seh.c
>> @@ -559,6 +559,24 @@ do_seh_endproc (void)
>> {
>> seh_ctx_cur->end_addr = symbol_temp_new_now ();
>>
>> +#if defined (COFFAARCH64)
>> +/* Fragment alignment should be handled before writing unwinding
>> + information to the .pdata/.xdata sections. This is required to
>> + accurately calculate the function size, which is used to split
>> + the function into multiple fragments if it is too large. */
>> +
>> + struct frag * current_frag = frchain_now->frch_root;
>> + while(current_frag)
>> + {
>> + if (current_frag->fr_type == rs_align_code)
>> + {
>> + HANDLE_ALIGN (now_seg, current_frag);
>> + current_frag->fr_type = rs_fill;
>> + }
>> + current_frag = current_frag->fr_next;
>> + }
>> +#endif
>> +
>
> This still feels like it might be a bit early, though I don't know the SEH
> (or coff for that matter) code well enough to be sure. The normal way of
> handling this inside, say, the .text section is to emit an internal
> relocation. These will then get processed and eliminated later on to
> leave the data. The only time that might get tricky is if the size of the
> relocated element itself can change (eg with encodings like LEB128.
>
> Perhaps Jan can comment here.
Thu Jul 24 2025
Jan Beulich <jbeulich@suse.com> wrote:
> Sadly I don't know the SEH code at all (yet). For LEB128 we have rs_leb128,
> if that's indeed needed here. There are some rough edges with relax_segment()
> there though, leading to the "Infinite loop encountered ..." fatal error
> there in certain cases.
Following this feedback, the patch series has been refactored, and emitting
records to .pdata/.xdata has been changed for the AArch64 implementation. Now it
happens in the md_finish hook, after all assembly has been completed.
It also uses obj_coff_generate_pdata, which is originally used in
write_object_file. Before the change, obj_coff_generate_pdata was used
only to validate syntax, which was fine for that purpose. However, that
location seems incorrect, as it is too late to emit .pdata/.xdata records
in the AArch64 case. Refactoring other targets in a similar way makes sense,
but it deserves a separate patch series and proper validation. The change will be
included in v3.
Regards,
Evgeny
More information about the Binutils
mailing list