linux.h revision 132718
150397Sobrien/* Definitions for Intel 386 running Linux-based GNU systems with ELF format.
290075Sobrien   Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002
390075Sobrien   Free Software Foundation, Inc.
418334Speter   Contributed by Eric Youngdale.
518334Speter   Modified for stabs-in-ELF by H.J. Lu.
618334Speter
7132718SkanThis file is part of GCC.
818334Speter
9132718SkanGCC is free software; you can redistribute it and/or modify
1018334Speterit under the terms of the GNU General Public License as published by
1118334Speterthe Free Software Foundation; either version 2, or (at your option)
1218334Speterany later version.
1318334Speter
14132718SkanGCC is distributed in the hope that it will be useful,
1518334Speterbut WITHOUT ANY WARRANTY; without even the implied warranty of
1618334SpeterMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1718334SpeterGNU General Public License for more details.
1818334Speter
1918334SpeterYou should have received a copy of the GNU General Public License
20132718Skanalong with GCC; see the file COPYING.  If not, write to
2118334Speterthe Free Software Foundation, 59 Temple Place - Suite 330,
2218334SpeterBoston, MA 02111-1307, USA.  */
2318334Speter
2490075Sobrien/* Output at beginning of assembler file.  */
2590075Sobrien/* The .file command should always begin the output.  */
26132718Skan#define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
2718334Speter
2818334Speter#define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)");
2918334Speter
3018334Speter/* The svr4 ABI for the i386 says that records and unions are returned
3118334Speter   in memory.  */
3218334Speter#undef DEFAULT_PCC_STRUCT_RETURN
3318334Speter#define DEFAULT_PCC_STRUCT_RETURN 1
3418334Speter
35132718Skan/* We arrange for the whole %gs segment to map the tls area.  */
36132718Skan#undef TARGET_TLS_DIRECT_SEG_REFS_DEFAULT
37132718Skan#define TARGET_TLS_DIRECT_SEG_REFS_DEFAULT MASK_TLS_DIRECT_SEG_REFS
38132718Skan
3950397Sobrien#undef ASM_COMMENT_START
4050397Sobrien#define ASM_COMMENT_START "#"
4150397Sobrien
4218334Speter#undef DBX_REGISTER_NUMBER
4318334Speter#define DBX_REGISTER_NUMBER(n) \
4490075Sobrien  (TARGET_64BIT ? dbx64_register_map[n] : svr4_dbx_register_map[n])
4518334Speter
4690075Sobrien/* Output assembler code to FILE to call the profiler.
4790075Sobrien   To the best of my knowledge, no Linux libc has required the label
4890075Sobrien   argument to mcount.  */
4918334Speter
50132718Skan#define NO_PROFILE_COUNTERS	1
5190075Sobrien
52117395Skan#undef MCOUNT_NAME
53117395Skan#define MCOUNT_NAME "mcount"
5418334Speter
55117395Skan/* The GLIBC version of mcount for the x86 assumes that there is a
5690075Sobrien   frame, so we cannot allow profiling without a frame pointer.  */
5790075Sobrien
58117395Skan#undef SUBTARGET_FRAME_POINTER_REQUIRED
59117395Skan#define SUBTARGET_FRAME_POINTER_REQUIRED current_function_profile
6090075Sobrien
6118334Speter#undef SIZE_TYPE
6218334Speter#define SIZE_TYPE "unsigned int"
6318334Speter
6418334Speter#undef PTRDIFF_TYPE
6518334Speter#define PTRDIFF_TYPE "int"
6618334Speter
6718334Speter#undef WCHAR_TYPE
6818334Speter#define WCHAR_TYPE "long int"
6918334Speter
7018334Speter#undef WCHAR_TYPE_SIZE
7118334Speter#define WCHAR_TYPE_SIZE BITS_PER_WORD
7218334Speter
73117395Skan#define TARGET_OS_CPP_BUILTINS()		\
74117395Skan  do						\
75117395Skan    {						\
76132718Skan	LINUX_TARGET_OS_CPP_BUILTINS();		\
77117395Skan	if (flag_pic)				\
78117395Skan	  {					\
79117395Skan	    builtin_define ("__PIC__");		\
80117395Skan	    builtin_define ("__pic__");		\
81117395Skan	  }					\
82117395Skan    }						\
83117395Skan  while (0)
8418334Speter
8518334Speter#undef CPP_SPEC
8648743Sobrien#ifdef USE_GNULIBC_1
87117395Skan#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}"
8818334Speter#else
89117395Skan#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
9018334Speter#endif
9118334Speter
9250397Sobrien#undef CC1_SPEC
9350397Sobrien#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
9448743Sobrien
9518334Speter/* Provide a LINK_SPEC appropriate for Linux.  Here we provide support
9618334Speter   for the special GCC options -static and -shared, which allow us to
9718334Speter   link things in one of these three modes by applying the appropriate
9818334Speter   combinations of options at link-time. We like to support here for
9918334Speter   as many of the other GNU linker options as possible. But I don't
10018334Speter   have the time to search for those flags. I am sure how to add
10118334Speter   support for -soname shared_object_name. H.J.
10218334Speter
10318334Speter   I took out %{v:%{!V:-V}}. It is too much :-(. They can use
10418334Speter   -Wl,-V.
10518334Speter
10618334Speter   When the -shared link option is used a final link is not being
10718334Speter   done.  */
10818334Speter
10990075Sobrien/* If ELF is the default format, we should not use /lib/elf.  */
11018334Speter
11118334Speter#undef	LINK_SPEC
11248743Sobrien#ifdef USE_GNULIBC_1
11318334Speter#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
11418334Speter  %{!shared: \
11518334Speter    %{!ibcs: \
11618334Speter      %{!static: \
11718334Speter	%{rdynamic:-export-dynamic} \
11818334Speter	%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \
11918334Speter	%{static:-static}}}"
12050397Sobrien#else
12148743Sobrien#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
12248743Sobrien  %{!shared: \
12348743Sobrien    %{!ibcs: \
12448743Sobrien      %{!static: \
12548743Sobrien	%{rdynamic:-export-dynamic} \
12648743Sobrien	%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
12748743Sobrien	%{static:-static}}}"
12850397Sobrien#endif
12918334Speter
13050397Sobrien/* A C statement (sans semicolon) to output to the stdio stream
13150397Sobrien   FILE the assembler definition of uninitialized global DECL named
13250397Sobrien   NAME whose size is SIZE bytes and alignment is ALIGN bytes.
13350397Sobrien   Try to use asm_output_aligned_bss to implement this macro.  */
13450397Sobrien
13550397Sobrien#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
13650397Sobrien  asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
13750397Sobrien
13850397Sobrien/* A C statement to output to the stdio stream FILE an assembler
13950397Sobrien   command to advance the location counter to a multiple of 1<<LOG
14050397Sobrien   bytes if it is within MAX_SKIP bytes.
14150397Sobrien
14250397Sobrien   This is used to align code labels according to Intel recommendations.  */
14350397Sobrien
14450397Sobrien#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
14552284Sobrien#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP)			\
14652284Sobrien  do {									\
14752284Sobrien    if ((LOG) != 0) {							\
14852284Sobrien      if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG));	\
14952284Sobrien      else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));	\
15052284Sobrien    }									\
15152284Sobrien  } while (0)
15250397Sobrien#endif
15390075Sobrien
15490075Sobrien#if defined(__PIC__) && defined (USE_GNULIBC_1)
15590075Sobrien/* This is a kludge. The i386 GNU/Linux dynamic linker needs ___brk_addr,
15690075Sobrien   __environ and atexit.  We have to make sure they are in the .dynsym
15790075Sobrien   section.  We do this by forcing the assembler to create undefined
15890075Sobrien   references to these symbols in the object file.  */
15990075Sobrien#undef CRT_CALL_STATIC_FUNCTION
16090075Sobrien#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)	\
16190075Sobrien   asm (SECTION_OP "\n\t"				\
16290075Sobrien	"call " USER_LABEL_PREFIX #FUNC "\n"		\
16390075Sobrien	TEXT_SECTION_ASM_OP "\n\t"			\
16490075Sobrien	".extern ___brk_addr\n\t"			\
16590075Sobrien	".type ___brk_addr,@object\n\t"			\
16690075Sobrien	".extern __environ\n\t"				\
16790075Sobrien	".type __environ,@object\n\t"			\
16890075Sobrien	".extern atexit\n\t"				\
16990075Sobrien	".type atexit,@function");
17090075Sobrien#endif
17190075Sobrien
17290075Sobrien/* Handle special EH pointer encodings.  Absolute, pc-relative, and
17390075Sobrien   indirect are handled automatically.  */
17490075Sobrien#define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
17590075Sobrien  do {									\
17690075Sobrien    if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_datarel)		\
17790075Sobrien      {									\
17890075Sobrien        fputs (ASM_LONG, FILE);			\
17990075Sobrien        assemble_name (FILE, XSTR (ADDR, 0));				\
18090075Sobrien	fputs (((ENCODING) & DW_EH_PE_indirect ? "@GOT" : "@GOTOFF"), FILE); \
18190075Sobrien        goto DONE;							\
18290075Sobrien      }									\
18390075Sobrien  } while (0)
18490075Sobrien
18590075Sobrien/* Used by crtstuff.c to initialize the base of data-relative relocations.
18690075Sobrien   These are GOT relative on x86, so return the pic register.  */
18790075Sobrien#ifdef __PIC__
18890075Sobrien#define CRT_GET_RFIB_DATA(BASE)			\
18990075Sobrien  {						\
19090075Sobrien    register void *ebx_ __asm__("ebx");		\
19190075Sobrien    BASE = ebx_;				\
19290075Sobrien  }
19390075Sobrien#else
19490075Sobrien#define CRT_GET_RFIB_DATA(BASE)						\
19590075Sobrien  __asm__ ("call\t.LPR%=\n"						\
19690075Sobrien	   ".LPR%=:\n\t"						\
19790075Sobrien	   "popl\t%0\n\t"						\
19890075Sobrien	   /* Due to a GAS bug, this cannot use EAX.  That encodes	\
19990075Sobrien	      smaller than the traditional EBX, which results in the	\
20090075Sobrien	      offset being off by one.  */				\
20190075Sobrien	   "addl\t$_GLOBAL_OFFSET_TABLE_+[.-.LPR%=],%0"			\
20290075Sobrien	   : "=d"(BASE))
20390075Sobrien#endif
20490075Sobrien
205132718Skan#undef NEED_INDICATE_EXEC_STACK
206132718Skan#define NEED_INDICATE_EXEC_STACK 1
207132718Skan
20890075Sobrien/* Do code reading to identify a signal frame, and set the frame
20990075Sobrien   state data appropriately.  See unwind-dw2.c for the structs.  */
21090075Sobrien
21190075Sobrien#ifdef IN_LIBGCC2
212117395Skan/* There's no sys/ucontext.h for some (all?) libc1, so no
213117395Skan   signal-turned-exceptions for them.  There's also no configure-run for
214117395Skan   the target, so we can't check on (e.g.) HAVE_SYS_UCONTEXT_H.  Using the
215117395Skan   target libc1 macro should be enough.  */
216132718Skan#if !(defined (USE_GNULIBC_1) || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0))
21790075Sobrien#include <signal.h>
21890075Sobrien#include <sys/ucontext.h>
21990075Sobrien
22090075Sobrien#define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)		\
22190075Sobrien  do {									\
22290075Sobrien    unsigned char *pc_ = (CONTEXT)->ra;					\
22390075Sobrien    struct sigcontext *sc_;						\
22490075Sobrien    long new_cfa_;							\
22590075Sobrien									\
22690075Sobrien    /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80  */		\
22790075Sobrien    if (*(unsigned short *)(pc_+0) == 0xb858				\
22890075Sobrien	&& *(unsigned int *)(pc_+2) == 119				\
22990075Sobrien	&& *(unsigned short *)(pc_+6) == 0x80cd)			\
23090075Sobrien      sc_ = (CONTEXT)->cfa + 4;						\
23190075Sobrien    /* movl $__NR_rt_sigreturn,%eax ; int $0x80  */			\
23290075Sobrien    else if (*(unsigned char *)(pc_+0) == 0xb8				\
23390075Sobrien	     && *(unsigned int *)(pc_+1) == 173				\
23490075Sobrien	     && *(unsigned short *)(pc_+5) == 0x80cd)			\
23590075Sobrien      {									\
23690075Sobrien	struct rt_sigframe {						\
23790075Sobrien	  int sig;							\
23890075Sobrien	  struct siginfo *pinfo;					\
23990075Sobrien	  void *puc;							\
24090075Sobrien	  struct siginfo info;						\
24190075Sobrien	  struct ucontext uc;						\
24290075Sobrien	} *rt_ = (CONTEXT)->cfa;					\
24390075Sobrien	sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext;		\
24490075Sobrien      }									\
24590075Sobrien    else								\
24690075Sobrien      break;								\
24790075Sobrien									\
24890075Sobrien    new_cfa_ = sc_->esp;						\
24990075Sobrien    (FS)->cfa_how = CFA_REG_OFFSET;					\
25090075Sobrien    (FS)->cfa_reg = 4;							\
25190075Sobrien    (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;		\
25290075Sobrien									\
25390075Sobrien    /* The SVR4 register numbering macros aren't usable in libgcc.  */	\
25490075Sobrien    (FS)->regs.reg[0].how = REG_SAVED_OFFSET;				\
25590075Sobrien    (FS)->regs.reg[0].loc.offset = (long)&sc_->eax - new_cfa_;		\
25690075Sobrien    (FS)->regs.reg[3].how = REG_SAVED_OFFSET;				\
25790075Sobrien    (FS)->regs.reg[3].loc.offset = (long)&sc_->ebx - new_cfa_;		\
25890075Sobrien    (FS)->regs.reg[1].how = REG_SAVED_OFFSET;				\
25990075Sobrien    (FS)->regs.reg[1].loc.offset = (long)&sc_->ecx - new_cfa_;		\
26090075Sobrien    (FS)->regs.reg[2].how = REG_SAVED_OFFSET;				\
26190075Sobrien    (FS)->regs.reg[2].loc.offset = (long)&sc_->edx - new_cfa_;		\
26290075Sobrien    (FS)->regs.reg[6].how = REG_SAVED_OFFSET;				\
26390075Sobrien    (FS)->regs.reg[6].loc.offset = (long)&sc_->esi - new_cfa_;		\
26490075Sobrien    (FS)->regs.reg[7].how = REG_SAVED_OFFSET;				\
26590075Sobrien    (FS)->regs.reg[7].loc.offset = (long)&sc_->edi - new_cfa_;		\
26690075Sobrien    (FS)->regs.reg[5].how = REG_SAVED_OFFSET;				\
26790075Sobrien    (FS)->regs.reg[5].loc.offset = (long)&sc_->ebp - new_cfa_;		\
26890075Sobrien    (FS)->regs.reg[8].how = REG_SAVED_OFFSET;				\
26990075Sobrien    (FS)->regs.reg[8].loc.offset = (long)&sc_->eip - new_cfa_;		\
27090075Sobrien    (FS)->retaddr_column = 8;						\
27190075Sobrien    goto SUCCESS;							\
27290075Sobrien  } while (0)
273117395Skan#endif /* not USE_GNULIBC_1 */
274117395Skan#endif /* IN_LIBGCC2 */
275