1c87b03e5Sespie /* Definitions for AMD x86-64 running Linux-based GNU systems with ELF format. 2c87b03e5Sespie Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. 3c87b03e5Sespie Contributed by Jan Hubicka <jh@suse.cz>, based on linux.h. 4c87b03e5Sespie 5c87b03e5Sespie This file is part of GNU CC. 6c87b03e5Sespie 7c87b03e5Sespie GNU CC is free software; you can redistribute it and/or modify 8c87b03e5Sespie it under the terms of the GNU General Public License as published by 9c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option) 10c87b03e5Sespie any later version. 11c87b03e5Sespie 12c87b03e5Sespie GNU CC is distributed in the hope that it will be useful, 13c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of 14c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15c87b03e5Sespie GNU General Public License for more details. 16c87b03e5Sespie 17c87b03e5Sespie You should have received a copy of the GNU General Public License 18c87b03e5Sespie along with GNU CC; see the file COPYING. If not, write to 19c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330, 20c87b03e5Sespie Boston, MA 02111-1307, USA. */ 21c87b03e5Sespie 22c87b03e5Sespie #define LINUX_DEFAULT_ELF 23c87b03e5Sespie 24c87b03e5Sespie #define TARGET_VERSION fprintf (stderr, " (x86-64 Linux/ELF)"); 25c87b03e5Sespie 26c87b03e5Sespie #define TARGET_OS_CPP_BUILTINS() \ 27c87b03e5Sespie do \ 28c87b03e5Sespie { \ 29c87b03e5Sespie builtin_define_std ("linux"); \ 30c87b03e5Sespie builtin_define_std ("unix"); \ 31c87b03e5Sespie builtin_define ("__gnu_linux__"); \ 32c87b03e5Sespie builtin_define ("__ELF__"); \ 33c87b03e5Sespie builtin_assert ("system=posix"); \ 34c87b03e5Sespie if (flag_pic) \ 35c87b03e5Sespie { \ 36c87b03e5Sespie builtin_define ("__PIC__"); \ 37c87b03e5Sespie builtin_define ("__pic__"); \ 38c87b03e5Sespie } \ 39c87b03e5Sespie if (TARGET_64BIT) \ 40c87b03e5Sespie { \ 41c87b03e5Sespie builtin_define ("__LP64__"); \ 42c87b03e5Sespie builtin_define ("_LP64"); \ 43c87b03e5Sespie } \ 44c87b03e5Sespie } \ 45c87b03e5Sespie while (0) 46c87b03e5Sespie 47c87b03e5Sespie #undef CPP_SPEC 48c87b03e5Sespie #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" 49c87b03e5Sespie 50c87b03e5Sespie /* The svr4 ABI for the i386 says that records and unions are returned 51c87b03e5Sespie in memory. In the 64bit compilation we will turn this flag off in 52c87b03e5Sespie override_options, as we never do pcc_struct_return scheme on this target. */ 53c87b03e5Sespie #undef DEFAULT_PCC_STRUCT_RETURN 54c87b03e5Sespie #define DEFAULT_PCC_STRUCT_RETURN 1 55c87b03e5Sespie 56c87b03e5Sespie /* Provide a LINK_SPEC. Here we provide support for the special GCC 57c87b03e5Sespie options -static and -shared, which allow us to link things in one 58c87b03e5Sespie of these three modes by applying the appropriate combinations of 59c87b03e5Sespie options at link-time. 60c87b03e5Sespie 61c87b03e5Sespie When the -shared link option is used a final link is not being 62c87b03e5Sespie done. */ 63c87b03e5Sespie 64c87b03e5Sespie #undef LINK_SPEC 65c87b03e5Sespie #define LINK_SPEC "%{!m32:-m elf_x86_64} %{m32:-m elf_i386} \ 66c87b03e5Sespie %{shared:-shared} \ 67c87b03e5Sespie %{!shared: \ 68c87b03e5Sespie %{!static: \ 69c87b03e5Sespie %{rdynamic:-export-dynamic} \ 70c87b03e5Sespie %{m32:%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \ 71c87b03e5Sespie %{!m32:%{!dynamic-linker:-dynamic-linker /lib64/ld-linux-x86-64.so.2}}} \ 72c87b03e5Sespie %{static:-static}}" 73c87b03e5Sespie 74c87b03e5Sespie #undef STARTFILE_SPEC 75c87b03e5Sespie #define STARTFILE_SPEC \ 76c87b03e5Sespie "%{!shared: \ 77c87b03e5Sespie %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \ 78c87b03e5Sespie %{!p:%{profile:gcrt1.o%s} %{!profile:crt1.o%s}}}} \ 79c87b03e5Sespie crti.o%s %{static:crtbeginT.o%s} \ 80c87b03e5Sespie %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}" 81c87b03e5Sespie 82c87b03e5Sespie #undef ENDFILE_SPEC 83c87b03e5Sespie #define ENDFILE_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" 84c87b03e5Sespie 85c87b03e5Sespie #define MULTILIB_DEFAULTS { "m64" } 86c87b03e5Sespie 87*4e43c760Sespie #define SUBTARGET_FILE_END(FILE) \ 88*4e43c760Sespie do { \ 89*4e43c760Sespie named_section_flags (".note.GNU-stack", \ 90*4e43c760Sespie SECTION_DEBUG \ 91*4e43c760Sespie | (trampolines_created ? SECTION_CODE : 0)); \ 92*4e43c760Sespie } while (0) 93*4e43c760Sespie 94c87b03e5Sespie /* Do code reading to identify a signal frame, and set the frame 95c87b03e5Sespie state data appropriately. See unwind-dw2.c for the structs. 96c87b03e5Sespie Don't use this at all if inhibit_libc is used. */ 97c87b03e5Sespie 98c87b03e5Sespie #ifndef inhibit_libc 99c87b03e5Sespie #ifdef IN_LIBGCC2 100c87b03e5Sespie #include <signal.h> 101c87b03e5Sespie #include <sys/ucontext.h> 102c87b03e5Sespie #endif 103c87b03e5Sespie 104c87b03e5Sespie #ifdef __x86_64__ 105c87b03e5Sespie #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \ 106c87b03e5Sespie do { \ 107c87b03e5Sespie unsigned char *pc_ = (CONTEXT)->ra; \ 108c87b03e5Sespie struct sigcontext *sc_; \ 109c87b03e5Sespie long new_cfa_; \ 110c87b03e5Sespie \ 111c87b03e5Sespie /* movq __NR_rt_sigreturn, %rax ; syscall */ \ 112c87b03e5Sespie if (*(unsigned char *)(pc_+0) == 0x48 \ 113c87b03e5Sespie && *(unsigned long *)(pc_+1) == 0x050f0000000fc0c7) \ 114c87b03e5Sespie { \ 115c87b03e5Sespie struct ucontext *uc_ = (CONTEXT)->cfa; \ 116c87b03e5Sespie sc_ = (struct sigcontext *) &uc_->uc_mcontext; \ 117c87b03e5Sespie } \ 118c87b03e5Sespie else \ 119c87b03e5Sespie break; \ 120c87b03e5Sespie \ 121c87b03e5Sespie new_cfa_ = sc_->rsp; \ 122c87b03e5Sespie (FS)->cfa_how = CFA_REG_OFFSET; \ 123c87b03e5Sespie /* Register 7 is rsp */ \ 124c87b03e5Sespie (FS)->cfa_reg = 7; \ 125c87b03e5Sespie (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \ 126c87b03e5Sespie \ 127c87b03e5Sespie /* The SVR4 register numbering macros aren't usable in libgcc. */ \ 128c87b03e5Sespie (FS)->regs.reg[0].how = REG_SAVED_OFFSET; \ 129c87b03e5Sespie (FS)->regs.reg[0].loc.offset = (long)&sc_->rax - new_cfa_; \ 130c87b03e5Sespie (FS)->regs.reg[1].how = REG_SAVED_OFFSET; \ 131c87b03e5Sespie (FS)->regs.reg[1].loc.offset = (long)&sc_->rdx - new_cfa_; \ 132c87b03e5Sespie (FS)->regs.reg[2].how = REG_SAVED_OFFSET; \ 133c87b03e5Sespie (FS)->regs.reg[2].loc.offset = (long)&sc_->rcx - new_cfa_; \ 134c87b03e5Sespie (FS)->regs.reg[3].how = REG_SAVED_OFFSET; \ 135c87b03e5Sespie (FS)->regs.reg[3].loc.offset = (long)&sc_->rbx - new_cfa_; \ 136c87b03e5Sespie (FS)->regs.reg[4].how = REG_SAVED_OFFSET; \ 137c87b03e5Sespie (FS)->regs.reg[4].loc.offset = (long)&sc_->rsi - new_cfa_; \ 138c87b03e5Sespie (FS)->regs.reg[5].how = REG_SAVED_OFFSET; \ 139c87b03e5Sespie (FS)->regs.reg[5].loc.offset = (long)&sc_->rdi - new_cfa_; \ 140c87b03e5Sespie (FS)->regs.reg[6].how = REG_SAVED_OFFSET; \ 141c87b03e5Sespie (FS)->regs.reg[6].loc.offset = (long)&sc_->rbp - new_cfa_; \ 142c87b03e5Sespie (FS)->regs.reg[8].how = REG_SAVED_OFFSET; \ 143c87b03e5Sespie (FS)->regs.reg[8].loc.offset = (long)&sc_->r8 - new_cfa_; \ 144c87b03e5Sespie (FS)->regs.reg[9].how = REG_SAVED_OFFSET; \ 145c87b03e5Sespie (FS)->regs.reg[9].loc.offset = (long)&sc_->r9 - new_cfa_; \ 146c87b03e5Sespie (FS)->regs.reg[10].how = REG_SAVED_OFFSET; \ 147c87b03e5Sespie (FS)->regs.reg[10].loc.offset = (long)&sc_->r10 - new_cfa_; \ 148c87b03e5Sespie (FS)->regs.reg[11].how = REG_SAVED_OFFSET; \ 149c87b03e5Sespie (FS)->regs.reg[11].loc.offset = (long)&sc_->r11 - new_cfa_; \ 150c87b03e5Sespie (FS)->regs.reg[12].how = REG_SAVED_OFFSET; \ 151c87b03e5Sespie (FS)->regs.reg[12].loc.offset = (long)&sc_->r12 - new_cfa_; \ 152c87b03e5Sespie (FS)->regs.reg[13].how = REG_SAVED_OFFSET; \ 153c87b03e5Sespie (FS)->regs.reg[13].loc.offset = (long)&sc_->r13 - new_cfa_; \ 154c87b03e5Sespie (FS)->regs.reg[14].how = REG_SAVED_OFFSET; \ 155c87b03e5Sespie (FS)->regs.reg[14].loc.offset = (long)&sc_->r14 - new_cfa_; \ 156c87b03e5Sespie (FS)->regs.reg[15].how = REG_SAVED_OFFSET; \ 157c87b03e5Sespie (FS)->regs.reg[15].loc.offset = (long)&sc_->r15 - new_cfa_; \ 158c87b03e5Sespie (FS)->regs.reg[16].how = REG_SAVED_OFFSET; \ 159c87b03e5Sespie (FS)->regs.reg[16].loc.offset = (long)&sc_->rip - new_cfa_; \ 160c87b03e5Sespie (FS)->retaddr_column = 16; \ 161c87b03e5Sespie goto SUCCESS; \ 162c87b03e5Sespie } while (0) 163c87b03e5Sespie #else /* ifdef __x86_64__ */ 164c87b03e5Sespie #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \ 165c87b03e5Sespie do { \ 166c87b03e5Sespie unsigned char *pc_ = (CONTEXT)->ra; \ 167c87b03e5Sespie struct sigcontext *sc_; \ 168c87b03e5Sespie long new_cfa_; \ 169c87b03e5Sespie \ 170c87b03e5Sespie /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80 */ \ 171c87b03e5Sespie if (*(unsigned short *)(pc_+0) == 0xb858 \ 172c87b03e5Sespie && *(unsigned int *)(pc_+2) == 119 \ 173c87b03e5Sespie && *(unsigned short *)(pc_+6) == 0x80cd) \ 174c87b03e5Sespie sc_ = (CONTEXT)->cfa + 4; \ 175c87b03e5Sespie /* movl $__NR_rt_sigreturn,%eax ; int $0x80 */ \ 176c87b03e5Sespie else if (*(unsigned char *)(pc_+0) == 0xb8 \ 177c87b03e5Sespie && *(unsigned int *)(pc_+1) == 173 \ 178c87b03e5Sespie && *(unsigned short *)(pc_+5) == 0x80cd) \ 179c87b03e5Sespie { \ 180c87b03e5Sespie struct rt_sigframe { \ 181c87b03e5Sespie int sig; \ 182c87b03e5Sespie struct siginfo *pinfo; \ 183c87b03e5Sespie void *puc; \ 184c87b03e5Sespie struct siginfo info; \ 185c87b03e5Sespie struct ucontext uc; \ 186c87b03e5Sespie } *rt_ = (CONTEXT)->cfa; \ 187c87b03e5Sespie sc_ = (struct sigcontext *) &rt_->uc.uc_mcontext; \ 188c87b03e5Sespie } \ 189c87b03e5Sespie else \ 190c87b03e5Sespie break; \ 191c87b03e5Sespie \ 192c87b03e5Sespie new_cfa_ = sc_->esp; \ 193c87b03e5Sespie (FS)->cfa_how = CFA_REG_OFFSET; \ 194c87b03e5Sespie (FS)->cfa_reg = 4; \ 195c87b03e5Sespie (FS)->cfa_offset = new_cfa_ - (long) (CONTEXT)->cfa; \ 196c87b03e5Sespie \ 197c87b03e5Sespie /* The SVR4 register numbering macros aren't usable in libgcc. */ \ 198c87b03e5Sespie (FS)->regs.reg[0].how = REG_SAVED_OFFSET; \ 199c87b03e5Sespie (FS)->regs.reg[0].loc.offset = (long)&sc_->eax - new_cfa_; \ 200c87b03e5Sespie (FS)->regs.reg[3].how = REG_SAVED_OFFSET; \ 201c87b03e5Sespie (FS)->regs.reg[3].loc.offset = (long)&sc_->ebx - new_cfa_; \ 202c87b03e5Sespie (FS)->regs.reg[1].how = REG_SAVED_OFFSET; \ 203c87b03e5Sespie (FS)->regs.reg[1].loc.offset = (long)&sc_->ecx - new_cfa_; \ 204c87b03e5Sespie (FS)->regs.reg[2].how = REG_SAVED_OFFSET; \ 205c87b03e5Sespie (FS)->regs.reg[2].loc.offset = (long)&sc_->edx - new_cfa_; \ 206c87b03e5Sespie (FS)->regs.reg[6].how = REG_SAVED_OFFSET; \ 207c87b03e5Sespie (FS)->regs.reg[6].loc.offset = (long)&sc_->esi - new_cfa_; \ 208c87b03e5Sespie (FS)->regs.reg[7].how = REG_SAVED_OFFSET; \ 209c87b03e5Sespie (FS)->regs.reg[7].loc.offset = (long)&sc_->edi - new_cfa_; \ 210c87b03e5Sespie (FS)->regs.reg[5].how = REG_SAVED_OFFSET; \ 211c87b03e5Sespie (FS)->regs.reg[5].loc.offset = (long)&sc_->ebp - new_cfa_; \ 212c87b03e5Sespie (FS)->regs.reg[8].how = REG_SAVED_OFFSET; \ 213c87b03e5Sespie (FS)->regs.reg[8].loc.offset = (long)&sc_->eip - new_cfa_; \ 214c87b03e5Sespie (FS)->retaddr_column = 8; \ 215c87b03e5Sespie goto SUCCESS; \ 216c87b03e5Sespie } while (0) 217c87b03e5Sespie #endif /* ifdef __x86_64__ */ 218c87b03e5Sespie #endif /* ifdef inhibit_libc */ 219