[PATCH v4 4/7] Add aarch64-specific SEH commands

Jan Beulich jbeulich@suse.com
Fri Oct 10 14:11:18 GMT 2025


On 15.08.2025 00:49, Evgeny Karpov wrote:
> --- a/gas/config/obj-coff-seh.c
> +++ b/gas/config/obj-coff-seh.c
> @@ -726,6 +726,105 @@ obj_coff_seh_endprologue (int what ATTRIBUTE_UNUSED)
>  #endif
>  }
> 
> +#if defined (COFFAARCH64)
> +static void
> +obj_coff_seh_startepilogue (int what ATTRIBUTE_UNUSED)
> +{
> +  symbolS *epilogue_start_addr;
> +  expressionS exp;
> +
> +  if (!verify_context (".seh_startepilogue")
> +      || !seh_validate_seg (".seh_startepilogue"))
> +    return;
> +  demand_empty_rest_of_line ();
> +
> +  const unsigned max_epilogue_scopes = AARCH64_MAX_EPILOGUE_SCOPES;
> +  if (seh_ctx_cur->aarch64_ctx.epilogue_scopes_count >= max_epilogue_scopes)
> +    {
> +      as_bad (_("no epilogue scopes available."));

See nit on earlier patch.

> +      return;
> +    }
> +
> +  epilogue_start_addr = symbol_temp_new_now ();
> +  exp.X_op = O_subtract;
> +  exp.X_add_symbol = epilogue_start_addr;
> +  exp.X_op_symbol = seh_ctx_cur->start_addr;
> +  exp.X_add_number = 0;
> +
> +  if (!resolve_expression (&exp) || exp.X_op != O_constant
> +      || exp.X_add_number < 0)
> +    as_bad (_(".seh_startepilog offset expression for %s "
> +	    "does not evaluate to a non-negative constant"),

This line's indentation looks wrong (off by 2), while ...

> +	    S_GET_NAME (epilogue_start_addr));

... things look good here. Question of course is if the wording can't be
a little more terse anyway, at which point things may fit on a single line.

> +
> +  if (seh_ctx_cur->aarch64_ctx.epilogue_scopes_count
> +      >= seh_ctx_cur->aarch64_ctx.epilogue_scopes_capacity)
> +    {
> +      const unsigned initial_capacity = 32;
> +      if (seh_ctx_cur->aarch64_ctx.epilogue_scopes_capacity)
> +	seh_ctx_cur->aarch64_ctx.epilogue_scopes_capacity *= 2;
> +      else
> +	seh_ctx_cur->aarch64_ctx.epilogue_scopes_capacity = initial_capacity;
> +
> +      seh_ctx_cur->aarch64_ctx.epilogue_scopes
> +	= XRESIZEVEC (seh_aarch64_epilogue_scope,
> +		     seh_ctx_cur->aarch64_ctx.epilogue_scopes,
> +		     seh_ctx_cur->aarch64_ctx.epilogue_scopes_capacity);
> +    }
> +
> +  seh_aarch64_epilogue_scope *epilogue_scope;
> +  epilogue_scope = seh_ctx_cur->aarch64_ctx.epilogue_scopes
> +    + seh_ctx_cur->aarch64_ctx.epilogue_scopes_count;
> +  epilogue_scope->epilogue_start_offset = exp.X_add_number / 4;
> +  epilogue_scope->reserved = 0;
> +  epilogue_scope->epilogue_start_index
> +    = seh_ctx_cur->aarch64_ctx.unwind_codes_byte_count;
> +  seh_ctx_cur->aarch64_ctx.epilogue_scopes_count++;
> +}
> +
> +static void
> +obj_coff_seh_endepilogue (int what ATTRIBUTE_UNUSED)
> +{
> +  if (!verify_context (".seh_endepilogue")
> +      || !seh_validate_seg (".seh_endepilogue"))
> +    return;
> +
> +  demand_empty_rest_of_line ();
> +
> +  expressionS exp;
> +  symbolS *epilogue_end_addr = symbol_temp_new_now ();
> +  exp.X_op = O_subtract;
> +  exp.X_add_symbol = epilogue_end_addr;
> +  exp.X_op_symbol = seh_ctx_cur->start_addr;
> +  exp.X_add_number = 0;
> +
> +  if (!resolve_expression (&exp) || exp.X_op != O_constant
> +      || exp.X_add_number < 0)
> +    as_bad (_(".seh_endepilogue offset expression for %s "
> +	    "does not evaluate to a non-negative constant"),
> +	    S_GET_NAME (epilogue_end_addr));
> +
> +   seh_aarch64_epilogue_scope *epilogue_scope;
> +   epilogue_scope = seh_ctx_cur->aarch64_ctx.epilogue_scopes
> +     + seh_ctx_cur->aarch64_ctx.epilogue_scopes_count - 1;
> +
> +   epilogue_scope->epilogue_end_offset = exp.X_add_number;
> +
> +  /* End code.  */
> +  seh_aarch64_add_unwind_element (end, 0, 0);
> +}
> +
> +static void
> +obj_coff_seh_endfunclet (int what ATTRIBUTE_UNUSED)
> +{
> +  if (!verify_context (".seh_endfunclet")
> +      || !seh_validate_seg (".seh_endfunclet"))
> +    return;
> +
> +  demand_empty_rest_of_line ();
> +}
> +#endif
> +
>  /* End-of-file hook.  */
> 
>  void
> @@ -927,6 +1026,58 @@ obj_coff_seh_save (int what)
>  }
>  #endif
> 
> +#if defined (COFFAARCH64)

Do we really need a 2nd #if here?

Jan


More information about the Binutils mailing list