]>
Commit | Line | Data |
---|---|---|
e75154a6 | 1 | /* Assembler macros for i386. |
d614a753 | 2 | Copyright (C) 1991-2020 Free Software Foundation, Inc. |
2c6fe0bd UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
2c6fe0bd UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
2c6fe0bd | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
e75154a6 | 18 | |
95b93c6e | 19 | #include <sysdeps/x86/sysdep.h> |
e75154a6 | 20 | |
314054ea JM |
21 | #include <features.h> /* For __GNUC_PREREQ. */ |
22 | ||
23 | /* It is desirable that the names of PIC thunks match those used by | |
d4a54ac6 JM |
24 | GCC so that multiple copies are eliminated by the linker. Because |
25 | GCC 4.6 and earlier use __i686 in the names, it is necessary to | |
26 | override that predefined macro. */ | |
27 | #if defined __i686 && defined __ASSEMBLER__ | |
28 | #undef __i686 | |
29 | #define __i686 __i686 | |
30 | #endif | |
314054ea JM |
31 | |
32 | #ifdef __ASSEMBLER__ | |
9f9f2724 | 33 | # define GET_PC_THUNK(reg) __x86.get_pc_thunk.reg |
b1da7dd9 | 34 | #else |
9f9f2724 | 35 | # define GET_PC_THUNK_STR(reg) "__x86.get_pc_thunk." #reg |
b1da7dd9 JM |
36 | #endif |
37 | ||
66715f83 | 38 | #ifdef __ASSEMBLER__ |
e75154a6 RM |
39 | |
40 | /* Syntactic details of assembler. */ | |
41 | ||
e75154a6 RM |
42 | /* If compiled for profiling, call `mcount' at the start of each function. */ |
43 | #ifdef PROF | |
44 | /* The mcount code relies on a normal frame pointer being on the stack | |
45 | to locate our caller, so push one just for its benefit. */ | |
46 | #define CALL_MCOUNT \ | |
cb8d9c93 | 47 | pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \ |
62d01985 UD |
48 | cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \ |
49 | popl %ebp; cfi_def_cfa (esp, 4); | |
e75154a6 RM |
50 | #else |
51 | #define CALL_MCOUNT /* Do nothing. */ | |
52 | #endif | |
53 | ||
e75154a6 | 54 | #define PSEUDO(name, syscall_name, args) \ |
e75154a6 | 55 | .globl syscall_error; \ |
ffa8d2a0 RM |
56 | lose: SYSCALL_PIC_SETUP \ |
57 | jmp JUMPTARGET(syscall_error); \ | |
e75154a6 RM |
58 | ENTRY (name) \ |
59 | DO_CALL (syscall_name, args); \ | |
60 | jb lose | |
61 | ||
11bf311e | 62 | # define SETUP_PIC_REG(reg) \ |
b1da7dd9 JM |
63 | .ifndef GET_PC_THUNK(reg); \ |
64 | .section .gnu.linkonce.t.GET_PC_THUNK(reg),"ax",@progbits; \ | |
65 | .globl GET_PC_THUNK(reg); \ | |
66 | .hidden GET_PC_THUNK(reg); \ | |
9a1d9254 | 67 | .p2align 4; \ |
b1da7dd9 JM |
68 | .type GET_PC_THUNK(reg),@function; \ |
69 | GET_PC_THUNK(reg): \ | |
1f708405 RM |
70 | movl (%esp), %e##reg; \ |
71 | ret; \ | |
b1da7dd9 | 72 | .size GET_PC_THUNK(reg), . - GET_PC_THUNK(reg); \ |
1f708405 RM |
73 | .previous; \ |
74 | .endif; \ | |
b1da7dd9 | 75 | call GET_PC_THUNK(reg) |
1f708405 RM |
76 | |
77 | # define LOAD_PIC_REG(reg) \ | |
78 | SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg | |
79 | ||
9a1d9254 JM |
80 | #undef JUMPTARGET |
81 | #ifdef PIC | |
82 | #define JUMPTARGET(name) name##@PLT | |
83 | #define SYSCALL_PIC_SETUP \ | |
84 | pushl %ebx; \ | |
85 | cfi_adjust_cfa_offset (4); \ | |
86 | call 0f; \ | |
87 | 0: popl %ebx; \ | |
88 | cfi_adjust_cfa_offset (-4); \ | |
1f150908 | 89 | addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ebx; |
9a1d9254 | 90 | |
e75154a6 RM |
91 | #else |
92 | #define JUMPTARGET(name) name | |
93 | #define SYSCALL_PIC_SETUP /* Nothing. */ | |
94 | #endif | |
95 | ||
d8e0ca50 JM |
96 | #else /* __ASSEMBLER__ */ |
97 | ||
98 | # define SETUP_PIC_REG_STR(reg) \ | |
99 | ".ifndef " GET_PC_THUNK_STR (reg) "\n" \ | |
100 | ".section .gnu.linkonce.t." GET_PC_THUNK_STR (reg) ",\"ax\",@progbits\n" \ | |
101 | ".globl " GET_PC_THUNK_STR (reg) "\n" \ | |
102 | ".hidden " GET_PC_THUNK_STR (reg) "\n" \ | |
103 | ".p2align 4\n" \ | |
104 | ".type " GET_PC_THUNK_STR (reg) ",@function\n" \ | |
105 | GET_PC_THUNK_STR (reg) ":" \ | |
106 | "movl (%%esp), %%e" #reg "\n" \ | |
107 | "ret\n" \ | |
108 | ".size " GET_PC_THUNK_STR (reg) ", . - " GET_PC_THUNK_STR (reg) "\n" \ | |
109 | ".previous\n" \ | |
110 | ".endif\n" \ | |
111 | "call " GET_PC_THUNK_STR (reg) | |
112 | ||
113 | # define LOAD_PIC_REG_STR(reg) \ | |
114 | SETUP_PIC_REG_STR (reg) "\naddl $_GLOBAL_OFFSET_TABLE_, %%e" #reg | |
115 | ||
66715f83 | 116 | #endif /* __ASSEMBLER__ */ |