alpha: Don't symbol_version syscalls outside libc
[glibc.git] / sysdeps / i386 / sysdep.h
blobba00d65c51ac9d6fa5d35e63dd72a71c11ffad50
1 /* Assembler macros for i386.
2 Copyright (C) 1991-93,95,96,98,2002,2003,2005,2006,2011,2012
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <sysdeps/generic/sysdep.h>
22 #include <features.h> /* For __GNUC_PREREQ. */
24 /* It is desirable that the names of PIC thunks match those used by
25 GCC so that multiple copies are eliminated by the linker. Because
26 GCC 4.6 and earlier use __i686 in the names, it is necessary to
27 override that predefined macro. */
28 #if defined __i686 && defined __ASSEMBLER__
29 #undef __i686
30 #define __i686 __i686
31 #endif
33 #ifdef __ASSEMBLER__
34 # if __GNUC_PREREQ (4, 7)
35 # define GET_PC_THUNK(reg) __x86.get_pc_thunk.reg
36 # else
37 # define GET_PC_THUNK(reg) __i686.get_pc_thunk.reg
38 # endif
39 #else
40 # if __GNUC_PREREQ (4, 7)
41 # define GET_PC_THUNK_STR(reg) "__x86.get_pc_thunk." #reg
42 # else
43 # define GET_PC_THUNK_STR(reg) "__i686.get_pc_thunk." #reg
44 # endif
45 #endif
47 #ifdef __ASSEMBLER__
49 /* Syntactic details of assembler. */
51 /* ELF uses byte-counts for .align, most others use log2 of count of bytes. */
52 #define ALIGNARG(log2) 1<<log2
53 /* For ELF we need the `.type' directive to make shared libs work right. */
54 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
55 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
58 /* Define an entry point visible from C.
60 There is currently a bug in gdb which prevents us from specifying
61 incomplete stabs information. Fake some entries here which specify
62 the current source file. */
63 #define ENTRY(name) \
64 STABS_CURRENT_FILE1("") \
65 STABS_CURRENT_FILE(name) \
66 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
67 ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
68 .align ALIGNARG(4); \
69 STABS_FUN(name) \
70 C_LABEL(name) \
71 cfi_startproc; \
72 CALL_MCOUNT
74 #undef END
75 #define END(name) \
76 cfi_endproc; \
77 ASM_SIZE_DIRECTIVE(name) \
78 STABS_FUN_END(name)
80 #define ENTRY_CHK(name) ENTRY (name)
81 #define END_CHK(name) END (name)
83 #ifdef HAVE_CPP_ASM_DEBUGINFO
84 /* Disable that goop, because we just pass -g through to the assembler
85 and it generates proper line number information directly. */
86 # define STABS_CURRENT_FILE1(name)
87 # define STABS_CURRENT_FILE(name)
88 # define STABS_FUN(name)
89 # define STABS_FUN_END(name)
90 #else
91 /* Remove the following two lines once the gdb bug is fixed. */
92 #define STABS_CURRENT_FILE(name) \
93 STABS_CURRENT_FILE1 (#name)
94 #define STABS_CURRENT_FILE1(name) \
95 1: .stabs name,100,0,0,1b;
96 /* Emit stabs definition lines. We use F(0,1) and define t(0,1) as `int',
97 the same way gcc does it. */
98 #define STABS_FUN(name) STABS_FUN2(name, name##:F(0,1))
99 #define STABS_FUN2(name, namestr) \
100 .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0; \
101 .stabs #namestr,36,0,0,name;
102 #define STABS_FUN_END(name) \
103 1: .stabs "",36,0,0,1b-name;
104 #endif
106 /* If compiled for profiling, call `mcount' at the start of each function. */
107 #ifdef PROF
108 /* The mcount code relies on a normal frame pointer being on the stack
109 to locate our caller, so push one just for its benefit. */
110 #define CALL_MCOUNT \
111 pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \
112 cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \
113 popl %ebp; cfi_def_cfa (esp, 4);
114 #else
115 #define CALL_MCOUNT /* Do nothing. */
116 #endif
118 /* Since C identifiers are not normally prefixed with an underscore
119 on this system, the asm identifier `syscall_error' intrudes on the
120 C name space. Make sure we use an innocuous name. */
121 #define syscall_error __syscall_error
122 #define mcount _mcount
124 #define PSEUDO(name, syscall_name, args) \
125 .globl syscall_error; \
126 lose: SYSCALL_PIC_SETUP \
127 jmp JUMPTARGET(syscall_error); \
128 ENTRY (name) \
129 DO_CALL (syscall_name, args); \
130 jb lose
132 #undef PSEUDO_END
133 #define PSEUDO_END(name) \
134 END (name)
136 # define SETUP_PIC_REG(reg) \
137 .ifndef GET_PC_THUNK(reg); \
138 .section .gnu.linkonce.t.GET_PC_THUNK(reg),"ax",@progbits; \
139 .globl GET_PC_THUNK(reg); \
140 .hidden GET_PC_THUNK(reg); \
141 .p2align 4; \
142 .type GET_PC_THUNK(reg),@function; \
143 GET_PC_THUNK(reg): \
144 movl (%esp), %e##reg; \
145 ret; \
146 .size GET_PC_THUNK(reg), . - GET_PC_THUNK(reg); \
147 .previous; \
148 .endif; \
149 call GET_PC_THUNK(reg)
151 # define LOAD_PIC_REG(reg) \
152 SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg
154 #undef JUMPTARGET
155 #ifdef PIC
156 #define JUMPTARGET(name) name##@PLT
157 #define SYSCALL_PIC_SETUP \
158 pushl %ebx; \
159 cfi_adjust_cfa_offset (4); \
160 call 0f; \
161 0: popl %ebx; \
162 cfi_adjust_cfa_offset (-4); \
163 addl $_GLOBAL_OFFSET_TABLE+[.-0b], %ebx;
165 #else
166 #define JUMPTARGET(name) name
167 #define SYSCALL_PIC_SETUP /* Nothing. */
168 #endif
170 /* Local label name for asm code. */
171 #ifndef L
172 #define L(name) .L##name
173 #endif
175 #define atom_text_section .section ".text.atom", "ax"
177 #else /* __ASSEMBLER__ */
179 # define SETUP_PIC_REG_STR(reg) \
180 ".ifndef " GET_PC_THUNK_STR (reg) "\n" \
181 ".section .gnu.linkonce.t." GET_PC_THUNK_STR (reg) ",\"ax\",@progbits\n" \
182 ".globl " GET_PC_THUNK_STR (reg) "\n" \
183 ".hidden " GET_PC_THUNK_STR (reg) "\n" \
184 ".p2align 4\n" \
185 ".type " GET_PC_THUNK_STR (reg) ",@function\n" \
186 GET_PC_THUNK_STR (reg) ":" \
187 "movl (%%esp), %%e" #reg "\n" \
188 "ret\n" \
189 ".size " GET_PC_THUNK_STR (reg) ", . - " GET_PC_THUNK_STR (reg) "\n" \
190 ".previous\n" \
191 ".endif\n" \
192 "call " GET_PC_THUNK_STR (reg)
194 # define LOAD_PIC_REG_STR(reg) \
195 SETUP_PIC_REG_STR (reg) "\naddl $_GLOBAL_OFFSET_TABLE_, %%e" #reg
197 #endif /* __ASSEMBLER__ */