Pass -nostdlib -nostartfiles together with -r [BZ #31753]
[glibc.git] / sysdeps / unix / sysv / linux / sh / ____longjmp_chk.S
blobf61db0bc6380c1dd57a8bec8441c862fae13f3d6
1 /* Copyright (C) 2009-2024 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <pointer_guard.h>
21 #include <sigaltstack-offsets.h>
23         .section .rodata.str1.1,"aMS",@progbits,1
24         .type   longjmp_msg,@object
25 longjmp_msg:
26         .string "longjmp causes uninitialized stack frame"
27         .size   longjmp_msg, .-longjmp_msg
28         .text
30 #define __longjmp ____longjmp_chk
32 #ifdef PIC
33 # define CALL_FAIL \
34         mov.l   .Lfail, r1;                             \
35         mov.l   .Lstr, r4;                              \
36         mov.l   r12, @-r15;                             \
37         cfi_remember_state;                             \
38         cfi_adjust_cfa_offset (4);                      \
39         cfi_rel_offset (r12, 0);                        \
40         mova    .Lgot, r0;                              \
41         mov.l   .Lgot, r12;                             \
42         add     r0, r12;                                \
43         sts.l   pr, @-r15;                              \
44         cfi_adjust_cfa_offset (4);                      \
45         cfi_rel_offset (pr, 0);                         \
46         bsrf    r1;                                     \
47          add    r12, r4;                                \
48 .Lfail0:                                                \
49         /* Unreachable.  */                             \
50         .align  2;                                      \
51 .Lgot:                                                  \
52         .long   _GLOBAL_OFFSET_TABLE_;                  \
53 .Lstr:                                                  \
54         .long   longjmp_msg@GOTOFF;                     \
55 .Lfail:                                                 \
56         .long   HIDDEN_JUMPTARGET(__fortify_fail)@PLT-(.Lfail0-.); \
57         cfi_restore_state;
58 #else
59 # define CALL_FAIL \
60         mov.l   .Lfail, r1;                             \
61         mov.l   .Lstr, r4;                              \
62         sts.l   pr, @-r15;                              \
63         cfi_remember_state;                             \
64         cfi_adjust_cfa_offset (4);                      \
65         cfi_rel_offset (pr, 0);                         \
66         jsr     @r1;                                    \
67          nop;                                           \
68         /* Unreachable.  */                             \
69         .align  2;                                      \
70 .Lstr:                                                  \
71         .long   longjmp_msg;                            \
72 .Lfail:                                                 \
73         .long   HIDDEN_JUMPTARGET(__fortify_fail);      \
74         cfi_restore_state;
75 #endif
77 #define CHECK_SP(reg) \
78         /* Jumping to a higher-address frame is always allowed.  */     \
79         cmp/hs  r15, reg;                                               \
80         bt      .Lok;                                                   \
81                                                                         \
82         mov.l   r0, @-r15; /* The return value is already in here.  */  \
83         cfi_adjust_cfa_offset (4);                                      \
84         mov.l   r1, @-r15; /* PTR_DEMANGLE helper.  */                  \
85         cfi_adjust_cfa_offset (4);                                      \
86         mov.l   r2, @-r15; /* The new SP value is already in here.  */  \
87         cfi_adjust_cfa_offset (4);                                      \
88         mov.l   r4, @-r15; /* We'll still need this one.  */            \
89         cfi_adjust_cfa_offset (4);                                      \
90         add     #-sizeSS, r15;                                          \
91         cfi_adjust_cfa_offset (sizeSS);                                 \
92         mov     #0, r4;                                                 \
93         mov     r15, r5;                                                \
94         DO_CALL (sigaltstack, 2);                                       \
95         /* Without working sigaltstack we cannot perform the test.  */  \
96         tst     r0, r0;                                                 \
97         bf      .Lok2;                                                  \
98         mov.l   @(oSS_FLAGS, r15), r0;                                  \
99         tst     #SS_ONSTACK, r0;                                        \
100         bt      .Lcall_fail;                                            \
101         mov.l   @(oSS_SIZE, r15), r2;                                   \
102         mov.l   @(oSS_SP, r15), r1;                                     \
103         add     r2, r1;                                                 \
104         sub     r8, r1;                                                 \
105         cmp/hi  r1, r2;                                                 \
106         bf      .Lok2;                                                  \
107 .Lcall_fail:                                                            \
108         CALL_FAIL                                                       \
109                                                                         \
110 .Lok2:                                                                  \
111         add     #sizeSS, r15;                                           \
112         cfi_adjust_cfa_offset (-sizeSS);                                \
113         mov.l   @r15+, r4;                                              \
114         cfi_adjust_cfa_offset (-4);                                     \
115         mov.l   @r15+, r2;                                              \
116         cfi_adjust_cfa_offset (-4);                                     \
117         mov.l   @r15+, r1;                                              \
118         cfi_adjust_cfa_offset (-4);                                     \
119         mov.l   @r15+, r0;                                              \
120         cfi_adjust_cfa_offset (-4);                                     \
121 .Lok:
123 #include <__longjmp.S>