OSDN Git Service

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