linux.h revision 117395
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
718334SpeterThis file is part of GNU CC.
818334Speter
918334SpeterGNU CC 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
1418334SpeterGNU CC 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
2018334Speteralong with GNU CC; see the file COPYING.  If not, write to
2118334Speterthe Free Software Foundation, 59 Temple Place - Suite 330,
2218334SpeterBoston, MA 02111-1307, USA.  */
2318334Speter
2418334Speter#define LINUX_DEFAULT_ELF
2518334Speter
2690075Sobrien/* Output at beginning of assembler file.  */
2790075Sobrien/* The .file command should always begin the output.  */
2890075Sobrien#undef ASM_FILE_START
2990075Sobrien#define ASM_FILE_START(FILE)						\
3090075Sobrien  do {									\
3190075Sobrien	output_file_directive (FILE, main_input_filename);		\
3290075Sobrien	if (ix86_asm_dialect == ASM_INTEL)				\
3390075Sobrien	  fputs ("\t.intel_syntax\n", FILE);				\
3490075Sobrien  } while (0)
3518334Speter
3618334Speter#define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)");
3718334Speter
3818334Speter/* The svr4 ABI for the i386 says that records and unions are returned
3918334Speter   in memory.  */
4018334Speter#undef DEFAULT_PCC_STRUCT_RETURN
4118334Speter#define DEFAULT_PCC_STRUCT_RETURN 1
4218334Speter
4350397Sobrien#undef ASM_COMMENT_START
4450397Sobrien#define ASM_COMMENT_START "#"
4550397Sobrien
4618334Speter#undef DBX_REGISTER_NUMBER
4718334Speter#define DBX_REGISTER_NUMBER(n) \
4890075Sobrien  (TARGET_64BIT ? dbx64_register_map[n] : svr4_dbx_register_map[n])
4918334Speter
5090075Sobrien/* Output assembler code to FILE to call the profiler.
5190075Sobrien   To the best of my knowledge, no Linux libc has required the label
5290075Sobrien   argument to mcount.  */
5318334Speter
5490075Sobrien#define NO_PROFILE_COUNTERS
5590075Sobrien
56117395Skan#undef MCOUNT_NAME
57117395Skan#define MCOUNT_NAME "mcount"
5818334Speter
59117395Skan/* The GLIBC version of mcount for the x86 assumes that there is a
6090075Sobrien   frame, so we cannot allow profiling without a frame pointer.  */
6190075Sobrien
62117395Skan#undef SUBTARGET_FRAME_POINTER_REQUIRED
63117395Skan#define SUBTARGET_FRAME_POINTER_REQUIRED current_function_profile
6490075Sobrien
6518334Speter#undef SIZE_TYPE
6618334Speter#define SIZE_TYPE "unsigned int"
6718334Speter
6818334Speter#undef PTRDIFF_TYPE
6918334Speter#define PTRDIFF_TYPE "int"
7018334Speter
7118334Speter#undef WCHAR_TYPE
7218334Speter#define WCHAR_TYPE "long int"
7318334Speter
7418334Speter#undef WCHAR_TYPE_SIZE
7518334Speter#define WCHAR_TYPE_SIZE BITS_PER_WORD
7618334Speter
77117395Skan#define TARGET_OS_CPP_BUILTINS()		\
78117395Skan  do						\
79117395Skan    {						\
80117395Skan	builtin_define_std ("linux");		\
81117395Skan	builtin_define_std ("unix");		\
82117395Skan	builtin_define ("__ELF__");		\
83117395Skan	builtin_define ("__gnu_linux__");	\
84117395Skan	builtin_assert ("system=posix");	\
85117395Skan	if (flag_pic)				\
86117395Skan	  {					\
87117395Skan	    builtin_define ("__PIC__");		\
88117395Skan	    builtin_define ("__pic__");		\
89117395Skan	  }					\
90117395Skan    }						\
91117395Skan  while (0)
9218334Speter
9318334Speter#undef CPP_SPEC
9448743Sobrien#ifdef USE_GNULIBC_1
95117395Skan#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}"
9618334Speter#else
97117395Skan#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
9818334Speter#endif
9918334Speter
10050397Sobrien#undef CC1_SPEC
10150397Sobrien#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
10248743Sobrien
10318334Speter/* Provide a LINK_SPEC appropriate for Linux.  Here we provide support
10418334Speter   for the special GCC options -static and -shared, which allow us to
10518334Speter   link things in one of these three modes by applying the appropriate
10618334Speter   combinations of options at link-time. We like to support here for
10718334Speter   as many of the other GNU linker options as possible. But I don't
10818334Speter   have the time to search for those flags. I am sure how to add
10918334Speter   support for -soname shared_object_name. H.J.
11018334Speter
11118334Speter   I took out %{v:%{!V:-V}}. It is too much :-(. They can use
11218334Speter   -Wl,-V.
11318334Speter
11418334Speter   When the -shared link option is used a final link is not being
11518334Speter   done.  */
11618334Speter
11790075Sobrien/* If ELF is the default format, we should not use /lib/elf.  */
11818334Speter
11918334Speter#undef	LINK_SPEC
12048743Sobrien#ifdef USE_GNULIBC_1
12118334Speter#ifndef LINUX_DEFAULT_ELF
12218334Speter#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
12318334Speter  %{!shared: \
12418334Speter    %{!ibcs: \
12518334Speter      %{!static: \
12618334Speter	%{rdynamic:-export-dynamic} \
12718334Speter	%{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \
12818334Speter	%{!rpath:-rpath /lib/elf/}} %{static:-static}}}"
12918334Speter#else
13018334Speter#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
13118334Speter  %{!shared: \
13218334Speter    %{!ibcs: \
13318334Speter      %{!static: \
13418334Speter	%{rdynamic:-export-dynamic} \
13518334Speter	%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \
13618334Speter	%{static:-static}}}"
13718334Speter#endif
13850397Sobrien#else
13948743Sobrien#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
14048743Sobrien  %{!shared: \
14148743Sobrien    %{!ibcs: \
14248743Sobrien      %{!static: \
14348743Sobrien	%{rdynamic:-export-dynamic} \
14448743Sobrien	%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
14548743Sobrien	%{static:-static}}}"
14650397Sobrien#endif
14718334Speter
14850397Sobrien/* A C statement (sans semicolon) to output to the stdio stream
14950397Sobrien   FILE the assembler definition of uninitialized global DECL named
15050397Sobrien   NAME whose size is SIZE bytes and alignment is ALIGN bytes.
15150397Sobrien   Try to use asm_output_aligned_bss to implement this macro.  */
15250397Sobrien
15350397Sobrien#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
15450397Sobrien  asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
15550397Sobrien
15650397Sobrien/* A C statement to output to the stdio stream FILE an assembler
15750397Sobrien   command to advance the location counter to a multiple of 1<<LOG
15850397Sobrien   bytes if it is within MAX_SKIP bytes.
15950397Sobrien
16050397Sobrien   This is used to align code labels according to Intel recommendations.  */
16150397Sobrien
16250397Sobrien#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
16352284Sobrien#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP)			\
16452284Sobrien  do {									\
16552284Sobrien    if ((LOG) != 0) {							\
16652284Sobrien      if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG));	\
16752284Sobrien      else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));	\
16852284Sobrien    }									\
16952284Sobrien  } while (0)
17050397Sobrien#endif
17190075Sobrien
17290075Sobrien#if defined(__PIC__) && defined (USE_GNULIBC_1)
17390075Sobrien/* This is a kludge. The i386 GNU/Linux dynamic linker needs ___brk_addr,
17490075Sobrien   __environ and atexit.  We have to make sure they are in the .dynsym
17590075Sobrien   section.  We do this by forcing the assembler to create undefined
17690075Sobrien   references to these symbols in the object file.  */
17790075Sobrien#undef CRT_CALL_STATIC_FUNCTION
17890075Sobrien#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)	\
17990075Sobrien   asm (SECTION_OP "\n\t"				\
18090075Sobrien	"call " USER_LABEL_PREFIX #FUNC "\n"		\
18190075Sobrien	TEXT_SECTION_ASM_OP "\n\t"			\
18290075Sobrien	".extern ___brk_addr\n\t"			\
18390075Sobrien	".type ___brk_addr,@object\n\t"			\
18490075Sobrien	".extern __environ\n\t"				\
18590075Sobrien	".type __environ,@object\n\t"			\
18690075Sobrien	".extern atexit\n\t"				\
18790075Sobrien	".type atexit,@function");
18890075Sobrien#endif
18990075Sobrien
19090075Sobrien/* Handle special EH pointer encodings.  Absolute, pc-relative, and
19190075Sobrien   indirect are handled automatically.  */
19290075Sobrien#define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
19390075Sobrien  do {									\
19490075Sobrien    if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_datarel)		\
19590075Sobrien      {									\
19690075Sobrien        fputs (ASM_LONG, FILE);			\
19790075Sobrien        assemble_name (FILE, XSTR (ADDR, 0));				\
19890075Sobrien	fputs (((ENCODING) & DW_EH_PE_indirect ? "@GOT" : "@GOTOFF"), FILE); \
19990075Sobrien        goto DONE;							\
20090075Sobrien      }									\
20190075Sobrien  } while (0)
20290075Sobrien
20390075Sobrien/* Used by crtstuff.c to initialize the base of data-relative relocations.
20490075Sobrien   These are GOT relative on x86, so return the pic register.  */
20590075Sobrien#ifdef __PIC__
20690075Sobrien#define CRT_GET_RFIB_DATA(BASE)			\
20790075Sobrien  {						\
20890075Sobrien    register void *ebx_ __asm__("ebx");		\
20990075Sobrien    BASE = ebx_;				\
21090075Sobrien  }
21190075Sobrien#else
21290075Sobrien#define CRT_GET_RFIB_DATA(BASE)						\
21390075Sobrien  __asm__ ("call\t.LPR%=\n"						\
21490075Sobrien	   ".LPR%=:\n\t"						\
21590075Sobrien	   "popl\t%0\n\t"						\
21690075Sobrien	   /* Due to a GAS bug, this cannot use EAX.  That encodes	\
21790075Sobrien	      smaller than the traditional EBX, which results in the	\
21890075Sobrien	      offset being off by one.  */				\
21990075Sobrien	   "addl\t$_GLOBAL_OFFSET_TABLE_+[.-.LPR%=],%0"			\
22090075Sobrien	   : "=d"(BASE))
22190075Sobrien#endif
22290075Sobrien
22390075Sobrien/* Do code reading to identify a signal frame, and set the frame
22490075Sobrien   state data appropriately.  See unwind-dw2.c for the structs.  */
22590075Sobrien
22690075Sobrien#ifdef IN_LIBGCC2
227117395Skan/* There's no sys/ucontext.h for some (all?) libc1, so no
228117395Skan   signal-turned-exceptions for them.  There's also no configure-run for
229117395Skan   the target, so we can't check on (e.g.) HAVE_SYS_UCONTEXT_H.  Using the
230117395Skan   target libc1 macro should be enough.  */
231117395Skan#ifndef USE_GNULIBC_1
23290075Sobrien#include <signal.h>
23390075Sobrien#include <sys/ucontext.h>
23490075Sobrien
23590075Sobrien#define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)		\
23690075Sobrien  do {									\
23790075Sobrien    unsigned char *pc_ = (CONTEXT)->ra;					\
23890075Sobrien    struct sigcontext *sc_;						\
23990075Sobrien    long new_cfa_;							\
24090075Sobrien									\
24190075Sobrien    /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80  */		\
24290075Sobrien    if (*(unsigned short *)(pc_+0) == 0xb858				\
24390075Sobrien	&& *(unsigned int *)(pc_+2) == 119				\
24490075Sobrien	&& *(unsigned short *)(pc_+6) == 0x80cd)			\
24590075Sobrien      sc_ = (CONTEXT)->cfa + 4;						\
24690075Sobrien    /* movl $__NR_rt_sigreturn,%eax ; int $0x80  */			\
24790075Sobrien    else if (*(unsigned char *)(pc_+0) == 0xb8				\
24890075Sobrien	     && *(unsigned int *)(pc_+1) == 173				\
24990075Sobrien	     && *(unsigned short *)(pc_+5) == 0x80cd)			\
25090075Sobrien      {									\
25190075Sobrien	struct rt_sigframe {						\
25290075Sobrien	  int sig;							\
25390075Sobrien	  struct siginfo *pinfo;					\
25490075Sobrien	  void *puc;							\
25590075Sobrien	  struct siginfo info;						\
25690075Sobrien	  struct ucontext uc;						\
25790075Sobrien	} *rt_ = (CONTEXT)->cfa;					\
25890075Sobrien	sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext;		\
25990075Sobrien      }									\
26090075Sobrien    else								\
26190075Sobrien      break;								\
26290075Sobrien									\
26390075Sobrien    new_cfa_ = sc_->esp;						\
26490075Sobrien    (FS)->cfa_how = CFA_REG_OFFSET;					\
26590075Sobrien    (FS)->cfa_reg = 4;							\
26690075Sobrien    (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;		\
26790075Sobrien									\
26890075Sobrien    /* The SVR4 register numbering macros aren't usable in libgcc.  */	\
26990075Sobrien    (FS)->regs.reg[0].how = REG_SAVED_OFFSET;				\
27090075Sobrien    (FS)->regs.reg[0].loc.offset = (long)&sc_->eax - new_cfa_;		\
27190075Sobrien    (FS)->regs.reg[3].how = REG_SAVED_OFFSET;				\
27290075Sobrien    (FS)->regs.reg[3].loc.offset = (long)&sc_->ebx - new_cfa_;		\
27390075Sobrien    (FS)->regs.reg[1].how = REG_SAVED_OFFSET;				\
27490075Sobrien    (FS)->regs.reg[1].loc.offset = (long)&sc_->ecx - new_cfa_;		\
27590075Sobrien    (FS)->regs.reg[2].how = REG_SAVED_OFFSET;				\
27690075Sobrien    (FS)->regs.reg[2].loc.offset = (long)&sc_->edx - new_cfa_;		\
27790075Sobrien    (FS)->regs.reg[6].how = REG_SAVED_OFFSET;				\
27890075Sobrien    (FS)->regs.reg[6].loc.offset = (long)&sc_->esi - new_cfa_;		\
27990075Sobrien    (FS)->regs.reg[7].how = REG_SAVED_OFFSET;				\
28090075Sobrien    (FS)->regs.reg[7].loc.offset = (long)&sc_->edi - new_cfa_;		\
28190075Sobrien    (FS)->regs.reg[5].how = REG_SAVED_OFFSET;				\
28290075Sobrien    (FS)->regs.reg[5].loc.offset = (long)&sc_->ebp - new_cfa_;		\
28390075Sobrien    (FS)->regs.reg[8].how = REG_SAVED_OFFSET;				\
28490075Sobrien    (FS)->regs.reg[8].loc.offset = (long)&sc_->eip - new_cfa_;		\
28590075Sobrien    (FS)->retaddr_column = 8;						\
28690075Sobrien    goto SUCCESS;							\
28790075Sobrien  } while (0)
288117395Skan#endif /* not USE_GNULIBC_1 */
289117395Skan#endif /* IN_LIBGCC2 */
290