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