* Makefile.in (CRTSTUFF_CFLAGS): New.
[official-gcc.git] / gcc / config / i386 / linux.h
blobde634d3a4e771679fff772860f50493bfbe3f4e1
1 /* Definitions for Intel 386 running Linux-based GNU systems with ELF format.
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Eric Youngdale.
5 Modified for stabs-in-ELF by H.J. Lu.
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 #define LINUX_DEFAULT_ELF
26 /* Output at beginning of assembler file. */
27 /* The .file command should always begin the output. */
28 #undef ASM_FILE_START
29 #define ASM_FILE_START(FILE) \
30 do { \
31 output_file_directive (FILE, main_input_filename); \
32 if (ix86_asm_dialect == ASM_INTEL) \
33 fputs ("\t.intel_syntax\n", FILE); \
34 } while (0)
36 #undef TARGET_VERSION
37 #define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)");
39 /* The svr4 ABI for the i386 says that records and unions are returned
40 in memory. */
41 #undef DEFAULT_PCC_STRUCT_RETURN
42 #define DEFAULT_PCC_STRUCT_RETURN 1
44 #undef ASM_COMMENT_START
45 #define ASM_COMMENT_START "#"
47 #undef DBX_REGISTER_NUMBER
48 #define DBX_REGISTER_NUMBER(n) \
49 (TARGET_64BIT ? dbx64_register_map[n] : svr4_dbx_register_map[n])
51 /* Output assembler code to FILE to call the profiler.
52 To the best of my knowledge, no Linux libc has required the label
53 argument to mcount. */
55 #define NO_PROFILE_COUNTERS
57 #undef FUNCTION_PROFILER
58 #define FUNCTION_PROFILER(FILE, LABELNO) \
59 { \
60 if (flag_pic) \
61 fprintf (FILE, "\tcall\t*mcount@GOT(%%ebx)\n"); \
62 else \
63 fprintf (FILE, "\tcall\tmcount\n"); \
66 /* True if it is possible to profile code that does not have a frame
67 pointer.
69 The GLIBC version of mcount for the x86 assumes that there is a
70 frame, so we cannot allow profiling without a frame pointer. */
72 #undef TARGET_ALLOWS_PROFILING_WITHOUT_FRAME_POINTER
73 #define TARGET_ALLOWS_PROFILING_WITHOUT_FRAME_POINTER false
75 #undef SIZE_TYPE
76 #define SIZE_TYPE "unsigned int"
78 #undef PTRDIFF_TYPE
79 #define PTRDIFF_TYPE "int"
81 #undef WCHAR_TYPE
82 #define WCHAR_TYPE "long int"
84 #undef WCHAR_TYPE_SIZE
85 #define WCHAR_TYPE_SIZE BITS_PER_WORD
87 #undef CPP_PREDEFINES
88 #define CPP_PREDEFINES "-D__ELF__ -Dunix -Dlinux -Asystem=posix"
90 #undef CPP_SPEC
91 #ifdef USE_GNULIBC_1
92 #define CPP_SPEC "%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE}"
93 #else
94 #define CPP_SPEC "%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
95 #endif
97 #undef CC1_SPEC
98 #define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
100 /* Provide a LINK_SPEC appropriate for Linux. Here we provide support
101 for the special GCC options -static and -shared, which allow us to
102 link things in one of these three modes by applying the appropriate
103 combinations of options at link-time. We like to support here for
104 as many of the other GNU linker options as possible. But I don't
105 have the time to search for those flags. I am sure how to add
106 support for -soname shared_object_name. H.J.
108 I took out %{v:%{!V:-V}}. It is too much :-(. They can use
109 -Wl,-V.
111 When the -shared link option is used a final link is not being
112 done. */
114 /* If ELF is the default format, we should not use /lib/elf. */
116 #undef LINK_SPEC
117 #ifdef USE_GNULIBC_1
118 #ifndef LINUX_DEFAULT_ELF
119 #define LINK_SPEC "-m elf_i386 %{shared:-shared} \
120 %{!shared: \
121 %{!ibcs: \
122 %{!static: \
123 %{rdynamic:-export-dynamic} \
124 %{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \
125 %{!rpath:-rpath /lib/elf/}} %{static:-static}}}"
126 #else
127 #define LINK_SPEC "-m elf_i386 %{shared:-shared} \
128 %{!shared: \
129 %{!ibcs: \
130 %{!static: \
131 %{rdynamic:-export-dynamic} \
132 %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \
133 %{static:-static}}}"
134 #endif
135 #else
136 #define LINK_SPEC "-m elf_i386 %{shared:-shared} \
137 %{!shared: \
138 %{!ibcs: \
139 %{!static: \
140 %{rdynamic:-export-dynamic} \
141 %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
142 %{static:-static}}}"
143 #endif
145 /* A C statement (sans semicolon) to output to the stdio stream
146 FILE the assembler definition of uninitialized global DECL named
147 NAME whose size is SIZE bytes and alignment is ALIGN bytes.
148 Try to use asm_output_aligned_bss to implement this macro. */
150 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
151 asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
153 /* A C statement to output to the stdio stream FILE an assembler
154 command to advance the location counter to a multiple of 1<<LOG
155 bytes if it is within MAX_SKIP bytes.
157 This is used to align code labels according to Intel recommendations. */
159 #ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
160 #define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP) \
161 do { \
162 if ((LOG) != 0) { \
163 if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG)); \
164 else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP)); \
166 } while (0)
167 #endif
169 #if defined(__PIC__) && defined (USE_GNULIBC_1)
170 /* This is a kludge. The i386 GNU/Linux dynamic linker needs ___brk_addr,
171 __environ and atexit. We have to make sure they are in the .dynsym
172 section. We do this by forcing the assembler to create undefined
173 references to these symbols in the object file. */
174 #undef CRT_CALL_STATIC_FUNCTION
175 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
176 asm (SECTION_OP "\n\t" \
177 "call " USER_LABEL_PREFIX #FUNC "\n" \
178 TEXT_SECTION_ASM_OP "\n\t" \
179 ".extern ___brk_addr\n\t" \
180 ".type ___brk_addr,@object\n\t" \
181 ".extern __environ\n\t" \
182 ".type __environ,@object\n\t" \
183 ".extern atexit\n\t" \
184 ".type atexit,@function");
185 #endif
187 /* Handle special EH pointer encodings. Absolute, pc-relative, and
188 indirect are handled automatically. */
189 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
190 do { \
191 if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_datarel) \
193 fputs (ASM_LONG, FILE); \
194 assemble_name (FILE, XSTR (ADDR, 0)); \
195 fputs (((ENCODING) & DW_EH_PE_indirect ? "@GOT" : "@GOTOFF"), FILE); \
196 goto DONE; \
198 } while (0)
200 /* Used by crtstuff.c to initialize the base of data-relative relocations.
201 These are GOT relative on x86, so return the pic register. */
202 #ifdef __PIC__
203 #define CRT_GET_RFIB_DATA(BASE) \
205 register void *ebx_ __asm__("ebx"); \
206 BASE = ebx_; \
208 #else
209 #define CRT_GET_RFIB_DATA(BASE) \
210 __asm__ ("call\t.LPR%=\n" \
211 ".LPR%=:\n\t" \
212 "popl\t%0\n\t" \
213 /* Due to a GAS bug, this cannot use EAX. That encodes \
214 smaller than the traditional EBX, which results in the \
215 offset being off by one. */ \
216 "addl\t$_GLOBAL_OFFSET_TABLE_+[.-.LPR%=],%0" \
217 : "=d"(BASE))
218 #endif
220 /* Do code reading to identify a signal frame, and set the frame
221 state data appropriately. See unwind-dw2.c for the structs. */
223 #ifdef IN_LIBGCC2
224 #include <signal.h>
225 #include <sys/ucontext.h>
226 #endif
228 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
229 do { \
230 unsigned char *pc_ = (CONTEXT)->ra; \
231 struct sigcontext *sc_; \
232 long new_cfa_; \
234 /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80 */ \
235 if (*(unsigned short *)(pc_+0) == 0xb858 \
236 && *(unsigned int *)(pc_+2) == 119 \
237 && *(unsigned short *)(pc_+6) == 0x80cd) \
238 sc_ = (CONTEXT)->cfa + 4; \
239 /* movl $__NR_rt_sigreturn,%eax ; int $0x80 */ \
240 else if (*(unsigned char *)(pc_+0) == 0xb8 \
241 && *(unsigned int *)(pc_+1) == 173 \
242 && *(unsigned short *)(pc_+5) == 0x80cd) \
244 struct rt_sigframe { \
245 int sig; \
246 struct siginfo *pinfo; \
247 void *puc; \
248 struct siginfo info; \
249 struct ucontext uc; \
250 } *rt_ = (CONTEXT)->cfa; \
251 sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext; \
253 else \
254 break; \
256 new_cfa_ = sc_->esp; \
257 (FS)->cfa_how = CFA_REG_OFFSET; \
258 (FS)->cfa_reg = 4; \
259 (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \
261 /* The SVR4 register numbering macros aren't usable in libgcc. */ \
262 (FS)->regs.reg[0].how = REG_SAVED_OFFSET; \
263 (FS)->regs.reg[0].loc.offset = (long)&sc_->eax - new_cfa_; \
264 (FS)->regs.reg[3].how = REG_SAVED_OFFSET; \
265 (FS)->regs.reg[3].loc.offset = (long)&sc_->ebx - new_cfa_; \
266 (FS)->regs.reg[1].how = REG_SAVED_OFFSET; \
267 (FS)->regs.reg[1].loc.offset = (long)&sc_->ecx - new_cfa_; \
268 (FS)->regs.reg[2].how = REG_SAVED_OFFSET; \
269 (FS)->regs.reg[2].loc.offset = (long)&sc_->edx - new_cfa_; \
270 (FS)->regs.reg[6].how = REG_SAVED_OFFSET; \
271 (FS)->regs.reg[6].loc.offset = (long)&sc_->esi - new_cfa_; \
272 (FS)->regs.reg[7].how = REG_SAVED_OFFSET; \
273 (FS)->regs.reg[7].loc.offset = (long)&sc_->edi - new_cfa_; \
274 (FS)->regs.reg[5].how = REG_SAVED_OFFSET; \
275 (FS)->regs.reg[5].loc.offset = (long)&sc_->ebp - new_cfa_; \
276 (FS)->regs.reg[8].how = REG_SAVED_OFFSET; \
277 (FS)->regs.reg[8].loc.offset = (long)&sc_->eip - new_cfa_; \
278 (FS)->retaddr_column = 8; \
279 goto SUCCESS; \
280 } while (0)