1 /* Definitions for SOM assembler support.
2 Copyright (C) 1999, 2001, 2002, 2003, 2004 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)
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. */
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. */
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) \
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", \
41 (* targetm.strip_name_encoding) (name), \
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) \
54 fputs ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", 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) \
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) \
88 else if (strncmp (PTR, "shared library binding:", \
89 sizeof ("shared library binding:") - 1) == 0)\
94 else if (strncmp (PTR, "static branch prediction disabled", \
95 sizeof ("static branch prediction disabled") - 1) == 0)\
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++; \
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"
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"
132 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
133 do { tree fntype = TREE_TYPE (TREE_TYPE (DECL)); \
134 tree tree_type = TREE_TYPE (DECL); \
137 if (TREE_PUBLIC (DECL) || TARGET_GAS) \
139 if (TREE_PUBLIC (DECL)) \
141 fputs ("\t.EXPORT ", FILE); \
142 assemble_name (FILE, NAME); \
143 fputs (",ENTRY,PRIV_LEV=3", FILE); \
147 fputs ("\t.PARAM ", FILE); \
148 assemble_name (FILE, NAME); \
149 fputs (",PRIV_LEV=3", FILE); \
151 for (parm = DECL_ARGUMENTS (DECL), i = 0; parm && i < 4; \
152 parm = TREE_CHAIN (parm)) \
154 if (TYPE_MODE (DECL_ARG_TYPE (parm)) == SFmode \
155 && ! TARGET_SOFT_FLOAT) \
156 fprintf (FILE, ",ARGW%d=FR", i++); \
157 else if (TYPE_MODE (DECL_ARG_TYPE (parm)) == DFmode \
158 && ! TARGET_SOFT_FLOAT) \
163 ASM_DOUBLE_ARG_DESCRIPTORS (FILE, i++, i++); \
171 FUNCTION_ARG_SIZE (TYPE_MODE (DECL_ARG_TYPE (parm)),\
172 DECL_ARG_TYPE (parm)); \
173 /* Passing structs by invisible reference uses \
174 one general register. */ \
176 || TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) \
178 if (arg_size == 2 && i <= 2) \
181 fprintf (FILE, ",ARGW%d=GR", i++); \
182 fprintf (FILE, ",ARGW%d=GR", i++); \
184 else if (arg_size == 1) \
185 fprintf (FILE, ",ARGW%d=GR", i++); \
190 /* anonymous args */ \
191 if (TYPE_ARG_TYPES (tree_type) != 0 \
192 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
193 != void_type_node)) \
196 fprintf (FILE, ",ARGW%d=GR", i); \
198 if (TYPE_MODE (fntype) == DFmode && ! TARGET_SOFT_FLOAT) \
199 fputs (DFMODE_RETURN_STRING, FILE); \
200 else if (TYPE_MODE (fntype) == SFmode && ! TARGET_SOFT_FLOAT) \
201 fputs (SFMODE_RETURN_STRING, FILE); \
202 else if (fntype != void_type_node) \
203 fputs (",RTNVAL=GR", FILE); \
204 fputs ("\n", FILE); \
207 #define TARGET_ASM_FILE_START pa_som_file_start
209 /* Select and return a TEXT_SECTION_ASM_OP string. */
210 #define TEXT_SECTION_ASM_OP som_text_section_asm_op ()
212 /* Output before code in the default text section. */
213 #define DEFAULT_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$"
215 /* Output before text in a new subspace. This allows the linker to
216 place stubs between functions. */
217 #define NEW_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$"
219 /* Output before text in a new one-only subspace. */
220 #define ONE_ONLY_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\
221 \t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,SORT=24,COMDAT"
223 /* Output before read-only data. */
224 #define READONLY_DATA_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$\n"
226 /* Output before one-only readonly data. We make readonly data one only
227 by creating a new $LIT$ subspace in $TEXT$ with the comdat flag. */
228 #define ONE_ONLY_READONLY_DATA_SECTION_ASM_OP "\t.SPACE $TEXT$\n\
229 \t.NSUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=16,COMDAT\n"
231 /* Output before writable data. */
232 #define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
234 /* Output before one-only data. We make data one only by creating
235 a new $DATA$ subspace in $PRIVATE$ with the comdat flag. */
236 #define ONE_ONLY_DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\
237 \t.NSUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=24,COMDAT\n"
239 /* Output before uninitialized data. */
240 #define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
242 #define EXTRA_SECTIONS \
244 in_one_only_readonly_data, \
247 #define EXTRA_SECTION_FUNCTIONS \
248 READONLY_DATA_FUNCTION \
249 ONE_ONLY_READONLY_DATA_SECTION_FUNCTION \
250 ONE_ONLY_DATA_SECTION_FUNCTION \
251 FORGET_SECTION_FUNCTION
253 #define READONLY_DATA_FUNCTION \
255 readonly_data (void) \
257 if (in_section != in_readonly_data) \
259 in_section = in_readonly_data; \
260 fputs (READONLY_DATA_ASM_OP, asm_out_file); \
264 #define ONE_ONLY_READONLY_DATA_SECTION_FUNCTION \
266 one_only_readonly_data_section (void) \
268 in_section = in_one_only_readonly_data; \
269 fputs (ONE_ONLY_READONLY_DATA_SECTION_ASM_OP, asm_out_file); \
272 #define ONE_ONLY_DATA_SECTION_FUNCTION \
274 one_only_data_section (void) \
276 in_section = in_one_only_data; \
277 fputs (ONE_ONLY_DATA_SECTION_ASM_OP, asm_out_file); \
280 #define FORGET_SECTION_FUNCTION \
282 forget_section (void) \
284 in_section = no_section; \
287 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
288 which reference data within the $TEXT$ space (for example constant
289 strings in the $LIT$ subspace).
291 The assemblers (GAS and HP as) both have problems with handling
292 the difference of two symbols which is the other correct way to
293 reference constant data during PIC code generation.
295 So, there's no way to reference constant data which is in the
296 $TEXT$ space during PIC generation. Instead place all constant
297 data into the $PRIVATE$ subspace (this reduces sharing, but it
299 #define READONLY_DATA_SECTION (flag_pic ? data_section : readonly_data)
301 /* We must not have a reference to an external symbol defined in a
302 shared library in a readonly section, else the SOM linker will
305 So, we force exception information into the data section. */
306 #define TARGET_ASM_EXCEPTION_SECTION data_section
308 /* This is how to output a command to make the user-level label named NAME
309 defined for reference from other files.
311 We call assemble_name, which in turn sets TREE_SYMBOL_REFERENCED. This
312 macro will restore the original value of TREE_SYMBOL_REFERENCED to avoid
313 placing useless function definitions in the output file.
315 Also note that the SOM based tools need the symbol imported as a CODE
316 symbol, while the ELF based tools require the symbol to be imported as
317 an ENTRY symbol. What a crock. */
319 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
320 do { int save_referenced; \
321 save_referenced = TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)); \
322 fputs ("\t.IMPORT ", FILE); \
323 assemble_name (FILE, NAME); \
324 if (FUNCTION_NAME_P (NAME)) \
325 fputs (",CODE\n", FILE); \
327 fputs (",DATA\n", FILE); \
328 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)) = save_referenced; \
331 /* The bogus HP assembler requires ALL external references to be
332 "imported", even library calls. They look a bit different, so
335 Also note not all libcall names are passed to pa_encode_section_info
336 (__main for example). To make sure all libcall names have section
337 info recorded in them, we do it here. We must also ensure that
338 we don't import a libcall that has been previously exported since
339 the HP assembler may change an ENTRY symbol to a CODE symbol. */
341 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
342 do { const char *name; \
345 if (!function_label_operand (RTL, VOIDmode)) \
346 hppa_encode_label (RTL); \
348 name = (*targetm.strip_name_encoding) (XSTR ((RTL), 0)); \
349 id = maybe_get_identifier (name); \
350 if (! id || ! TREE_SYMBOL_REFERENCED (id)) \
352 fputs ("\t.IMPORT ", FILE); \
353 assemble_name (FILE, XSTR ((RTL), 0)); \
354 fputs (",CODE\n", FILE); \
358 /* We want __gcc_plt_call to appear in every program built by
359 gcc, so we make a reference to it out of __main.
360 We use the asm statement to fool the optimizer into not
361 removing the dead (but important) initialization of
364 #define DO_GLOBAL_DTORS_BODY \
366 extern void __gcc_plt_call (void); \
367 void (*reference)(void) = &__gcc_plt_call; \
369 __asm__ ("" : : "r" (reference)); \
370 for (p = __DTOR_LIST__ + 1; *p; ) \
374 /* The .align directive in the HP assembler allows up to a 32 alignment. */
375 #define MAX_OFILE_ALIGNMENT 32768
377 /* The SOM linker hardcodes paths into binaries. As a result, dotdots
378 must be removed from library prefixes to prevent binaries from depending
379 on the location of the GCC tool directory. The downside is GCC
380 cannot be moved after installation using a symlink. */
381 #define ALWAYS_STRIP_DOTDOT 1
383 /* Aggregates with a single float or double field should be passed and
384 returned in the general registers. */
385 #define MEMBER_TYPE_FORCES_BLK(FIELD, MODE) (MODE==SFmode || MODE==DFmode)
387 /* If GAS supports weak, we can support weak when we have working linker
388 support for secondary definitions and are generating code for GAS. */
390 #define SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS)
392 #define SUPPORTS_WEAK 0
395 /* We can support one only if we support weak. */
396 #define SUPPORTS_ONE_ONLY SUPPORTS_WEAK
398 /* Use weak (secondary definitions) to make one only declarations. */
399 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
401 /* This is how we tell the assembler that a symbol is weak. The SOM
402 weak implementation uses the secondary definition (sdef) flag.
404 The behavior of sdef symbols is similar to ELF weak symbols in that
405 multiple definitions can occur without incurring a link error.
406 However, they differ in the following ways:
407 1) Undefined sdef symbols are not allowed.
408 2) The linker searches for undefined sdef symbols and will load an
409 archive library member to resolve an undefined sdef symbol.
410 3) The exported symbol from a shared library is a primary symbol
411 rather than a sdef symbol. Thus, more care is needed in the
412 ordering of libraries.
414 It appears that the linker discards extra copies of "weak" functions
415 when linking shared libraries, independent of whether or not they
416 are in their own section. In linking final executables, -Wl,-O can
417 be used to remove dead procedures. Thus, support for named sections
418 is not needed and in previous testing caused problems with various
420 #define ASM_WEAKEN_LABEL(FILE,NAME) \
421 do { fputs ("\t.weak\t", FILE); \
422 assemble_name (FILE, NAME); \
423 fputc ('\n', FILE); \
424 if (! FUNCTION_NAME_P (NAME)) \
426 fputs ("\t.EXPORT ", FILE); \
427 assemble_name (FILE, NAME); \
428 fputs (",DATA\n", FILE); \
432 /* We can't handle weak aliases, and therefore can't support pragma weak.
433 Suppress the use of pragma weak in gthr-dce.h and gthr-posix.h. */
434 #define GTHREAD_USE_WEAK 0