linux.h revision 48743
118334Speter/* Definitions for Intel 386 running Linux with ELF format 218334Speter Copyright (C) 1994, 1995 Free Software Foundation, Inc. 318334Speter Contributed by Eric Youngdale. 418334Speter Modified for stabs-in-ELF by H.J. Lu. 518334Speter 618334SpeterThis file is part of GNU CC. 718334Speter 818334SpeterGNU CC is free software; you can redistribute it and/or modify 918334Speterit under the terms of the GNU General Public License as published by 1018334Speterthe Free Software Foundation; either version 2, or (at your option) 1118334Speterany later version. 1218334Speter 1318334SpeterGNU CC is distributed in the hope that it will be useful, 1418334Speterbut WITHOUT ANY WARRANTY; without even the implied warranty of 1518334SpeterMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1618334SpeterGNU General Public License for more details. 1718334Speter 1818334SpeterYou should have received a copy of the GNU General Public License 1918334Speteralong with GNU CC; see the file COPYING. If not, write to 2018334Speterthe Free Software Foundation, 59 Temple Place - Suite 330, 2118334SpeterBoston, MA 02111-1307, USA. */ 2218334Speter 2318334Speter#define LINUX_DEFAULT_ELF 2418334Speter 2518334Speter/* A lie, I guess, but the general idea behind linux/ELF is that we are 2618334Speter supposed to be outputting something that will assemble under SVr4. 2718334Speter This gets us pretty close. */ 2818334Speter#include <i386/i386.h> /* Base i386 target machine definitions */ 2918334Speter#include <i386/att.h> /* Use the i386 AT&T assembler syntax */ 3018334Speter#include <linux.h> /* some common stuff */ 3118334Speter 3218334Speter#undef TARGET_VERSION 3318334Speter#define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)"); 3418334Speter 3518334Speter/* The svr4 ABI for the i386 says that records and unions are returned 3618334Speter in memory. */ 3718334Speter#undef DEFAULT_PCC_STRUCT_RETURN 3818334Speter#define DEFAULT_PCC_STRUCT_RETURN 1 3918334Speter 4018334Speter/* This is how to output an element of a case-vector that is relative. 4118334Speter This is only used for PIC code. See comments by the `casesi' insn in 4218334Speter i386.md for an explanation of the expression this outputs. */ 4318334Speter#undef ASM_OUTPUT_ADDR_DIFF_ELT 4418334Speter#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ 4518334Speter fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) 4618334Speter 4718334Speter/* Indicate that jump tables go in the text section. This is 4818334Speter necessary when compiling PIC code. */ 4918334Speter#define JUMP_TABLES_IN_TEXT_SECTION 5018334Speter 5118334Speter/* Copy this from the svr4 specifications... */ 5218334Speter/* Define the register numbers to be used in Dwarf debugging information. 5318334Speter The SVR4 reference port C compiler uses the following register numbers 5418334Speter in its Dwarf output code: 5518334Speter 0 for %eax (gnu regno = 0) 5618334Speter 1 for %ecx (gnu regno = 2) 5718334Speter 2 for %edx (gnu regno = 1) 5818334Speter 3 for %ebx (gnu regno = 3) 5918334Speter 4 for %esp (gnu regno = 7) 6018334Speter 5 for %ebp (gnu regno = 6) 6118334Speter 6 for %esi (gnu regno = 4) 6218334Speter 7 for %edi (gnu regno = 5) 6318334Speter The following three DWARF register numbers are never generated by 6418334Speter the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4 6518334Speter believes these numbers have these meanings. 6618334Speter 8 for %eip (no gnu equivalent) 6718334Speter 9 for %eflags (no gnu equivalent) 6818334Speter 10 for %trapno (no gnu equivalent) 6918334Speter It is not at all clear how we should number the FP stack registers 7018334Speter for the x86 architecture. If the version of SDB on x86/svr4 were 7118334Speter a bit less brain dead with respect to floating-point then we would 7218334Speter have a precedent to follow with respect to DWARF register numbers 7318334Speter for x86 FP registers, but the SDB on x86/svr4 is so completely 7418334Speter broken with respect to FP registers that it is hardly worth thinking 7518334Speter of it as something to strive for compatibility with. 7618334Speter The version of x86/svr4 SDB I have at the moment does (partially) 7718334Speter seem to believe that DWARF register number 11 is associated with 7818334Speter the x86 register %st(0), but that's about all. Higher DWARF 7918334Speter register numbers don't seem to be associated with anything in 8018334Speter particular, and even for DWARF regno 11, SDB only seems to under- 8118334Speter stand that it should say that a variable lives in %st(0) (when 8218334Speter asked via an `=' command) if we said it was in DWARF regno 11, 8318334Speter but SDB still prints garbage when asked for the value of the 8418334Speter variable in question (via a `/' command). 8518334Speter (Also note that the labels SDB prints for various FP stack regs 8618334Speter when doing an `x' command are all wrong.) 8718334Speter Note that these problems generally don't affect the native SVR4 8818334Speter C compiler because it doesn't allow the use of -O with -g and 8918334Speter because when it is *not* optimizing, it allocates a memory 9018334Speter location for each floating-point variable, and the memory 9118334Speter location is what gets described in the DWARF AT_location 9218334Speter attribute for the variable in question. 9318334Speter Regardless of the severe mental illness of the x86/svr4 SDB, we 9418334Speter do something sensible here and we use the following DWARF 9518334Speter register numbers. Note that these are all stack-top-relative 9618334Speter numbers. 9718334Speter 11 for %st(0) (gnu regno = 8) 9818334Speter 12 for %st(1) (gnu regno = 9) 9918334Speter 13 for %st(2) (gnu regno = 10) 10018334Speter 14 for %st(3) (gnu regno = 11) 10118334Speter 15 for %st(4) (gnu regno = 12) 10218334Speter 16 for %st(5) (gnu regno = 13) 10318334Speter 17 for %st(6) (gnu regno = 14) 10418334Speter 18 for %st(7) (gnu regno = 15) 10518334Speter*/ 10618334Speter#undef DBX_REGISTER_NUMBER 10718334Speter#define DBX_REGISTER_NUMBER(n) \ 10818334Speter((n) == 0 ? 0 \ 10918334Speter : (n) == 1 ? 2 \ 11018334Speter : (n) == 2 ? 1 \ 11118334Speter : (n) == 3 ? 3 \ 11218334Speter : (n) == 4 ? 6 \ 11318334Speter : (n) == 5 ? 7 \ 11418334Speter : (n) == 6 ? 5 \ 11518334Speter : (n) == 7 ? 4 \ 11618334Speter : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \ 11718334Speter : (-1)) 11818334Speter 11918334Speter/* Output assembler code to FILE to increment profiler label # LABELNO 12018334Speter for profiling a function entry. */ 12118334Speter 12218334Speter#undef FUNCTION_PROFILER 12318334Speter#define FUNCTION_PROFILER(FILE, LABELNO) \ 12418334Speter{ \ 12518334Speter if (flag_pic) \ 12618334Speter { \ 12718334Speter fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \ 12818334Speter LPREFIX, (LABELNO)); \ 12918334Speter fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \ 13018334Speter } \ 13118334Speter else \ 13218334Speter { \ 13318334Speter fprintf (FILE, "\tmovl $%sP%d,%%edx\n", LPREFIX, (LABELNO)); \ 13418334Speter fprintf (FILE, "\tcall mcount\n"); \ 13518334Speter } \ 13618334Speter} 13718334Speter 13818334Speter#undef SIZE_TYPE 13918334Speter#define SIZE_TYPE "unsigned int" 14018334Speter 14118334Speter#undef PTRDIFF_TYPE 14218334Speter#define PTRDIFF_TYPE "int" 14318334Speter 14418334Speter#undef WCHAR_TYPE 14518334Speter#define WCHAR_TYPE "long int" 14618334Speter 14718334Speter#undef WCHAR_TYPE_SIZE 14818334Speter#define WCHAR_TYPE_SIZE BITS_PER_WORD 14918334Speter 15018334Speter#undef CPP_PREDEFINES 15118334Speter#define CPP_PREDEFINES "-D__ELF__ -Dunix -Di386 -Dlinux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386)" 15218334Speter 15318334Speter#undef CPP_SPEC 15448743Sobrien#ifdef USE_GNULIBC_1 15518334Speter#if TARGET_CPU_DEFAULT == 2 15618334Speter#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{!m386:-D__i486__} %{posix:-D_POSIX_SOURCE}" 15718334Speter#else 15818334Speter#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{m486:-D__i486__} %{posix:-D_POSIX_SOURCE}" 15918334Speter#endif 16048743Sobrien#else /* not USE_GNULIBC_1 */ 16148743Sobrien#define CPP_SPEC "%(cpp_cpu) %[cpp_cpu] %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" 16248743Sobrien#endif /* not USE_GNULIBC_1 */ 16318334Speter 16448743Sobrien#undef LIBGCC_SPEC 16548743Sobrien#define LIBGCC_SPEC "-lgcc" 16648743Sobrien 16718334Speter#undef LIB_SPEC 16848743Sobrien#ifdef USE_GNULIBC_1 16918334Speter#if 1 17018334Speter/* We no longer link with libc_p.a or libg.a by default. If you 17118334Speter * want to profile or debug the Linux C library, please add 17218334Speter * -lc_p or -ggdb to LDFLAGS at the link time, respectively. 17318334Speter */ 17418334Speter#define LIB_SPEC \ 17518334Speter "%{!shared: %{mieee-fp:-lieee} %{p:-lgmon} %{pg:-lgmon} \ 17618334Speter %{!ggdb:-lc} %{ggdb:-lg}}" 17718334Speter#else 17818334Speter#define LIB_SPEC \ 17918334Speter "%{!shared: \ 18018334Speter %{mieee-fp:-lieee} %{p:-lgmon -lc_p} %{pg:-lgmon -lc_p} \ 18118334Speter %{!p:%{!pg:%{!g*:-lc} %{g*:-lg}}}}" 18218334Speter#endif 18348743Sobrien#else 18448743Sobrien#define LIB_SPEC \ 18548743Sobrien "%{!shared: %{mieee-fp:-lieee} %{pthread:-lpthread} \ 18648743Sobrien %{profile:-lc_p} %{!profile: -lc}}" 18748743Sobrien#endif /* not USE_GNULIBC_1 */ 18818334Speter 18918334Speter/* Provide a LINK_SPEC appropriate for Linux. Here we provide support 19018334Speter for the special GCC options -static and -shared, which allow us to 19118334Speter link things in one of these three modes by applying the appropriate 19218334Speter combinations of options at link-time. We like to support here for 19318334Speter as many of the other GNU linker options as possible. But I don't 19418334Speter have the time to search for those flags. I am sure how to add 19518334Speter support for -soname shared_object_name. H.J. 19618334Speter 19718334Speter I took out %{v:%{!V:-V}}. It is too much :-(. They can use 19818334Speter -Wl,-V. 19918334Speter 20018334Speter When the -shared link option is used a final link is not being 20118334Speter done. */ 20218334Speter 20318334Speter/* If ELF is the default format, we should not use /lib/elf. */ 20418334Speter 20518334Speter#undef LINK_SPEC 20648743Sobrien#ifdef USE_GNULIBC_1 20718334Speter#ifndef LINUX_DEFAULT_ELF 20818334Speter#define LINK_SPEC "-m elf_i386 %{shared:-shared} \ 20918334Speter %{!shared: \ 21018334Speter %{!ibcs: \ 21118334Speter %{!static: \ 21218334Speter %{rdynamic:-export-dynamic} \ 21318334Speter %{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \ 21418334Speter %{!rpath:-rpath /lib/elf/}} %{static:-static}}}" 21518334Speter#else 21618334Speter#define LINK_SPEC "-m elf_i386 %{shared:-shared} \ 21718334Speter %{!shared: \ 21818334Speter %{!ibcs: \ 21918334Speter %{!static: \ 22018334Speter %{rdynamic:-export-dynamic} \ 22118334Speter %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \ 22218334Speter %{static:-static}}}" 22318334Speter#endif 22448743Sobrien#else /* not USE_GNULIBC_1 */ 22548743Sobrien#define LINK_SPEC "-m elf_i386 %{shared:-shared} \ 22648743Sobrien %{!shared: \ 22748743Sobrien %{!ibcs: \ 22848743Sobrien %{!static: \ 22948743Sobrien %{rdynamic:-export-dynamic} \ 23048743Sobrien %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \ 23148743Sobrien %{static:-static}}}" 23248743Sobrien#endif /* not USE_GNULIBC_1 */ 23318334Speter 23418334Speter/* Get perform_* macros to build libgcc.a. */ 23518334Speter#include "i386/perform.h" 236