1 /* Definitions of target machine for GNU compiler, for DEC Alpha w/ELF.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Richard Henderson (rth@tamu.edu).
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #undef OBJECT_FORMAT_COFF
24 #define OBJECT_FORMAT_ELF
26 #define DBX_DEBUGGING_INFO
27 #define DWARF2_DEBUGGING_INFO
29 #undef PREFERRED_DEBUGGING_TYPE
30 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
35 #define CC1_SPEC "%{G*}"
38 #define ASM_SPEC "%{G*} %{relax:-relax} %{!gstabs*:-no-mdebug}%{gstabs*:-mdebug}"
41 #define LINK_SPEC "-m elf64alpha %{G*} %{relax:-relax} \
42 %{O*:-O3} %{!O*:-O1} \
46 %{rdynamic:-export-dynamic} \
47 %{!dynamic-linker:-dynamic-linker %(elf_dynamic_linker)}} \
50 /* Output at beginning of assembler file. */
52 #define ASM_FILE_START(FILE) \
54 if (write_symbols == DBX_DEBUG) \
56 alpha_write_verstamp (FILE); \
57 output_file_directive (FILE, main_input_filename); \
59 fprintf (FILE, "\t.set noat\n"); \
60 fprintf (FILE, "\t.set noreorder\n"); \
61 if (TARGET_EXPLICIT_RELOCS) \
62 fprintf (FILE, "\t.set nomacro\n"); \
63 if (TARGET_BWX | TARGET_MAX | TARGET_FIX | TARGET_CIX) \
65 fprintf (FILE, "\t.arch %s\n", \
66 (TARGET_CPU_EV6 ? "ev6" \
67 : TARGET_MAX ? "pca56" : "ev56")); \
72 #define IDENT_ASM_OP "\t.ident\t"
74 /* Allow #sccs in preprocessor. */
75 #define SCCS_DIRECTIVE
77 /* Output #ident as a .ident. */
78 #undef ASM_OUTPUT_IDENT
79 #define ASM_OUTPUT_IDENT(FILE, NAME) \
80 fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME);
82 /* This is how to allocate empty space in some section. The .zero
83 pseudo-op is used for this on most svr4 assemblers. */
86 #define SKIP_ASM_OP "\t.zero\t"
88 #undef ASM_OUTPUT_SKIP
89 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
90 fprintf (FILE, "%s%u\n", SKIP_ASM_OP, (SIZE))
92 /* Output the label which precedes a jumptable. Note that for all svr4
93 systems where we actually generate jumptables (which is to say every
94 svr4 target except i386, where we use casesi instead) we put the jump-
95 tables into the .rodata section and since other stuff could have been
96 put into the .rodata section prior to any given jumptable, we have to
97 make sure that the location counter for the .rodata section gets pro-
98 perly re-aligned prior to the actual beginning of the jump table. */
101 #define ALIGN_ASM_OP "\t.align\t"
103 #ifndef ASM_OUTPUT_BEFORE_CASE_LABEL
104 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \
105 ASM_OUTPUT_ALIGN ((FILE), 2);
108 #undef ASM_OUTPUT_CASE_LABEL
109 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \
111 ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \
112 ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); \
115 /* The standard SVR4 assembler seems to require that certain builtin
116 library routines (e.g. .udiv) be explicitly declared as .globl
117 in each assembly file where they are referenced. */
119 #undef ASM_OUTPUT_EXTERNAL_LIBCALL
120 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
121 ASM_GLOBALIZE_LABEL (FILE, XSTR (FUN, 0))
123 /* This says how to output assembler code to declare an
124 uninitialized external linkage data object. Under SVR4,
125 the linker seems to want the alignment of data objects
126 to depend on their types. We do exactly that here. */
129 #define COMMON_ASM_OP "\t.comm\t"
131 #undef ASM_OUTPUT_ALIGNED_COMMON
132 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
134 fprintf ((FILE), "%s", COMMON_ASM_OP); \
135 assemble_name ((FILE), (NAME)); \
136 fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \
139 /* This says how to output assembler code to declare an
140 uninitialized internal linkage data object. Under SVR4,
141 the linker seems to want the alignment of data objects
142 to depend on their types. We do exactly that here. */
144 #undef ASM_OUTPUT_ALIGNED_LOCAL
145 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
147 if ((SIZE) <= g_switch_value) \
151 fprintf (FILE, "%s", TYPE_ASM_OP); \
152 assemble_name (FILE, NAME); \
154 fprintf (FILE, TYPE_OPERAND_FMT, "object"); \
156 if (!flag_inhibit_size_directive) \
158 fprintf (FILE, "%s", SIZE_ASM_OP); \
159 assemble_name (FILE, NAME); \
160 fprintf (FILE, ",%d\n", (SIZE)); \
162 ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
163 ASM_OUTPUT_LABEL(FILE, NAME); \
164 ASM_OUTPUT_SKIP((FILE), (SIZE)); \
167 /* This is the pseudo-op used to generate a 64-bit word of data with a
168 specific value in some section. */
171 #define INT_ASM_OP "\t.quad\t"
173 /* Biggest alignment supported by the object file format of this
174 machine. Use this macro to limit the alignment which can be
175 specified using the `__attribute__ ((aligned (N)))' construct. If
176 not defined, the default value is `BIGGEST_ALIGNMENT'.
178 This value is really 2^63. Since gcc figures the alignment in bits,
179 we could only potentially get to 2^60 on suitible hosts. Due to other
180 considerations in varasm, we must restrict this to what fits in an int. */
182 #undef MAX_OFILE_ALIGNMENT
183 #define MAX_OFILE_ALIGNMENT \
184 (1 << (HOST_BITS_PER_INT < 64 ? HOST_BITS_PER_INT - 2 : 62))
186 /* This is the pseudo-op used to generate a contiguous sequence of byte
187 values from a double-quoted string WITHOUT HAVING A TERMINATING NUL
188 AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */
190 #undef ASCII_DATA_ASM_OP
191 #define ASCII_DATA_ASM_OP "\t.ascii\t"
193 /* Support const sections and the ctors and dtors sections for g++.
194 Note that there appears to be two different ways to support const
195 sections at the moment. You can either #define the symbol
196 READONLY_DATA_SECTION (giving it some code which switches to the
197 readonly data section) or else you can #define the symbols
198 EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and
199 SELECT_RTX_SECTION. We do both here just to be on the safe side. */
201 #undef USE_CONST_SECTION
202 #define USE_CONST_SECTION 1
204 #undef CONST_SECTION_ASM_OP
205 #define CONST_SECTION_ASM_OP "\t.section\t.rodata"
207 #undef BSS_SECTION_ASM_OP
208 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
209 #undef SBSS_SECTION_ASM_OP
210 #define SBSS_SECTION_ASM_OP "\t.section\t.sbss,\"aw\""
211 #undef SDATA_SECTION_ASM_OP
212 #define SDATA_SECTION_ASM_OP "\t.section\t.sdata,\"aw\""
214 /* On svr4, we *do* have support for the .init and .fini sections, and we
215 can put stuff in there to be executed before and after `main'. We let
216 crtstuff.c and other files know this by defining the following symbols.
217 The definitions say how to change sections to the .init and .fini
218 sections. This is the same for all known svr4 assemblers. */
220 #undef INIT_SECTION_ASM_OP
221 #define INIT_SECTION_ASM_OP "\t.section\t.init"
222 #undef FINI_SECTION_ASM_OP
223 #define FINI_SECTION_ASM_OP "\t.section\t.fini"
225 /* A default list of other sections which we might be "in" at any given
226 time. For targets that use additional sections (e.g. .tdesc) you
227 should override this definition in the target-specific file which
228 includes this file. */
230 #undef EXTRA_SECTIONS
231 #define EXTRA_SECTIONS in_const, in_sbss, in_sdata
233 /* A default list of extra section function definitions. For targets
234 that use additional sections (e.g. .tdesc) you should override this
235 definition in the target-specific file which includes this file. */
237 #undef EXTRA_SECTION_FUNCTIONS
238 #define EXTRA_SECTION_FUNCTIONS \
239 CONST_SECTION_FUNCTION \
240 SECTION_FUNCTION_TEMPLATE(sbss_section, in_sbss, SBSS_SECTION_ASM_OP) \
241 SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP)
243 extern void ctors_section PARAMS ((void));
244 extern void dtors_section PARAMS ((void));
245 extern void sbss_section PARAMS ((void));
246 extern void sdata_section PARAMS ((void));
248 #undef READONLY_DATA_SECTION
249 #define READONLY_DATA_SECTION() const_section ()
251 #undef CONST_SECTION_FUNCTION
252 #define CONST_SECTION_FUNCTION \
256 if (!USE_CONST_SECTION) \
258 else if (in_section != in_const) \
260 fprintf (asm_out_file, "%s\n", CONST_SECTION_ASM_OP); \
261 in_section = in_const; \
265 #undef SECTION_FUNCTION_TEMPLATE
266 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP) \
269 if (in_section != ENUM) \
271 fprintf (asm_out_file, "%s\n", OP); \
276 /* Switch into a generic section. */
277 #define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
279 /* A C statement or statements to switch to the appropriate
280 section for output of DECL. DECL is either a `VAR_DECL' node
281 or a constant of some sort. RELOC indicates whether forming
282 the initial value of DECL requires link-time relocations.
293 #define DO_SELECT_SECTION(SECNUM, DECL, RELOC) \
297 if (TREE_CODE (DECL) == FUNCTION_DECL) \
299 else if (TREE_CODE (DECL) == STRING_CST) \
301 if (flag_writable_strings) \
304 else if (TREE_CODE (DECL) == VAR_DECL) \
306 if (DECL_INITIAL (DECL) == NULL \
307 || DECL_INITIAL (DECL) == error_mark_node) \
309 else if ((flag_pic && RELOC) \
310 || ! TREE_READONLY (DECL) \
311 || TREE_SIDE_EFFECTS (DECL) \
312 || ! TREE_CONSTANT (DECL_INITIAL (DECL))) \
315 else if (TREE_CODE (DECL) == CONSTRUCTOR) \
317 if ((flag_pic && RELOC) \
318 || ! TREE_READONLY (DECL) \
319 || TREE_SIDE_EFFECTS (DECL) \
320 || ! TREE_CONSTANT (DECL)) \
324 /* Select small data sections based on size. */ \
327 int size = int_size_in_bytes (TREE_TYPE (DECL)); \
328 if (size >= 0 && size <= g_switch_value) \
334 #undef SELECT_SECTION
335 #define SELECT_SECTION(DECL, RELOC) \
338 typedef void (*sec_fn) PARAMS ((void)); \
339 static sec_fn const sec_functions[6] = \
351 DO_SELECT_SECTION (sec, DECL, RELOC); \
353 (*sec_functions[sec]) (); \
357 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
359 #undef UNIQUE_SECTION
360 #define UNIQUE_SECTION(DECL, RELOC) \
363 static const char * const prefixes[6][2] = \
365 { ".text.", ".gnu.linkonce.t." }, \
366 { ".rodata.", ".gnu.linkonce.r." }, \
367 { ".data.", ".gnu.linkonce.d." }, \
368 { ".sdata.", ".gnu.linkonce.s." }, \
369 { ".bss.", ".gnu.linkonce.b." }, \
370 { ".sbss.", ".gnu.linkonce.sb." } \
373 int nlen, plen, sec; \
374 const char *name, *prefix; \
377 DO_SELECT_SECTION (sec, DECL, RELOC); \
379 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
380 STRIP_NAME_ENCODING (name, name); \
381 nlen = strlen (name); \
383 prefix = prefixes[sec][DECL_ONE_ONLY(DECL)]; \
384 plen = strlen (prefix); \
386 string = alloca (nlen + plen + 1); \
388 memcpy (string, prefix, plen); \
389 memcpy (string + plen, name, nlen + 1); \
391 DECL_SECTION_NAME (DECL) = build_string (nlen + plen, string); \
395 /* A C statement or statements to switch to the appropriate
396 section for output of RTX in mode MODE. RTX is some kind
397 of constant in RTL. The argument MODE is redundant except
398 in the case of a `const_int' rtx. Currently, these always
399 go into the const section. */
401 #undef SELECT_RTX_SECTION
402 #define SELECT_RTX_SECTION(MODE, RTX) \
405 /* Define the strings used for the special svr4 .type and .size directives.
406 These strings generally do not vary from one system running svr4 to
407 another, but if a given system (e.g. m88k running svr) needs to use
408 different pseudo-op names for these, they may be overridden in the
409 file which includes this one. */
412 #define TYPE_ASM_OP "\t.type\t"
414 #define SIZE_ASM_OP "\t.size\t"
416 /* This is how we tell the assembler that a symbol is weak. */
418 #undef ASM_WEAKEN_LABEL
419 #define ASM_WEAKEN_LABEL(FILE, NAME) \
420 do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
421 fputc ('\n', FILE); } while (0)
423 /* This is how we tell the assembler that two symbols have the same value. */
425 #undef ASM_OUTPUT_DEF
426 #define ASM_OUTPUT_DEF(FILE, NAME1, NAME2) \
427 do { assemble_name(FILE, NAME1); \
428 fputs(" = ", FILE); \
429 assemble_name(FILE, NAME2); \
430 fputc('\n', FILE); } while (0)
432 /* The following macro defines the format used to output the second
433 operand of the .type assembler directive. Different svr4 assemblers
434 expect various different forms for this operand. The one given here
435 is just a default. You may need to override it in your machine-
436 specific tm.h file (depending upon the particulars of your assembler). */
438 #undef TYPE_OPERAND_FMT
439 #define TYPE_OPERAND_FMT "@%s"
441 /* Write the extra assembler code needed to declare a function's result.
442 Most svr4 assemblers don't require any special declaration of the
443 result value, but there are exceptions. */
445 #ifndef ASM_DECLARE_RESULT
446 #define ASM_DECLARE_RESULT(FILE, RESULT)
449 /* These macros generate the special .type and .size directives which
450 are used to set the corresponding fields of the linker symbol table
451 entries in an ELF object file under SVR4. These macros also output
452 the starting labels for the relevant functions/objects. */
454 /* Write the extra assembler code needed to declare an object properly. */
456 #undef ASM_DECLARE_OBJECT_NAME
457 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
459 HOST_WIDE_INT size; \
460 fprintf (FILE, "%s", TYPE_ASM_OP); \
461 assemble_name (FILE, NAME); \
463 fprintf (FILE, TYPE_OPERAND_FMT, "object"); \
465 size_directive_output = 0; \
466 if (!flag_inhibit_size_directive \
467 && DECL_SIZE (DECL) \
468 && (size = int_size_in_bytes (TREE_TYPE (DECL))) > 0) \
470 size_directive_output = 1; \
471 fprintf (FILE, "%s", SIZE_ASM_OP); \
472 assemble_name (FILE, NAME); \
474 fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, size); \
475 fputc ('\n', FILE); \
477 ASM_OUTPUT_LABEL(FILE, NAME); \
480 /* Output the size directive for a decl in rest_of_decl_compilation
481 in the case where we did not do so before the initializer.
482 Once we find the error_mark_node, we know that the value of
483 size_directive_output was set
484 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
486 #undef ASM_FINISH_DECLARE_OBJECT
487 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \
489 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
490 HOST_WIDE_INT size; \
491 if (!flag_inhibit_size_directive \
492 && DECL_SIZE (DECL) \
493 && ! AT_END && TOP_LEVEL \
494 && DECL_INITIAL (DECL) == error_mark_node \
495 && !size_directive_output \
496 && (size = int_size_in_bytes (TREE_TYPE (DECL))) > 0) \
498 size_directive_output = 1; \
499 fprintf (FILE, "%s", SIZE_ASM_OP); \
500 assemble_name (FILE, name); \
502 fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, size); \
503 fputc ('\n', FILE); \
507 /* A table of bytes codes used by the ASM_OUTPUT_ASCII and
508 ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table
509 corresponds to a particular byte value [0..255]. For any
510 given byte value, if the value in the corresponding table
511 position is zero, the given character can be output directly.
512 If the table value is 1, the byte must be output as a \ooo
513 octal escape. If the tables value is anything else, then the
514 byte value should be output as a \ followed by the value
515 in the table. Note that we can use standard UN*X escape
516 sequences for many control characters, but we don't use
517 \a to represent BEL because some svr4 assemblers (e.g. on
518 the i386) don't know about that. Also, we don't use \v
519 since some versions of gas, such as 2.2 did not accept it. */
523 "\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
524 \0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
525 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\
526 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\
527 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
528 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
529 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
530 \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"
532 /* Some svr4 assemblers have a limit on the number of characters which
533 can appear in the operand of a .string directive. If your assembler
534 has such a limitation, you should define STRING_LIMIT to reflect that
535 limit. Note that at least some svr4 assemblers have a limit on the
536 actual number of bytes in the double-quoted string, and that they
537 count each character in an escape sequence as one byte. Thus, an
538 escape sequence like \377 would count as four bytes.
540 If your target assembler doesn't support the .string directive, you
541 should define this to zero. */
544 #define STRING_LIMIT ((unsigned) 256)
546 #define STRING_ASM_OP "\t.string\t"
548 /* GAS is the only Alpha/ELF assembler. */
550 #define TARGET_GAS (1)
552 /* Provide a STARTFILE_SPEC appropriate for ELF. Here we add the
553 (even more) magical crtbegin.o file which provides part of the
554 support for getting C++ file-scope static object constructed
555 before entering `main'.
557 Don't bother seeing crtstuff.c -- there is absolutely no hope
558 of getting that file to understand multiple GPs. We provide a
559 hand-coded assembly version. */
561 #undef STARTFILE_SPEC
562 #define STARTFILE_SPEC \
564 %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\
565 crti.o%s %{shared:crtbeginS.o%s}%{!shared:crtbegin.o%s}"
567 /* Provide a ENDFILE_SPEC appropriate for ELF. Here we tack on the
568 magical crtend.o file which provides part of the support for
569 getting C++ file-scope static object constructed before entering
570 `main', followed by a normal ELF "finalizer" file, `crtn.o'. */
573 #define ENDFILE_SPEC \
574 "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
575 %{shared:crtendS.o%s}%{!shared:crtend.o%s} crtn.o%s"
577 /* We support #pragma. */
578 #define HANDLE_SYSV_PRAGMA
580 /* Undo the auto-alignment stuff from alpha.h. ELF has unaligned data
582 #undef UNALIGNED_SHORT_ASM_OP
583 #undef UNALIGNED_INT_ASM_OP
584 #undef UNALIGNED_DOUBLE_INT_ASM_OP
586 /* Select a format to encode pointers in exception handling data. CODE
587 is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is
588 true if the symbol may be affected by dynamic relocations.
590 Since application size is already constrained to <2GB by the form of
591 the ldgp relocation, we can use a 32-bit pc-relative relocation to
592 static data. Dynamic data is accessed indirectly to allow for read
594 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
595 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
597 /* If defined, a C statement to be executed just prior to the output of
598 assembler code for INSN. */
599 #define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS) \
600 (alpha_this_literal_sequence_number = 0, \
601 alpha_this_gpdisp_sequence_number = 0)
602 extern int alpha_this_literal_sequence_number;
603 extern int alpha_this_gpdisp_sequence_number;