linux64.h revision 107590
1275970Scy/* Definitions for AMD x86-64 running Linux-based GNU systems with ELF format.
2275970Scy   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3275970Scy   Contributed by Jan Hubicka <jh@suse.cz>, based on linux.h.
4275970Scy
5275970ScyThis file is part of GNU CC.
6275970Scy
7275970ScyGNU CC is free software; you can redistribute it and/or modify
8275970Scyit under the terms of the GNU General Public License as published by
9275970Scythe Free Software Foundation; either version 2, or (at your option)
10275970Scyany later version.
11275970Scy
12275970ScyGNU CC is distributed in the hope that it will be useful,
13275970Scybut WITHOUT ANY WARRANTY; without even the implied warranty of
14275970ScyMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15275970ScyGNU General Public License for more details.
16275970Scy
17275970ScyYou should have received a copy of the GNU General Public License
18275970Scyalong with GNU CC; see the file COPYING.  If not, write to
19275970Scythe Free Software Foundation, 59 Temple Place - Suite 330,
20275970ScyBoston, MA 02111-1307, USA.  */
21275970Scy
22275970Scy#define LINUX_DEFAULT_ELF
23275970Scy
24275970Scy#undef TARGET_VERSION
25275970Scy#define TARGET_VERSION fprintf (stderr, " (x86-64 Linux/ELF)");
26275970Scy
27275970Scy#undef CPP_PREDEFINES
28275970Scy#define CPP_PREDEFINES "-D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -Asystem(posix)"
29275970Scy
30275970Scy#undef CPP_SPEC
31275970Scy#define CPP_SPEC "%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT} %{!m32:-D__LONG_MAX__=9223372036854775807L}"
32275970Scy
33275970Scy/* The svr4 ABI for the i386 says that records and unions are returned
34275970Scy   in memory.  In the 64bit compilation we will turn this flag off in
35275970Scy   override_options, as we never do pcc_struct_return scheme on this target.  */
36275970Scy#undef DEFAULT_PCC_STRUCT_RETURN
37275970Scy#define DEFAULT_PCC_STRUCT_RETURN 1
38275970Scy
39275970Scy/* Provide a LINK_SPEC.  Here we provide support for the special GCC
40275970Scy   options -static and -shared, which allow us to link things in one
41275970Scy   of these three modes by applying the appropriate combinations of
42275970Scy   options at link-time.
43275970Scy
44275970Scy   When the -shared link option is used a final link is not being
45275970Scy   done.  */
46275970Scy
47#undef	LINK_SPEC
48#define LINK_SPEC "%{!m32:-m elf_x86_64 -Y P,/usr/lib64} %{m32:-m elf_i386} \
49  %{shared:-shared} \
50  %{!shared: \
51    %{!static: \
52      %{rdynamic:-export-dynamic} \
53      %{m32:%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
54      %{!m32:%{!dynamic-linker:-dynamic-linker /lib64/ld-linux-x86-64.so.2}}} \
55    %{static:-static}}"
56
57#undef  STARTFILE_SPEC
58#define STARTFILE_SPEC \
59  "%{!shared: \
60     %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \
61     %{!p:%{profile:gcrt1.o%s} %{!profile:crt1.o%s}}}} \
62   crti.o%s %{static:crtbeginT.o%s} \
63   %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}"
64
65#undef  ENDFILE_SPEC
66#define ENDFILE_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"
67
68#define MULTILIB_DEFAULTS { "m64" }
69
70/* Do code reading to identify a signal frame, and set the frame
71   state data appropriately.  See unwind-dw2.c for the structs.
72   Don't use this at all if inhibit_libc is used.  */
73
74#ifndef inhibit_libc
75#ifdef IN_LIBGCC2
76#include <signal.h>
77#include <sys/ucontext.h>
78#endif
79
80#ifdef __x86_64__
81#define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)		\
82  do {									\
83    unsigned char *pc_ = (CONTEXT)->ra;					\
84    struct sigcontext *sc_;						\
85    long new_cfa_;							\
86									\
87    /* movq __NR_rt_sigreturn, %rax ; syscall  */			\
88    if (*(unsigned char *)(pc_+0) == 0x48				\
89	&& *(unsigned long *)(pc_+1) == 0x050f0000000fc0c7)		\
90      {									\
91	struct ucontext *uc_ = (CONTEXT)->cfa;				\
92	sc_ = (struct sigcontext *) &uc_->uc_mcontext;			\
93      }									\
94    else								\
95      break;								\
96									\
97    new_cfa_ = sc_->rsp;						\
98    (FS)->cfa_how = CFA_REG_OFFSET;					\
99    /* Register 7 is rsp  */						\
100    (FS)->cfa_reg = 7;							\
101    (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;		\
102									\
103    /* The SVR4 register numbering macros aren't usable in libgcc.  */	\
104    (FS)->regs.reg[0].how = REG_SAVED_OFFSET;				\
105    (FS)->regs.reg[0].loc.offset = (long)&sc_->rax - new_cfa_;		\
106    (FS)->regs.reg[1].how = REG_SAVED_OFFSET;				\
107    (FS)->regs.reg[1].loc.offset = (long)&sc_->rbx - new_cfa_;		\
108    (FS)->regs.reg[2].how = REG_SAVED_OFFSET;				\
109    (FS)->regs.reg[2].loc.offset = (long)&sc_->rcx - new_cfa_;		\
110    (FS)->regs.reg[3].how = REG_SAVED_OFFSET;				\
111    (FS)->regs.reg[3].loc.offset = (long)&sc_->rdx - new_cfa_;		\
112    (FS)->regs.reg[4].how = REG_SAVED_OFFSET;				\
113    (FS)->regs.reg[4].loc.offset = (long)&sc_->rbp - new_cfa_;		\
114    (FS)->regs.reg[5].how = REG_SAVED_OFFSET;				\
115    (FS)->regs.reg[5].loc.offset = (long)&sc_->rsi - new_cfa_;		\
116    (FS)->regs.reg[6].how = REG_SAVED_OFFSET;				\
117    (FS)->regs.reg[6].loc.offset = (long)&sc_->rdi - new_cfa_;		\
118    (FS)->regs.reg[8].how = REG_SAVED_OFFSET;				\
119    (FS)->regs.reg[8].loc.offset = (long)&sc_->r8 - new_cfa_;		\
120    (FS)->regs.reg[9].how = REG_SAVED_OFFSET;				\
121    (FS)->regs.reg[9].loc.offset = (long)&sc_->r9 - new_cfa_;		\
122    (FS)->regs.reg[10].how = REG_SAVED_OFFSET;				\
123    (FS)->regs.reg[10].loc.offset = (long)&sc_->r10 - new_cfa_;		\
124    (FS)->regs.reg[11].how = REG_SAVED_OFFSET;				\
125    (FS)->regs.reg[11].loc.offset = (long)&sc_->r11 - new_cfa_;		\
126    (FS)->regs.reg[12].how = REG_SAVED_OFFSET;				\
127    (FS)->regs.reg[12].loc.offset = (long)&sc_->r12 - new_cfa_;		\
128    (FS)->regs.reg[13].how = REG_SAVED_OFFSET;				\
129    (FS)->regs.reg[13].loc.offset = (long)&sc_->r13 - new_cfa_;		\
130    (FS)->regs.reg[14].how = REG_SAVED_OFFSET;				\
131    (FS)->regs.reg[14].loc.offset = (long)&sc_->r14 - new_cfa_;		\
132    (FS)->regs.reg[15].how = REG_SAVED_OFFSET;				\
133    (FS)->regs.reg[15].loc.offset = (long)&sc_->r15 - new_cfa_;		\
134    (FS)->retaddr_column = 16;						\
135    goto SUCCESS;							\
136  } while (0)
137#else /* ifdef __x86_64__  */
138#define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS)		\
139  do {									\
140    unsigned char *pc_ = (CONTEXT)->ra;					\
141    struct sigcontext *sc_;						\
142    long new_cfa_;							\
143									\
144    /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80  */		\
145    if (*(unsigned short *)(pc_+0) == 0xb858				\
146	&& *(unsigned int *)(pc_+2) == 119				\
147	&& *(unsigned short *)(pc_+6) == 0x80cd)			\
148      sc_ = (CONTEXT)->cfa + 4;						\
149    /* movl $__NR_rt_sigreturn,%eax ; int $0x80  */			\
150    else if (*(unsigned char *)(pc_+0) == 0xb8				\
151	     && *(unsigned int *)(pc_+1) == 173				\
152	     && *(unsigned short *)(pc_+5) == 0x80cd)			\
153      {									\
154	struct rt_sigframe {						\
155	  int sig;							\
156	  struct siginfo *pinfo;					\
157	  void *puc;							\
158	  struct siginfo info;						\
159	  struct ucontext uc;						\
160	} *rt_ = (CONTEXT)->cfa;					\
161	sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext;		\
162      }									\
163    else								\
164      break;								\
165									\
166    new_cfa_ = sc_->esp;						\
167    (FS)->cfa_how = CFA_REG_OFFSET;					\
168    (FS)->cfa_reg = 4;							\
169    (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa;		\
170									\
171    /* The SVR4 register numbering macros aren't usable in libgcc.  */	\
172    (FS)->regs.reg[0].how = REG_SAVED_OFFSET;				\
173    (FS)->regs.reg[0].loc.offset = (long)&sc_->eax - new_cfa_;		\
174    (FS)->regs.reg[3].how = REG_SAVED_OFFSET;				\
175    (FS)->regs.reg[3].loc.offset = (long)&sc_->ebx - new_cfa_;		\
176    (FS)->regs.reg[1].how = REG_SAVED_OFFSET;				\
177    (FS)->regs.reg[1].loc.offset = (long)&sc_->ecx - new_cfa_;		\
178    (FS)->regs.reg[2].how = REG_SAVED_OFFSET;				\
179    (FS)->regs.reg[2].loc.offset = (long)&sc_->edx - new_cfa_;		\
180    (FS)->regs.reg[6].how = REG_SAVED_OFFSET;				\
181    (FS)->regs.reg[6].loc.offset = (long)&sc_->esi - new_cfa_;		\
182    (FS)->regs.reg[7].how = REG_SAVED_OFFSET;				\
183    (FS)->regs.reg[7].loc.offset = (long)&sc_->edi - new_cfa_;		\
184    (FS)->regs.reg[5].how = REG_SAVED_OFFSET;				\
185    (FS)->regs.reg[5].loc.offset = (long)&sc_->ebp - new_cfa_;		\
186    (FS)->regs.reg[8].how = REG_SAVED_OFFSET;				\
187    (FS)->regs.reg[8].loc.offset = (long)&sc_->eip - new_cfa_;		\
188    (FS)->retaddr_column = 8;						\
189    goto SUCCESS;							\
190  } while (0)
191#endif /* ifdef __x86_64__  */
192#endif /* ifdef inhibit_libc  */
193