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