OSDN Git Service

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