OSDN Git Service

Shared library support.
[pf3gnuchains/gcc-fork.git] / gcc / config / sparc / sysv4.h
1 /* Target definitions for GNU compiler for Sparc running System V.4
2    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
3
4    Written by Ron Guilmette (rfg@netcom.com).
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
21
22 #include "sparc/sparc.h"
23
24 /* Undefine some symbols which are defined in "sparc.h" but which are
25    appropriate only for SunOS 4.x, and not for svr4.  */
26
27 #undef WORD_SWITCH_TAKES_ARG
28 #undef ASM_OUTPUT_SOURCE_LINE
29 #undef SELECT_SECTION
30 #undef ASM_DECLARE_FUNCTION_NAME
31 #undef TEXT_SECTION_ASM_OP
32 #undef DATA_SECTION_ASM_OP
33
34 #include "svr4.h"
35
36 /* Undefined some symbols which are defined in "svr4.h" but which are
37    appropriate only for typical svr4 systems, but not for the specific
38    case of svr4 running on a Sparc.  */
39
40 #undef INIT_SECTION_ASM_OP
41 #undef FINI_SECTION_ASM_OP
42 #undef CONST_SECTION_ASM_OP
43 #undef TYPE_OPERAND_FMT
44 #undef PUSHSECTION_FORMAT
45 #undef STRING_ASM_OP
46 #undef COMMON_ASM_OP
47 #undef SKIP_ASM_OP
48 #undef SET_ASM_OP       /* Has no equivalent.  See ASM_OUTPUT_DEF below.  */
49
50 /* Provide a set of pre-definitions and pre-assertions appropriate for
51    the Sparc running svr4.  __svr4__ is our extension.  */
52
53 #define CPP_PREDEFINES \
54   "-Dsparc -Dunix -D__svr4__ \
55    -Asystem(unix) -Asystem(svr4) -Acpu(sparc) -Amachine(sparc) \
56    -D__GCC_NEW_VARARGS__"
57
58 /* The native assembler can't compute differences between symbols in different
59    sections when generating pic code, so we must put jump tables in the
60    text section.  */
61 #define JUMP_TABLES_IN_TEXT_SECTION 1
62
63 /* Pass -K to the assembler when PIC.  */
64 #undef ASM_SPEC
65 #define ASM_SPEC \
66   "%{V} %{v:%{!V:-V}} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*} \
67    %{fpic:-K PIC} %{fPIC:-K PIC}"
68
69 /* Must use data section for relocatable constants when pic.  */
70 #undef SELECT_RTX_SECTION
71 #define SELECT_RTX_SECTION(MODE,RTX)            \
72 {                                               \
73   if (flag_pic && symbolic_operand (RTX))       \
74     data_section ();                            \
75   else                                          \
76     const_section ();                           \
77 }
78
79 /* This is the string used to begin an assembly language comment for the
80    Sparc/svr4 assembler.  */
81
82 #define ASM_COMMENT_START "!"
83
84 /* Define the names of various pseudo-op used by the Sparc/svr4 assembler.
85    Note that many of these are different from the typical pseudo-ops used
86    by most svr4 assemblers.  That is probably due to a (misguided?) attempt
87    to keep the Sparc/svr4 assembler somewhat compatible with the Sparc/SunOS
88    assembler.  */
89
90 #define STRING_ASM_OP           ".asciz"
91 #define COMMON_ASM_OP           ".common"
92 #define SKIP_ASM_OP             ".skip"
93 #define UNALIGNED_INT_ASM_OP    ".uaword"
94 #define UNALIGNED_SHORT_ASM_OP  ".uahalf"
95 #define PUSHSECTION_ASM_OP      ".pushsection"
96 #define POPSECTION_ASM_OP       ".popsection"
97
98 /* This is the format used to print the second operand of a .type pseudo-op
99    for the Sparc/svr4 assembler.  */
100
101 #define TYPE_OPERAND_FMT      "#%s"
102
103 /* This is the format used to print a .pushsection pseudo-op (and its operand)
104    for the Sparc/svr4 assembler.  */
105
106 #define PUSHSECTION_FORMAT      "\t%s\t\"%s\"\n"
107
108 #undef ASM_OUTPUT_CASE_LABEL
109 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE)             \
110 do { ASM_OUTPUT_ALIGN ((FILE), Pmode == SImode ? 2 : 3);                \
111      ASM_OUTPUT_INTERNAL_LABEL ((FILE), PREFIX, NUM);                   \
112    } while (0)
113
114 /* This is how to equate one symbol to another symbol.  The syntax used is
115    `SYM1=SYM2'.  Note that this is different from the way equates are done
116    with most svr4 assemblers, where the syntax is `.set SYM1,SYM2'.  */
117
118 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                              \
119  do {   fprintf ((FILE), "\t");                                         \
120         assemble_name (FILE, LABEL1);                                   \
121         fprintf (FILE, " = ");                                          \
122         assemble_name (FILE, LABEL2);                                   \
123         fprintf (FILE, "\n");                                           \
124   } while (0)
125
126 /* Define how the Sparc registers should be numbered for Dwarf output.
127    The numbering provided here should be compatible with the native
128    svr4 SDB debugger in the Sparc/svr4 reference port.  The numbering
129    is as follows:
130
131    Assembly name        gcc internal regno      Dwarf regno
132    ----------------------------------------------------------
133    g0-g7                0-7                     0-7
134    o0-o7                8-15                    8-15
135    l0-l7                16-23                   16-23
136    i0-i7                24-31                   24-31
137    f0-f31               32-63                   40-71
138 */
139
140 #define DBX_REGISTER_NUMBER(REGNO)                                      \
141   (((REGNO) < 32) ? (REGNO)                                             \
142    : ((REGNO) < 63) ? ((REGNO) + 8)                                     \
143    : (abort (), 0))
144
145 /* A set of symbol definitions for assembly pseudo-ops which will
146    get us switched to various sections of interest.  These are used
147    in all places where we simply want to switch to a section, and
148    *not* to push the previous section name onto the assembler's
149    section names stack (as we do often in dwarfout.c).  */
150
151 #define TEXT_SECTION_ASM_OP     ".section\t\".text\""
152 #define DATA_SECTION_ASM_OP     ".section\t\".data\""
153 #define BSS_SECTION_ASM_OP      ".section\t\".bss\""
154 #define CONST_SECTION_ASM_OP    ".section\t\".rodata\""
155 #define INIT_SECTION_ASM_OP     ".section\t\".init\""
156 #define FINI_SECTION_ASM_OP     ".section\t\".fini\""
157
158 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
159  
160    Note that we want to give these sections the SHF_WRITE attribute
161    because these sections will actually contain data (i.e. tables of
162    addresses of functions in the current root executable or shared library
163    file) and, in the case of a shared library, the relocatable addresses
164    will have to be properly resolved/relocated (and then written into) by
165    the dynamic linker when it actually attaches the given shared library
166    to the executing process.  (Note that on SVR4, you may wish to use the
167    `-z text' option to the ELF linker, when building a shared library, as
168    an additional check that you are doing everything right.  But if you do
169    use the `-z text' option when building a shared library, you will get
170    errors unless the .ctors and .dtors sections are marked as writable
171    via the SHF_WRITE attribute.)  */
172  
173 #undef CTORS_SECTION_ASM_OP
174 #define CTORS_SECTION_ASM_OP    ".section\t\".ctors\",#alloc,#write"
175 #undef DTORS_SECTION_ASM_OP
176 #define DTORS_SECTION_ASM_OP    ".section\t\".dtors\",#alloc,#write"
177
178 /* A C statement to output something to the assembler file to switch to section
179    NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
180    NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
181    define this macro in such cases.  */
182
183 #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \
184 do {                                                                    \
185   if (TREE_CODE (DECL) == FUNCTION_DECL)                                \
186     fprintf (FILE, ".section\t\"%s\",#alloc,#execinstr\n", (NAME));     \
187   else if (TREE_READONLY (DECL))                                        \
188     fprintf (FILE, ".section\t\"%s\",#alloc\n", (NAME));                \
189   else                                                                  \
190     fprintf (FILE, ".section\t\"%s\",#alloc,#write\n", (NAME));         \
191 } while (0)
192
193 /* If the host and target formats match, output the floats as hex.  */
194 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
195 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
196
197 /* This is how to output assembly code to define a `float' constant.
198    We always have to use a .long pseudo-op to do this because the native
199    SVR4 ELF assembler is buggy and it generates incorrect values when we
200    try to use the .float pseudo-op instead.  */
201
202 #undef ASM_OUTPUT_FLOAT
203 #define ASM_OUTPUT_FLOAT(FILE,VALUE)                                    \
204 do { long value;                                                        \
205      REAL_VALUE_TO_TARGET_SINGLE ((VALUE), value);                      \
206      fprintf((FILE), "\t.long\t0x%x\n", value);                         \
207    } while (0)
208
209 /* This is how to output assembly code to define a `double' constant.
210    We always have to use a pair of .long pseudo-ops to do this because
211    the native SVR4 ELF assembler is buggy and it generates incorrect
212    values when we try to use the the .double pseudo-op instead.  */
213
214 #undef ASM_OUTPUT_DOUBLE
215 #define ASM_OUTPUT_DOUBLE(FILE,VALUE)                                   \
216 do { long value[2];                                                     \
217      REAL_VALUE_TO_TARGET_DOUBLE ((VALUE), value);                      \
218      fprintf((FILE), "\t.long\t0x%x\n", value[0]);                      \
219      fprintf((FILE), "\t.long\t0x%x\n", value[1]);                      \
220    } while (0)
221
222 #endif /* word order matches */
223 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
224
225 /* This is how to output an assembler line defining a `long double'
226    constant.  */
227
228 #undef ASM_OUTPUT_LONG_DOUBLE
229 #define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE)                              \
230 do { long value[4];                                                     \
231      REAL_VALUE_TO_TARGET_LONG_DOUBLE ((VALUE), value);                 \
232      fprintf((FILE), "\t.long\t0x%x\n", value[0]);                      \
233      fprintf((FILE), "\t.long\t0x%x\n", value[1]);                      \
234      fprintf((FILE), "\t.long\t0x%x\n", value[2]);                      \
235      fprintf((FILE), "\t.long\t0x%x\n", value[3]);                      \
236    } while (0)
237 \f
238 /* Output assembler code to FILE to initialize this source file's
239    basic block profiling info, if that has not already been done.  */
240
241 #undef FUNCTION_BLOCK_PROFILER
242 #define FUNCTION_BLOCK_PROFILER(FILE, LABELNO)  \
243   do { \
244     if (TARGET_MEDANY) \
245       fprintf (FILE, "\tsethi %%hi(.LLPBX0),%%o0\n\tor %%0,%%lo(.LLPBX0),%%o0\n\tld [%s+%%o0],%%o1\n\ttst %%o1\n\tbne .LLPY%d\n\tadd %%o0,%s,%%o0\n\tcall __bb_init_func\n\tnop\nLPY%d:\n", \
246                MEDANY_BASE_REG, (LABELNO), MEDANY_BASE_REG, (LABELNO)); \
247     else \
248       fprintf (FILE, "\tsethi %%hi(.LLPBX0),%%o0\n\tld [%%lo(.LLPBX0)+%%o0],%%o1\n\ttst %%o1\n\tbne LPY%d\n\tadd %%o0,%%lo(.LLPBX0),%%o0\n\tcall __bb_init_func\n\tnop\nLPY%d:\n", \
249                (LABELNO), (LABELNO)); \
250   } while (0)
251
252 /* Output assembler code to FILE to increment the entry-count for
253    the BLOCKNO'th basic block in this source file.  */
254
255 #undef BLOCK_PROFILER
256 #define BLOCK_PROFILER(FILE, BLOCKNO) \
257 { \
258   int blockn = (BLOCKNO); \
259   if (TARGET_MEDANY) \
260     fprintf (FILE, "\tsethi %%hi(.LLPBX2+%d),%%g1\n\tor %%g1,%%lo(.LLPBX2+%d),%%g1\n\tld [%%g1+%s],%%g2\n\tadd %%g2,1,%%g2\n\tst %%g2,[%%g1+%s]\n", \
261              4 * blockn, 4 * blockn, MEDANY_BASE_REG, MEDANY_BASE_REG); \
262   else \
263     fprintf (FILE, "\tsethi %%hi(.LLPBX2+%d),%%g1\n\tld [%%lo(.LLPBX2+%d)+%%g1],%%g2\n\
264 \tadd %%g2,1,%%g2\n\tst %%g2,[%%lo(.LLPBX2+%d)+%%g1]\n", \
265              4 * blockn, 4 * blockn, 4 * blockn); \
266 }
267