On Tue, Feb 03, 2026 at 08:57:17PM +0200, Доля Денис wrote:
> This patch removes a redundant condition in
> libgcc/config/s390/tpf-unwind.h (PR69286).

Hmm this patch does something else.  The fix for PR69286 was already
done as a byproduct in commit r10-7529-gb749b5ec58acd1.

> 
> Tested: not tested on s390/TPF (no access to hardware).

> From 98404d500ae4f36fa1ef43ec9ac61c28f1570aec Mon Sep 17 00:00:00 2001
> From: Ferki-git-creator <[email protected]>

I might be wrong here, but I think the project rules are that we rather
prefer clear names here?  (DCO certification is also missing; ChangeLog,
too)

Anyhow, my zTPF knowledge is non-existing which is why I defer this to
Andreas (CC).

Cheers,
Stefan

> Date: Tue, 3 Feb 2026 18:40:12 +0000
> Subject: [PATCH] libgcc: s390: tpf-unwind: remove redundant condition
>  (PR69286)
> 
> ---
>  libgcc/config/s390/tpf-unwind.h | 187 +++++++++++++++++---------------
>  1 file changed, 101 insertions(+), 86 deletions(-)
> 
> diff --git a/libgcc/config/s390/tpf-unwind.h b/libgcc/config/s390/tpf-unwind.h
> index 086d8a67b8c..42e0f0a498e 100644
> --- a/libgcc/config/s390/tpf-unwind.h
> +++ b/libgcc/config/s390/tpf-unwind.h
> @@ -76,9 +76,9 @@ s390_fallback_frame_state (struct _Unwind_Context *context,
>      {
>  
>        /* Our return register isn't zero for end of stack, so
> -         check backward stackpointer to see if it is zero.  */
> +      check backward stackpointer to see if it is zero.  */
>        if (regs == 0)
> -         return _URC_END_OF_STACK;
> +      return _URC_END_OF_STACK;
>  
>        /* No stack frame.  */
>        fs->regs.cfa_how = CFA_REG_OFFSET;
> @@ -94,16 +94,13 @@ s390_fallback_frame_state (struct _Unwind_Context 
> *context,
>  
>        /* ... except for %r14, which is stored at CFA+offset where offset
>        is displacment of ICST_CRET or ICST_SRET from CFA */
> -      if ( __isPATrange(context->ra) )  {
> -        fs->regs.how[14] = REG_SAVED_OFFSET;
> -        fs->regs.reg[14].loc.offset = ICST_CRET - STACK_POINTER_OFFSET;
> -        fs->retaddr_column = 14;
> -      }  else  {
> -        fs->regs.how[14] = REG_SAVED_OFFSET;
> -        fs->regs.reg[14].loc.offset = ICST_SRET - STACK_POINTER_OFFSET;
> -        fs->retaddr_column = 14;
> +      fs->regs.how[14] = REG_SAVED_OFFSET;
> +      fs->retaddr_column = 14;
>  
> -      }
> +      if (__isPATrange (context->ra))
> +        fs->regs.reg[14].loc.offset = ICST_CRET - STACK_POINTER_OFFSET;
> +      else
> +        fs->regs.reg[14].loc.offset = ICST_SRET - STACK_POINTER_OFFSET;
>  
>        return _URC_NO_REASON;
>      }
> @@ -129,37 +126,57 @@ s390_fallback_frame_state (struct _Unwind_Context 
> *context,
>        fs->regs.reg[16 + i].loc.offset = regs + 16*8 + i*8 - new_cfa;
>      }
>  
> +  fs->regs.how[20] = REG_SAVED_OFFSET;
> +  fs->regs.reg[20].loc.offset = regs + 20*8 - new_cfa;
> +
> +  for (i = 0; i < 11; i++)
> +    {
> +      fs->regs.how[21 + i] = REG_SAVED_OFFSET;
> +      fs->regs.reg[21 + i].loc.offset = regs + 21*8 + i*8 - new_cfa;
> +    }
> +
>    fs->retaddr_column = 14;
>  
>    return _URC_NO_REASON;
>  }
>  
> -/* Function Name: __tpf_eh_return
> -   Parameters passed into it: Destination address to jump to.
> -   Return Value: Converted Destination address if a Pat Stub exists.
> -   Description: This function swaps the unwinding return address
> -      with the cp stub code.  The original target return address is
> -      then stored into the tpf return address field.  The cp stub
> -      code is searched for by climbing back up the stack and
> -      comparing the tpf stored return address object address to
> -      that of the targets object address.  */
> +/* Macros needed for libgcc functions.
> +   Reason is that since we are a cross-platform macro file,
> +   we need to resolve function name references.  */
>  
> -#define CURRENT_STACK_PTR() \
> -  ({ register unsigned long int *stack_ptr asm ("%r15"); stack_ptr; })
> +#define CURRENT_STACK_PTR   __current_stack_ptr
> +#define PREVIOUS_STACK_PTR  __previous_stack_ptr
> +#define LOWCORE_PAGE3_ADDR  __lowcore_page3_addr
> +#define INVALID_RETURN      __invalid_return
> +#define R15_OFFSET          __r15_offset
> +#define RA_OFFSET           __ra_offset
> +#define TPFAREA_OFFSET      __tpfarea_offset
> +#define TPFAREA_SIZE        __tpfarea_size
> +#define PG3_SKIPPING_OFFSET __pg3_skipping_offset
>  
> +#define CURRENT_STACK_PTR() \
> +  ((unsigned long int *) (unsigned long int) 0x0000000000000f78u)
>  #define PREVIOUS_STACK_PTR() \
> -  ((unsigned long int *)(*(CURRENT_STACK_PTR())))
> -
> -#define RA_OFFSET 112
> -#define R15_OFFSET 120
> -#define TPFAREA_OFFSET 160
> -#define TPFAREA_SIZE STACK_POINTER_OFFSET-TPFAREA_OFFSET
> +  ((unsigned long int *) (unsigned long int) 0x0000000000000f70u)
> +#define LOWCORE_PAGE3_ADDR 0x0000000000001d18u
>  #define INVALID_RETURN 0
> +#define R15_OFFSET  0x58
> +#define RA_OFFSET  0x8
> +#define TPFAREA_OFFSET 0x90
> +#define TPFAREA_SIZE 224
> +#define PG3_SKIPPING_OFFSET 0x10
>  
> -#define LOWCORE_PAGE3_ADDR 4032
> -#define PG3_SKIPPING_OFFSET 18
> +extern void *__tpf_eh_return (void *target, void *origRA);
>  
> -void * __tpf_eh_return (void *target, void *origRA);
> +/* Function Name: __tpf_eh_return
> +   Parameters passed into it:  target = return address to find pat stub for
> +                           origRA = return address of exception catcher
> +   Return Value: A void * to pat stub return address, or original address
> +   Description: This function iterates through stack frames from current
> +   upwards looking for a return address that is in the same module as
> +   target.  Once found, the code will determine the exact address in
> +   order to call a pat stub and execute the desired return to the
> +   target address.  */
>  
>  void *
>  __tpf_eh_return (void *target, void *origRA)
> @@ -192,9 +209,9 @@ __tpf_eh_return (void *target, void *origRA)
>        }
>  
>        /* Begin looping through stack frames.  Stop if invalid
> -         code information is retrieved or if a match between the
> -         current stack frame iteration shared object's address
> -         matches that of the target, calculated above.  */
> +      code information is retrieved or if a match between the
> +      current stack frame iteration shared object's address
> +      matches that of the target, calculated above.  */
>        do
>          {
>         /* Get return address based on our stackptr iterator.  */
> @@ -211,53 +228,53 @@ __tpf_eh_return (void *target, void *origRA)
>             is_a_stub = true;
>           }
>  
> -          /* Get codeinfo on RA so that we can figure out
> -             the module address.  */
> -          retval = dladdr (current, &currentcodeInfo);
> -
> -          /* Check that codeinfo for current stack frame is valid.
> -             Then compare the module address of current stack frame
> -             to target stack frame to determine if we have the pat
> -             stub address we want.  Also ensure we are dealing
> -             with a module crossing, stub return address. */
> -          if (is_a_stub && retval != INVALID_RETURN
> -             && targetcodeInfo.dli_fbase == currentcodeInfo.dli_fbase)
> -             {
> -               /* Yes! They are in the same module.
> -                  Force copy of TPF private stack area to
> -                  destination stack frame TPF private area. */
> -               destination_frame = (void *) *((unsigned long int *)
> -                   (*PREVIOUS_STACK_PTR() + R15_OFFSET));
> -
> -               /* Copy TPF linkage area from current frame to
> -                  destination frame.  */
> -               memcpy((void *) (destination_frame + TPFAREA_OFFSET),
> -                 (void *) (stackptr + TPFAREA_OFFSET), TPFAREA_SIZE);
> -
> -               /* Now overlay the
> -                  real target address into the TPF stack area of
> -                  the target frame we are jumping to.  */
> +       /* Get codeinfo on RA so that we can figure out
> +          the module address.  */
> +       retval = dladdr (current, &currentcodeInfo);
> +
> +       /* Check that codeinfo for current stack frame is valid.
> +          Then compare the module address of current stack frame
> +          to target stack frame to determine if we have the pat
> +          stub address we want.  Also ensure we are dealing
> +          with a module crossing, stub return address. */
> +       if (is_a_stub && retval != INVALID_RETURN
> +          && targetcodeInfo.dli_fbase == currentcodeInfo.dli_fbase)
> +          {
> +            /* Yes! They are in the same module.
> +               Force copy of TPF private stack area to
> +               destination stack frame TPF private area. */
> +            destination_frame = (void *) *((unsigned long int *)
> +                (*PREVIOUS_STACK_PTR() + R15_OFFSET));
> +
> +            /* Copy TPF linkage area from current frame to
> +               destination frame.  */
> +            memcpy((void *) (destination_frame + TPFAREA_OFFSET),
> +              (void *) (stackptr + TPFAREA_OFFSET), TPFAREA_SIZE);
> +
> +            /* Now overlay the
> +               real target address into the TPF stack area of
> +               the target frame we are jumping to.  */
>              *(unsigned long *) (destination_frame + ICST_CRET) =
>                (unsigned long) target;
>  
> -               /* Before returning the desired pat stub address to
> -                  the exception handling unwinder so that it can
> -                  actually do the "leap" shift out the low order
> -                  bit designated to determine if we are in 64BIT mode.
> -                  This is necessary for CTOA stubs.
> -                  Otherwise we leap one byte past where we want to
> -                  go to in the TPF pat stub linkage code.  */
> -            shifter = *(unsigned long *) (stackptr + RA_OFFSET);
> -
> -               shifter &= ~1ul;
> -
> -               /* Store Pat Stub Address in destination Stack Frame.  */
> -               *((unsigned long int *) (destination_frame +
> -                   RA_OFFSET)) = shifter;
> -
> -               /* Re-adjust pat stub address to go to correct place
> -                  in linkage.  */
> -               shifter = shifter - 4;
> +            /* Before returning the desired pat stub address to
> +               the exception handling unwinder so that it can
> +               actually do the "leap" shift out the low order
> +               bit designated to determine if we are in 64BIT mode.
> +               Then set bit 1, the on return indicator. */
> +            shifter = *(unsigned long int *) (stackptr + RA_OFFSET);
> +            shifter = shifter & 0xfffffffffffffffe;
> +            shifter = shifter | 0x1;
> +
> +            /* Overlay original return address of target stack frame
> +               with new pat stub address that will execute return
> +               in our desired module.  */
> +            *((unsigned long int *) (destination_frame +
> +                RA_OFFSET)) = shifter;
> +
> +            /* Re-adjust pat stub address to go to correct place
> +               in linkage.  */
> +            shifter = shifter - 4;
>  
>              /* Reset the Function Trace Skipping Switch to re-enable */
>              /* recording Trace entries if it was turned off. */
> @@ -266,14 +283,12 @@ __tpf_eh_return (void *target, void *origRA)
>              skipFlagAddress += PG3_SKIPPING_OFFSET;
>              *skipFlagAddress = '\x00';
>  
> -               return (void *) shifter;
> -             }
> -
> -          /* Desired module pat stub not found ...
> -             Bump stack frame iterator.  */
> -          stackptr = (void *) *(unsigned long int *) stackptr;
> +            return (void *) shifter;
> +          }
>  
> -          is_a_stub = false;
> +       /* Move to next stack frame.  */
> +       stackptr = (void *) *(unsigned long *) stackptr;
> +       is_a_stub = false;
>  
>          }  while (stackptr && retval != INVALID_RETURN
>                  && targetcodeInfo.dli_fbase != currentcodeInfo.dli_fbase);
> @@ -288,4 +303,4 @@ __tpf_eh_return (void *target, void *origRA)
>    /* No pat stub found, could be a problem?  Simply return unmodified
>       target address.  */
>    return target;
> -}
> +}
> \ No newline at end of file
> -- 
> 2.51.0
> 

Reply via email to