1/* Definitions for SOM assembler support. 2 Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, 3 Inc. 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GCC is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GCC; see the file COPYING. If not, write to 19the Free Software Foundation, 51 Franklin Street, Fifth Floor, 20Boston, MA 02110-1301, USA. */ 21 22/* So we can conditionalize small amounts of code in pa.c or pa.md. */ 23#undef TARGET_SOM 24#define TARGET_SOM 1 25 26/* We do not use BINCL stabs in SOM. 27 ??? If it does not hurt, we probably should to avoid useless divergence 28 from other embedded stabs implementations. */ 29#undef DBX_USE_BINCL 30 31#define DBX_LINES_FUNCTION_RELATIVE 1 32 33/* gdb needs a null N_SO at the end of each file for scattered loading. */ 34 35#define DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END 36 37/* HPUX has a program 'chatr' to list the dependencies of dynamically 38 linked executables and shared libraries. */ 39#define LDD_SUFFIX "chatr" 40/* Look for lines like "dynamic /usr/lib/X11R5/libX11.sl" 41 or "static /usr/lib/X11R5/libX11.sl". 42 43 HPUX 10.20 also has lines like "static branch prediction ..." 44 so we filter that out explicitly. 45 46 We also try to bound our search for libraries with marker 47 lines. What a pain. */ 48#define PARSE_LDD_OUTPUT(PTR) \ 49do { \ 50 static int in_shlib_list = 0; \ 51 while (*PTR == ' ') PTR++; \ 52 if (strncmp (PTR, "shared library list:", \ 53 sizeof ("shared library list:") - 1) == 0) \ 54 { \ 55 PTR = 0; \ 56 in_shlib_list = 1; \ 57 } \ 58 else if (strncmp (PTR, "shared library binding:", \ 59 sizeof ("shared library binding:") - 1) == 0)\ 60 { \ 61 PTR = 0; \ 62 in_shlib_list = 0; \ 63 } \ 64 else if (strncmp (PTR, "static branch prediction disabled", \ 65 sizeof ("static branch prediction disabled") - 1) == 0)\ 66 { \ 67 PTR = 0; \ 68 in_shlib_list = 0; \ 69 } \ 70 else if (in_shlib_list \ 71 && strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \ 72 { \ 73 PTR += sizeof ("dynamic") - 1; \ 74 while (*p == ' ') PTR++; \ 75 } \ 76 else if (in_shlib_list \ 77 && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \ 78 { \ 79 PTR += sizeof ("static") - 1; \ 80 while (*p == ' ') PTR++; \ 81 } \ 82 else \ 83 PTR = 0; \ 84} while (0) 85 86/* Output the label for a function definition. */ 87#ifndef HP_FP_ARG_DESCRIPTOR_REVERSED 88#define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1) \ 89 do { fprintf (FILE, ",ARGW%d=FR", (ARG0)); \ 90 fprintf (FILE, ",ARGW%d=FU", (ARG1));} while (0) 91#define DFMODE_RETURN_STRING ",RTNVAL=FU" 92#define SFMODE_RETURN_STRING ",RTNVAL=FR" 93#else 94#define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1) \ 95 do { fprintf (FILE, ",ARGW%d=FU", (ARG0)); \ 96 fprintf (FILE, ",ARGW%d=FR", (ARG1));} while (0) 97#define DFMODE_RETURN_STRING ",RTNVAL=FR" 98#define SFMODE_RETURN_STRING ",RTNVAL=FU" 99#endif 100 101 102#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ 103 do { tree fntype = TREE_TYPE (TREE_TYPE (DECL)); \ 104 tree tree_type = TREE_TYPE (DECL); \ 105 tree parm; \ 106 int i; \ 107 if (TREE_PUBLIC (DECL) || TARGET_GAS) \ 108 { \ 109 if (TREE_PUBLIC (DECL)) \ 110 { \ 111 fputs ("\t.EXPORT ", FILE); \ 112 assemble_name (FILE, NAME); \ 113 fputs (",ENTRY,PRIV_LEV=3", FILE); \ 114 } \ 115 else \ 116 { \ 117 fputs ("\t.PARAM ", FILE); \ 118 assemble_name (FILE, NAME); \ 119 fputs (",PRIV_LEV=3", FILE); \ 120 } \ 121 for (parm = DECL_ARGUMENTS (DECL), i = 0; parm && i < 4; \ 122 parm = TREE_CHAIN (parm)) \ 123 { \ 124 if (TYPE_MODE (DECL_ARG_TYPE (parm)) == SFmode \ 125 && ! TARGET_SOFT_FLOAT) \ 126 fprintf (FILE, ",ARGW%d=FR", i++); \ 127 else if (TYPE_MODE (DECL_ARG_TYPE (parm)) == DFmode \ 128 && ! TARGET_SOFT_FLOAT) \ 129 { \ 130 if (i <= 2) \ 131 { \ 132 if (i == 1) i++; \ 133 ASM_DOUBLE_ARG_DESCRIPTORS (FILE, i++, i++); \ 134 } \ 135 else \ 136 break; \ 137 } \ 138 else \ 139 { \ 140 int arg_size = \ 141 FUNCTION_ARG_SIZE (TYPE_MODE (DECL_ARG_TYPE (parm)),\ 142 DECL_ARG_TYPE (parm)); \ 143 /* Passing structs by invisible reference uses \ 144 one general register. */ \ 145 if (arg_size > 2 \ 146 || TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) \ 147 arg_size = 1; \ 148 if (arg_size == 2 && i <= 2) \ 149 { \ 150 if (i == 1) i++; \ 151 fprintf (FILE, ",ARGW%d=GR", i++); \ 152 fprintf (FILE, ",ARGW%d=GR", i++); \ 153 } \ 154 else if (arg_size == 1) \ 155 fprintf (FILE, ",ARGW%d=GR", i++); \ 156 else \ 157 i += arg_size; \ 158 } \ 159 } \ 160 /* anonymous args */ \ 161 if (TYPE_ARG_TYPES (tree_type) != 0 \ 162 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\ 163 != void_type_node)) \ 164 { \ 165 for (; i < 4; i++) \ 166 fprintf (FILE, ",ARGW%d=GR", i); \ 167 } \ 168 if (TYPE_MODE (fntype) == DFmode && ! TARGET_SOFT_FLOAT) \ 169 fputs (DFMODE_RETURN_STRING, FILE); \ 170 else if (TYPE_MODE (fntype) == SFmode && ! TARGET_SOFT_FLOAT) \ 171 fputs (SFMODE_RETURN_STRING, FILE); \ 172 else if (fntype != void_type_node) \ 173 fputs (",RTNVAL=GR", FILE); \ 174 fputs ("\n", FILE); \ 175 }} while (0) 176 177#define TARGET_ASM_FILE_START pa_som_file_start 178 179/* String to output before text. */ 180#define TEXT_SECTION_ASM_OP som_text_section_asm_op () 181 182/* String to output before writable data. */ 183#define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n" 184 185/* String to output before uninitialized data. */ 186#define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n" 187 188/* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups 189 which reference data within the $TEXT$ space (for example constant 190 strings in the $LIT$ subspace). 191 192 The assemblers (GAS and HP as) both have problems with handling 193 the difference of two symbols which is the other correct way to 194 reference constant data during PIC code generation. 195 196 So, there's no way to reference constant data which is in the 197 $TEXT$ space during PIC generation. Instead place all constant 198 data into the $PRIVATE$ subspace (this reduces sharing, but it 199 works correctly). */ 200#define READONLY_DATA_SECTION \ 201 (flag_pic ? data_section : som_readonly_data_section) 202 203/* We must not have a reference to an external symbol defined in a 204 shared library in a readonly section, else the SOM linker will 205 complain. 206 207 So, we force exception information into the data section. */ 208#define TARGET_ASM_EXCEPTION_SECTION data_section 209 210/* This is how to output a command to make the user-level label 211 named NAME defined for reference from other files. We use 212 assemble_name_raw instead of assemble_name since a symbol in 213 a .IMPORT directive that isn't otherwise referenced is not 214 placed in the symbol table of the assembled object. 215 216 Failure to import a function reference can cause the HP linker 217 to segmentation fault! 218 219 Note that the SOM based tools need the symbol imported as a 220 CODE symbol, while the ELF based tools require the symbol to 221 be imported as an ENTRY symbol. */ 222 223#define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \ 224 pa_hpux_asm_output_external ((FILE), (DECL), (NAME)) 225#define ASM_OUTPUT_EXTERNAL_REAL(FILE, DECL, NAME) \ 226 do { fputs ("\t.IMPORT ", FILE); \ 227 assemble_name_raw (FILE, NAME); \ 228 if (FUNCTION_NAME_P (NAME)) \ 229 fputs (",CODE\n", FILE); \ 230 else \ 231 fputs (",DATA\n", FILE); \ 232 } while (0) 233 234/* The bogus HP assembler requires ALL external references to be 235 "imported", even library calls. They look a bit different, so 236 here's this macro. 237 238 Also note not all libcall names are passed to pa_encode_section_info 239 (__main for example). To make sure all libcall names have section 240 info recorded in them, we do it here. 241 242 We must also ensure that a libcall that has been previously 243 exported is not subsequently imported since the HP assembler may 244 change the type from an ENTRY to a CODE symbol. This would make 245 the symbol local. We are forced to use the identifier node 246 associated with the real assembler name for this check as the 247 symbol_ref available in ASM_DECLARE_FUNCTION_NAME is not the 248 same as the one used here. As a result, we can't use flags 249 in the symbol_ref for this check. The identifier check assumes 250 assemble_external_libcall is called before the symbol is used. */ 251 252#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \ 253 do { const char *name; \ 254 tree id; \ 255 \ 256 if (!function_label_operand (RTL, VOIDmode)) \ 257 hppa_encode_label (RTL); \ 258 \ 259 name = targetm.strip_name_encoding (XSTR ((RTL), 0)); \ 260 id = maybe_get_identifier (name); \ 261 if (!id || !TREE_SYMBOL_REFERENCED (id)) \ 262 { \ 263 fputs ("\t.IMPORT ", FILE); \ 264 assemble_name_raw (FILE, XSTR ((RTL), 0)); \ 265 fputs (",CODE\n", FILE); \ 266 } \ 267 } while (0) 268 269/* We want __gcc_plt_call to appear in every program built by 270 gcc, so we make a reference to it out of __main. 271 We use the asm statement to fool the optimizer into not 272 removing the dead (but important) initialization of 273 REFERENCE. */ 274 275#define DO_GLOBAL_DTORS_BODY \ 276do { \ 277 extern void __gcc_plt_call (void); \ 278 void (*reference)(void) = &__gcc_plt_call; \ 279 func_ptr *p; \ 280 __asm__ ("" : : "r" (reference)); \ 281 for (p = __DTOR_LIST__ + 1; *p; ) \ 282 (*p++) (); \ 283} while (0) 284 285/* This macro specifies the biggest alignment supported by the object 286 file format of this machine. 287 288 The .align directive in the HP assembler allows alignments up to 4096 289 bytes. However, the maximum alignment of a global common symbol is 8 290 bytes for objects smaller than the page size (4096 bytes). For larger 291 objects, the linker provides an alignment of 32 bytes. Unfortunately, 292 this macro doesn't provide a mechanism to test for common symbols. */ 293#define MAX_OFILE_ALIGNMENT 32768 294 295/* The SOM linker hardcodes paths into binaries. As a result, dotdots 296 must be removed from library prefixes to prevent binaries from depending 297 on the location of the GCC tool directory. The downside is GCC 298 cannot be moved after installation using a symlink. */ 299#define ALWAYS_STRIP_DOTDOT 1 300 301/* If GAS supports weak, we can support weak when we have working linker 302 support for secondary definitions and are generating code for GAS. */ 303#ifdef HAVE_GAS_WEAK 304#define SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS) 305#else 306#define SUPPORTS_WEAK 0 307#endif 308 309/* CVS GAS as of 4/28/04 supports a comdat parameter for the .nsubspa 310 directive. This provides one-only linkage semantics even though we 311 don't have weak support. */ 312#ifdef HAVE_GAS_NSUBSPA_COMDAT 313#define SUPPORTS_SOM_COMDAT (TARGET_GAS) 314#else 315#define SUPPORTS_SOM_COMDAT 0 316#endif 317 318/* We can support one only if we support weak or comdat. */ 319#define SUPPORTS_ONE_ONLY (SUPPORTS_WEAK || SUPPORTS_SOM_COMDAT) 320 321/* We use DECL_COMMON for uninitialized one-only variables as we don't 322 have linkonce .bss. We use SOM secondary definitions or comdat for 323 initialized variables and functions. */ 324#define MAKE_DECL_ONE_ONLY(DECL) \ 325 do { \ 326 if (TREE_CODE (DECL) == VAR_DECL \ 327 && (DECL_INITIAL (DECL) == 0 \ 328 || DECL_INITIAL (DECL) == error_mark_node)) \ 329 DECL_COMMON (DECL) = 1; \ 330 else if (SUPPORTS_WEAK) \ 331 DECL_WEAK (DECL) = 1; \ 332 } while (0) 333 334/* This is how we tell the assembler that a symbol is weak. The SOM 335 weak implementation uses the secondary definition (sdef) flag. 336 337 The behavior of sdef symbols is similar to ELF weak symbols in that 338 multiple definitions can occur without incurring a link error. 339 However, they differ in the following ways: 340 1) Undefined sdef symbols are not allowed. 341 2) The linker searches for undefined sdef symbols and will load an 342 archive library member to resolve an undefined sdef symbol. 343 3) The exported symbol from a shared library is a primary symbol 344 rather than a sdef symbol. Thus, more care is needed in the 345 ordering of libraries. 346 347 It appears that the linker discards extra copies of "weak" functions 348 when linking shared libraries, independent of whether or not they 349 are in their own section. In linking final executables, -Wl,-O can 350 be used to remove dead procedures. Thus, support for named sections 351 is not needed and in previous testing caused problems with various 352 HP tools. */ 353#define ASM_WEAKEN_LABEL(FILE,NAME) \ 354 do { fputs ("\t.weak\t", FILE); \ 355 assemble_name (FILE, NAME); \ 356 fputc ('\n', FILE); \ 357 targetm.asm_out.globalize_label (FILE, NAME); \ 358 } while (0) 359 360/* We can't handle weak aliases, and therefore can't support pragma weak. 361 Suppress the use of pragma weak in gthr-dce.h and gthr-posix.h. */ 362#define GTHREAD_USE_WEAK 0 363 364/* Shared library suffix. Collect2 strips the version string after 365 this suffix when generating constructor/destructor names. */ 366#define SHLIB_SUFFIX ".sl" 367