2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / config / pa / som.h
blobae52cd0a30e26d5c95c41e3e1794720fc25dd487
1 /* Definitions for SOM assembler support.
2 Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* So we can conditionalize small amounts of code in pa.c or pa.md. */
22 #undef TARGET_SOM
23 #define TARGET_SOM 1
25 /* We do not use BINCL stabs in SOM.
26 ??? If it does not hurt, we probably should to avoid useless divergence
27 from other embedded stabs implementations. */
28 #undef DBX_USE_BINCL
30 /* We make the first line stab special to avoid adding several
31 gross hacks to GAS. */
32 #undef ASM_OUTPUT_SOURCE_LINE
33 #define ASM_OUTPUT_SOURCE_LINE(file, line, counter) \
34 { static tree last_function_decl = NULL; \
35 if (current_function_decl == last_function_decl) \
36 { \
37 rtx func = DECL_RTL (current_function_decl); \
38 const char *name = XSTR (XEXP (func, 0), 0); \
39 fprintf (file, "\t.stabn 68,0,%d,L$M%d-%s\nL$M%d:\n", \
40 line, counter, \
41 (* targetm.strip_name_encoding) (name), \
42 counter); \
43 } \
44 else \
45 fprintf (file, "\t.stabn 68,0,%d,0\n", line); \
46 last_function_decl = current_function_decl; \
49 /* gdb needs a null N_SO at the end of each file for scattered loading. */
51 #undef DBX_OUTPUT_MAIN_SOURCE_FILE_END
52 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
53 text_section (); \
54 fputs ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE); \
55 fprintf (FILE, \
56 "\t.stabs \"\",%d,0,0,L$text_end0000\nL$text_end0000:\n", N_SO)
58 /* Select a format to encode pointers in exception handling data. CODE
59 is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
60 true if the symbol may be affected by dynamic relocations. Because
61 the HP assembler does auto alignment, it is necessary to use
62 DW_EH_PE_aligned instead of the default DW_EH_PE_absptr. */
64 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
65 (TARGET_GAS ? DW_EH_PE_absptr : DW_EH_PE_aligned)
67 /* HPUX has a program 'chatr' to list the dependencies of dynamically
68 linked executables and shared libraries. */
69 #define LDD_SUFFIX "chatr"
70 /* Look for lines like "dynamic /usr/lib/X11R5/libX11.sl"
71 or "static /usr/lib/X11R5/libX11.sl".
73 HPUX 10.20 also has lines like "static branch prediction ..."
74 so we filter that out explicitly.
76 We also try to bound our search for libraries with marker
77 lines. What a pain. */
78 #define PARSE_LDD_OUTPUT(PTR) \
79 do { \
80 static int in_shlib_list = 0; \
81 while (*PTR == ' ') PTR++; \
82 if (strncmp (PTR, "shared library list:", \
83 sizeof ("shared library list:") - 1) == 0) \
84 { \
85 PTR = 0; \
86 in_shlib_list = 1; \
87 } \
88 else if (strncmp (PTR, "shared library binding:", \
89 sizeof ("shared library binding:") - 1) == 0)\
90 { \
91 PTR = 0; \
92 in_shlib_list = 0; \
93 } \
94 else if (strncmp (PTR, "static branch prediction disabled", \
95 sizeof ("static branch prediction disabled") - 1) == 0)\
96 { \
97 PTR = 0; \
98 in_shlib_list = 0; \
99 } \
100 else if (in_shlib_list \
101 && strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \
103 PTR += sizeof ("dynamic") - 1; \
104 while (*p == ' ') PTR++; \
106 else if (in_shlib_list \
107 && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \
109 PTR += sizeof ("static") - 1; \
110 while (*p == ' ') PTR++; \
112 else \
113 PTR = 0; \
114 } while (0)
116 /* Output the label for a function definition. */
117 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
118 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1) \
119 do { fprintf (FILE, ",ARGW%d=FR", (ARG0)); \
120 fprintf (FILE, ",ARGW%d=FU", (ARG1));} while (0)
121 #define DFMODE_RETURN_STRING ",RTNVAL=FU"
122 #define SFMODE_RETURN_STRING ",RTNVAL=FR"
123 #else
124 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1) \
125 do { fprintf (FILE, ",ARGW%d=FU", (ARG0)); \
126 fprintf (FILE, ",ARGW%d=FR", (ARG1));} while (0)
127 #define DFMODE_RETURN_STRING ",RTNVAL=FR"
128 #define SFMODE_RETURN_STRING ",RTNVAL=FU"
129 #endif
132 /* NAME refers to the function's name. If we are placing each function into
133 its own section, we need to switch to the section for this function. Note
134 that the section name will have a "." prefix. */
135 #define ASM_OUTPUT_FUNCTION_PREFIX(FILE, NAME) \
137 const char *name = (*targetm.strip_name_encoding) (NAME); \
138 if (TARGET_GAS && in_section == in_text) \
139 fputs ("\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE); \
140 else if (TARGET_GAS) \
141 fprintf (FILE, \
142 "\t.SUBSPA .%s\n", name); \
145 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
146 do { tree fntype = TREE_TYPE (TREE_TYPE (DECL)); \
147 tree tree_type = TREE_TYPE (DECL); \
148 tree parm; \
149 int i; \
150 if (TREE_PUBLIC (DECL) || TARGET_GAS) \
152 if (TREE_PUBLIC (DECL)) \
154 fputs ("\t.EXPORT ", FILE); \
155 assemble_name (FILE, NAME); \
156 fputs (",ENTRY,PRIV_LEV=3", FILE); \
158 else \
160 fputs ("\t.PARAM ", FILE); \
161 assemble_name (FILE, NAME); \
162 fputs (",PRIV_LEV=3", FILE); \
164 for (parm = DECL_ARGUMENTS (DECL), i = 0; parm && i < 4; \
165 parm = TREE_CHAIN (parm)) \
167 if (TYPE_MODE (DECL_ARG_TYPE (parm)) == SFmode \
168 && ! TARGET_SOFT_FLOAT) \
169 fprintf (FILE, ",ARGW%d=FR", i++); \
170 else if (TYPE_MODE (DECL_ARG_TYPE (parm)) == DFmode \
171 && ! TARGET_SOFT_FLOAT) \
173 if (i <= 2) \
175 if (i == 1) i++; \
176 ASM_DOUBLE_ARG_DESCRIPTORS (FILE, i++, i++); \
178 else \
179 break; \
181 else \
183 int arg_size = \
184 FUNCTION_ARG_SIZE (TYPE_MODE (DECL_ARG_TYPE (parm)),\
185 DECL_ARG_TYPE (parm)); \
186 /* Passing structs by invisible reference uses \
187 one general register. */ \
188 if (arg_size > 2 \
189 || TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) \
190 arg_size = 1; \
191 if (arg_size == 2 && i <= 2) \
193 if (i == 1) i++; \
194 fprintf (FILE, ",ARGW%d=GR", i++); \
195 fprintf (FILE, ",ARGW%d=GR", i++); \
197 else if (arg_size == 1) \
198 fprintf (FILE, ",ARGW%d=GR", i++); \
199 else \
200 i += arg_size; \
203 /* anonymous args */ \
204 if (TYPE_ARG_TYPES (tree_type) != 0 \
205 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
206 != void_type_node)) \
208 for (; i < 4; i++) \
209 fprintf (FILE, ",ARGW%d=GR", i); \
211 if (TYPE_MODE (fntype) == DFmode && ! TARGET_SOFT_FLOAT) \
212 fputs (DFMODE_RETURN_STRING, FILE); \
213 else if (TYPE_MODE (fntype) == SFmode && ! TARGET_SOFT_FLOAT) \
214 fputs (SFMODE_RETURN_STRING, FILE); \
215 else if (fntype != void_type_node) \
216 fputs (",RTNVAL=GR", FILE); \
217 fputs ("\n", FILE); \
218 }} while (0)
220 #define TARGET_ASM_FILE_START pa_som_file_start
222 /* Output before code. */
224 /* Supposedly the assembler rejects the command if there is no tab! */
225 #define TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$\n"
227 /* Output before read-only data. */
229 /* Supposedly the assembler rejects the command if there is no tab! */
230 #define READONLY_DATA_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$\n"
232 #define EXTRA_SECTIONS in_readonly_data
234 #define EXTRA_SECTION_FUNCTIONS \
235 extern void readonly_data (void); \
236 void \
237 readonly_data (void) \
239 if (in_section != in_readonly_data) \
241 in_section = in_readonly_data; \
242 fprintf (asm_out_file, "%s\n", READONLY_DATA_ASM_OP); \
246 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
247 which reference data within the $TEXT$ space (for example constant
248 strings in the $LIT$ subspace).
250 The assemblers (GAS and HP as) both have problems with handling
251 the difference of two symbols which is the other correct way to
252 reference constant data during PIC code generation.
254 So, there's no way to reference constant data which is in the
255 $TEXT$ space during PIC generation. Instead place all constant
256 data into the $PRIVATE$ subspace (this reduces sharing, but it
257 works correctly). */
259 #define READONLY_DATA_SECTION (flag_pic ? data_section : readonly_data)
261 /* Output before writable data. */
263 /* Supposedly the assembler rejects the command if there is no tab! */
264 #define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
266 /* Output before uninitialized data. */
268 #define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
270 /* We must not have a reference to an external symbol defined in a
271 shared library in a readonly section, else the SOM linker will
272 complain.
274 So, we force exception information into the data section. */
275 #define TARGET_ASM_EXCEPTION_SECTION data_section
277 /* This is how to output a command to make the user-level label named NAME
278 defined for reference from other files.
280 We call assemble_name, which in turn sets TREE_SYMBOL_REFERENCED. This
281 macro will restore the original value of TREE_SYMBOL_REFERENCED to avoid
282 placing useless function definitions in the output file.
284 Also note that the SOM based tools need the symbol imported as a CODE
285 symbol, while the ELF based tools require the symbol to be imported as
286 an ENTRY symbol. What a crock. */
288 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
289 do { int save_referenced; \
290 save_referenced = TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)); \
291 fputs ("\t.IMPORT ", FILE); \
292 assemble_name (FILE, NAME); \
293 if (FUNCTION_NAME_P (NAME)) \
294 fputs (",CODE\n", FILE); \
295 else \
296 fputs (",DATA\n", FILE); \
297 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)) = save_referenced; \
298 } while (0)
300 /* The bogus HP assembler requires ALL external references to be
301 "imported", even library calls. They look a bit different, so
302 here's this macro.
304 Also note not all libcall names are passed to pa_encode_section_info
305 (__main for example). To make sure all libcall names have section
306 info recorded in them, we do it here. We must also ensure that
307 we don't import a libcall that has been previously exported since
308 the HP assembler may change an ENTRY symbol to a CODE symbol. */
310 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
311 do { const char *name; \
312 tree id; \
314 if (!function_label_operand (RTL, VOIDmode)) \
315 hppa_encode_label (RTL); \
317 name = (*targetm.strip_name_encoding) (XSTR ((RTL), 0)); \
318 id = maybe_get_identifier (name); \
319 if (! id || ! TREE_SYMBOL_REFERENCED (id)) \
321 fputs ("\t.IMPORT ", FILE); \
322 assemble_name (FILE, XSTR ((RTL), 0)); \
323 fputs (",CODE\n", FILE); \
325 } while (0)
327 /* We want __gcc_plt_call to appear in every program built by
328 gcc, so we make a reference to it out of __main.
329 We use the asm statement to fool the optimizer into not
330 removing the dead (but important) initialization of
331 REFERENCE. */
333 #define DO_GLOBAL_DTORS_BODY \
334 do { \
335 extern void __gcc_plt_call (void); \
336 void (*reference)(void) = &__gcc_plt_call; \
337 func_ptr *p; \
338 __asm__ ("" : : "r" (reference)); \
339 for (p = __DTOR_LIST__ + 1; *p; ) \
340 (*p++) (); \
341 } while (0)
343 /* The .align directive in the HP assembler allows up to a 32 alignment. */
344 #define MAX_OFILE_ALIGNMENT 32768
346 /* The SOM linker hardcodes paths into binaries. As a result, dotdots
347 must be removed from library prefixes to prevent binaries from depending
348 on the location of the GCC tool directory. The downside is GCC
349 cannot be moved after installation using a symlink. */
350 #define ALWAYS_STRIP_DOTDOT 1
352 /* Aggregates with a single float or double field should be passed and
353 returned in the general registers. */
354 #define MEMBER_TYPE_FORCES_BLK(FIELD, MODE) (MODE==SFmode || MODE==DFmode)
356 /* If GAS supports weak, we can support weak when we have working linker
357 support for secondary definitions and are generating code for GAS. */
358 #ifdef HAVE_GAS_WEAK
359 #define SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS)
360 #else
361 #define SUPPORTS_WEAK 0
362 #endif
364 /* We can support one only if we support weak. */
365 #define SUPPORTS_ONE_ONLY SUPPORTS_WEAK
367 /* Use weak (secondary definitions) to make one only declarations. */
368 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
370 /* This is how we tell the assembler that a symbol is weak. The SOM
371 weak implementation uses the secondary definition (sdef) flag.
373 The behavior of sdef symbols is similar to ELF weak symbols in that
374 multiple definitions can occur without incurring a link error.
375 However, they differ in the following ways:
376 1) Undefined sdef symbols are not allowed.
377 2) The linker searches for undefined sdef symbols and will load an
378 archive library member to resolve an undefined sdef symbol.
379 3) The exported symbol from a shared library is a primary symbol
380 rather than a sdef symbol. Thus, more care is needed in the
381 ordering of libraries.
383 It appears that the linker discards extra copies of "weak" functions
384 when linking shared libraries, independent of whether or not they
385 are in their own section. In linking final executables, -Wl,-O can
386 be used to remove dead procedures. Thus, support for named sections
387 is not needed and in previous testing caused problems with various
388 HP tools. */
389 #define ASM_WEAKEN_LABEL(FILE,NAME) \
390 do { fputs ("\t.weak\t", FILE); \
391 assemble_name (FILE, NAME); \
392 fputc ('\n', FILE); \
393 if (! FUNCTION_NAME_P (NAME)) \
395 fputs ("\t.EXPORT ", FILE); \
396 assemble_name (FILE, NAME); \
397 fputs (",DATA\n", FILE); \
399 } while (0)
401 /* We can't handle weak aliases, and therefore can't support pragma weak.
402 Suppress the use of pragma weak in gthr-dce.h and gthr-posix.h. */
403 #define GTHREAD_USE_WEAK 0