OSDN Git Service

* config.gcc (with_cpu handling): Translate sparc64 in
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / linux.h
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.
6
7 This file is part of GNU CC.
8
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.
13
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.
18
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.  */
23
24 #define LINUX_DEFAULT_ELF
25
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)
35
36 #define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)");
37
38 /* The svr4 ABI for the i386 says that records and unions are returned
39    in memory.  */
40 #undef DEFAULT_PCC_STRUCT_RETURN
41 #define DEFAULT_PCC_STRUCT_RETURN 1
42
43 /* We arrange for the whole %gs segment to map the tls area.  */
44 #undef TARGET_TLS_DIRECT_SEG_REFS_DEFAULT
45 #define TARGET_TLS_DIRECT_SEG_REFS_DEFAULT MASK_TLS_DIRECT_SEG_REFS
46
47 #undef ASM_COMMENT_START
48 #define ASM_COMMENT_START "#"
49
50 #undef DBX_REGISTER_NUMBER
51 #define DBX_REGISTER_NUMBER(n) \
52   (TARGET_64BIT ? dbx64_register_map[n] : svr4_dbx_register_map[n])
53
54 /* Output assembler code to FILE to call the profiler.
55    To the best of my knowledge, no Linux libc has required the label
56    argument to mcount.  */
57
58 #define NO_PROFILE_COUNTERS     1
59
60 #undef MCOUNT_NAME
61 #define MCOUNT_NAME "mcount"
62
63 /* The GLIBC version of mcount for the x86 assumes that there is a
64    frame, so we cannot allow profiling without a frame pointer.  */
65
66 #undef SUBTARGET_FRAME_POINTER_REQUIRED
67 #define SUBTARGET_FRAME_POINTER_REQUIRED current_function_profile
68
69 #undef SIZE_TYPE
70 #define SIZE_TYPE "unsigned int"
71  
72 #undef PTRDIFF_TYPE
73 #define PTRDIFF_TYPE "int"
74   
75 #undef WCHAR_TYPE
76 #define WCHAR_TYPE "long int"
77    
78 #undef WCHAR_TYPE_SIZE
79 #define WCHAR_TYPE_SIZE BITS_PER_WORD
80     
81 #define TARGET_OS_CPP_BUILTINS()                \
82   do                                            \
83     {                                           \
84         builtin_define_std ("linux");           \
85         builtin_define_std ("unix");            \
86         builtin_define ("__gnu_linux__");       \
87         builtin_assert ("system=posix");        \
88         if (flag_pic)                           \
89           {                                     \
90             builtin_define ("__PIC__");         \
91             builtin_define ("__pic__");         \
92           }                                     \
93     }                                           \
94   while (0)
95
96 #undef CPP_SPEC
97 #ifdef USE_GNULIBC_1
98 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE}"
99 #else
100 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
101 #endif
102
103 #undef CC1_SPEC
104 #define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
105
106 /* Provide a LINK_SPEC appropriate for Linux.  Here we provide support
107    for the special GCC options -static and -shared, which allow us to
108    link things in one of these three modes by applying the appropriate
109    combinations of options at link-time. We like to support here for
110    as many of the other GNU linker options as possible. But I don't
111    have the time to search for those flags. I am sure how to add
112    support for -soname shared_object_name. H.J.
113
114    I took out %{v:%{!V:-V}}. It is too much :-(. They can use
115    -Wl,-V.
116
117    When the -shared link option is used a final link is not being
118    done.  */
119
120 /* If ELF is the default format, we should not use /lib/elf.  */
121
122 #undef  LINK_SPEC
123 #ifdef USE_GNULIBC_1
124 #ifndef LINUX_DEFAULT_ELF
125 #define LINK_SPEC "-m elf_i386 %{shared:-shared} \
126   %{!shared: \
127     %{!ibcs: \
128       %{!static: \
129         %{rdynamic:-export-dynamic} \
130         %{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \
131         %{!rpath:-rpath /lib/elf/}} %{static:-static}}}"
132 #else
133 #define LINK_SPEC "-m elf_i386 %{shared:-shared} \
134   %{!shared: \
135     %{!ibcs: \
136       %{!static: \
137         %{rdynamic:-export-dynamic} \
138         %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \
139         %{static:-static}}}"
140 #endif
141 #else
142 #define LINK_SPEC "-m elf_i386 %{shared:-shared} \
143   %{!shared: \
144     %{!ibcs: \
145       %{!static: \
146         %{rdynamic:-export-dynamic} \
147         %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
148         %{static:-static}}}"
149 #endif
150
151 /* A C statement (sans semicolon) to output to the stdio stream
152    FILE the assembler definition of uninitialized global DECL named
153    NAME whose size is SIZE bytes and alignment is ALIGN bytes.
154    Try to use asm_output_aligned_bss to implement this macro.  */
155
156 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
157   asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
158
159 /* A C statement to output to the stdio stream FILE an assembler
160    command to advance the location counter to a multiple of 1<<LOG
161    bytes if it is within MAX_SKIP bytes.
162
163    This is used to align code labels according to Intel recommendations.  */
164
165 #ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
166 #define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP)                    \
167   do {                                                                  \
168     if ((LOG) != 0) {                                                   \
169       if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG));  \
170       else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));  \
171     }                                                                   \
172   } while (0)
173 #endif
174
175 #if defined(__PIC__) && defined (USE_GNULIBC_1)
176 /* This is a kludge. The i386 GNU/Linux dynamic linker needs ___brk_addr,
177    __environ and atexit.  We have to make sure they are in the .dynsym
178    section.  We do this by forcing the assembler to create undefined 
179    references to these symbols in the object file.  */
180 #undef CRT_CALL_STATIC_FUNCTION
181 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)      \
182    asm (SECTION_OP "\n\t"                               \
183         "call " USER_LABEL_PREFIX #FUNC "\n"            \
184         TEXT_SECTION_ASM_OP "\n\t"                      \
185         ".extern ___brk_addr\n\t"                       \
186         ".type ___brk_addr,@object\n\t"                 \
187         ".extern __environ\n\t"                         \
188         ".type __environ,@object\n\t"                   \
189         ".extern atexit\n\t"                            \
190         ".type atexit,@function");
191 #endif
192
193 /* Handle special EH pointer encodings.  Absolute, pc-relative, and
194    indirect are handled automatically.  */
195 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
196   do {                                                                  \
197     if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_datarel)         \
198       {                                                                 \
199         fputs (ASM_LONG, FILE);                 \
200         assemble_name (FILE, XSTR (ADDR, 0));                           \
201         fputs (((ENCODING) & DW_EH_PE_indirect ? "@GOT" : "@GOTOFF"), FILE); \
202         goto DONE;                                                      \
203       }                                                                 \
204   } while (0)
205
206 /* Used by crtstuff.c to initialize the base of data-relative relocations.
207    These are GOT relative on x86, so return the pic register.  */
208 #ifdef __PIC__
209 #define CRT_GET_RFIB_DATA(BASE)                 \
210   {                                             \
211     register void *ebx_ __asm__("ebx");         \
212     BASE = ebx_;                                \
213   }
214 #else
215 #define CRT_GET_RFIB_DATA(BASE)                                         \
216   __asm__ ("call\t.LPR%=\n"                                             \
217            ".LPR%=:\n\t"                                                \
218            "popl\t%0\n\t"                                               \
219            /* Due to a GAS bug, this cannot use EAX.  That encodes      \
220               smaller than the traditional EBX, which results in the    \
221               offset being off by one.  */                              \
222            "addl\t$_GLOBAL_OFFSET_TABLE_+[.-.LPR%=],%0"                 \
223            : "=d"(BASE))
224 #endif
225
226 #undef NEED_INDICATE_EXEC_STACK
227 #define NEED_INDICATE_EXEC_STACK 1
228
229 /* Do code reading to identify a signal frame, and set the frame
230    state data appropriately.  See unwind-dw2.c for the structs.  */
231
232 #ifdef IN_LIBGCC2
233 /* There's no sys/ucontext.h for some (all?) libc1, so no
234    signal-turned-exceptions for them.  There's also no configure-run for
235    the target, so we can't check on (e.g.) HAVE_SYS_UCONTEXT_H.  Using the
236    target libc1 macro should be enough.  */
237 #ifndef USE_GNULIBC_1
238 #include <signal.h>
239 #include <sys/ucontext.h>
240
241 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)               \
242   do {                                                                  \
243     unsigned char *pc_ = (CONTEXT)->ra;                                 \
244     struct sigcontext *sc_;                                             \
245     long new_cfa_;                                                      \
246                                                                         \
247     /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80  */            \
248     if (*(unsigned short *)(pc_+0) == 0xb858                            \
249         && *(unsigned int *)(pc_+2) == 119                              \
250         && *(unsigned short *)(pc_+6) == 0x80cd)                        \
251       sc_ = (CONTEXT)->cfa + 4;                                         \
252     /* movl $__NR_rt_sigreturn,%eax ; int $0x80  */                     \
253     else if (*(unsigned char *)(pc_+0) == 0xb8                          \
254              && *(unsigned int *)(pc_+1) == 173                         \
255              && *(unsigned short *)(pc_+5) == 0x80cd)                   \
256       {                                                                 \
257         struct rt_sigframe {                                            \
258           int sig;                                                      \
259           struct siginfo *pinfo;                                        \
260           void *puc;                                                    \
261           struct siginfo info;                                          \
262           struct ucontext uc;                                           \
263         } *rt_ = (CONTEXT)->cfa;                                        \
264         sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext;               \
265       }                                                                 \
266     else                                                                \
267       break;                                                            \
268                                                                         \
269     new_cfa_ = sc_->esp;                                                \
270     (FS)->cfa_how = CFA_REG_OFFSET;                                     \
271     (FS)->cfa_reg = 4;                                                  \
272     (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;                \
273                                                                         \
274     /* The SVR4 register numbering macros aren't usable in libgcc.  */  \
275     (FS)->regs.reg[0].how = REG_SAVED_OFFSET;                           \
276     (FS)->regs.reg[0].loc.offset = (long)&sc_->eax - new_cfa_;          \
277     (FS)->regs.reg[3].how = REG_SAVED_OFFSET;                           \
278     (FS)->regs.reg[3].loc.offset = (long)&sc_->ebx - new_cfa_;          \
279     (FS)->regs.reg[1].how = REG_SAVED_OFFSET;                           \
280     (FS)->regs.reg[1].loc.offset = (long)&sc_->ecx - new_cfa_;          \
281     (FS)->regs.reg[2].how = REG_SAVED_OFFSET;                           \
282     (FS)->regs.reg[2].loc.offset = (long)&sc_->edx - new_cfa_;          \
283     (FS)->regs.reg[6].how = REG_SAVED_OFFSET;                           \
284     (FS)->regs.reg[6].loc.offset = (long)&sc_->esi - new_cfa_;          \
285     (FS)->regs.reg[7].how = REG_SAVED_OFFSET;                           \
286     (FS)->regs.reg[7].loc.offset = (long)&sc_->edi - new_cfa_;          \
287     (FS)->regs.reg[5].how = REG_SAVED_OFFSET;                           \
288     (FS)->regs.reg[5].loc.offset = (long)&sc_->ebp - new_cfa_;          \
289     (FS)->regs.reg[8].how = REG_SAVED_OFFSET;                           \
290     (FS)->regs.reg[8].loc.offset = (long)&sc_->eip - new_cfa_;          \
291     (FS)->retaddr_column = 8;                                           \
292     goto SUCCESS;                                                       \
293   } while (0)
294 #endif /* not USE_GNULIBC_1 */
295 #endif /* IN_LIBGCC2 */