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