1/* Copyright (C) 2016-2020 Free Software Foundation, Inc.
2
3   This file is free software; you can redistribute it and/or modify it under
4   the terms of the GNU General Public License as published by the Free
5   Software Foundation; either version 3 of the License, or (at your option)
6   any later version.
7
8   This file is distributed in the hope that it will be useful, but WITHOUT
9   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11   for more details.
12
13   You should have received a copy of the GNU General Public License
14   along with GCC; see the file COPYING3.  If not see
15   <http://www.gnu.org/licenses/>.  */
16
17#ifndef OBJECT_FORMAT_ELF
18 #error elf.h included before elfos.h
19#endif
20
21#define TEXT_SECTION_ASM_OP "\t.section\t.text"
22#define BSS_SECTION_ASM_OP  "\t.section\t.bss"
23#define GLOBAL_ASM_OP       "\t.globl\t"
24#define DATA_SECTION_ASM_OP "\t.data\t"
25#define SET_ASM_OP          "\t.set\t"
26#define LOCAL_LABEL_PREFIX  "."
27#define USER_LABEL_PREFIX   ""
28#define ASM_COMMENT_START   ";"
29#define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
30
31#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
32	    asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
33
34#undef ASM_DECLARE_FUNCTION_NAME
35#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
36  gcn_hsa_declare_function_name ((FILE), (NAME), (DECL))
37
38/* Unlike GNU as, the LLVM assembler uses log2 alignments.  */
39#undef ASM_OUTPUT_ALIGNED_COMMON
40#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGNMENT)	  \
41 (fprintf ((FILE), "%s", COMMON_ASM_OP),			  \
42  assemble_name ((FILE), (NAME)),				  \
43  fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",	  \
44	   (SIZE) > 0 ? (SIZE) : 1, exact_log2 ((ALIGNMENT) / BITS_PER_UNIT)))
45
46#define ASM_OUTPUT_LABEL(FILE,NAME) \
47  do { assemble_name (FILE, NAME); fputs (":\n", FILE); } while (0)
48
49#define ASM_OUTPUT_LABELREF(FILE, NAME) \
50  asm_fprintf (FILE, "%U%s", default_strip_name_encoding (NAME))
51
52extern unsigned int gcn_local_sym_hash (const char *name);
53
54#define ASM_OUTPUT_SYMBOL_REF(FILE, X) gcn_asm_output_symbol_ref (FILE, X)
55
56#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
57  fprintf (FILE, "\t.word .L%d-.L%d\n", VALUE, REL)
58
59#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
60  fprintf (FILE, "\t.word .L%d\n", VALUE)
61
62#define ASM_OUTPUT_ALIGN(FILE,LOG) \
63  do { if (LOG!=0) fprintf (FILE, "\t.align\t%d\n", 1<<(LOG)); } while (0)
64#define ASM_OUTPUT_ALIGN_WITH_NOP(FILE,LOG)	       \
65  do {						       \
66    if (LOG!=0)					       \
67      fprintf (FILE, "\t.p2alignl\t%d, 0xBF800000"     \
68	       " ; Fill value is 's_nop 0'\n", (LOG)); \
69  } while (0)
70
71#define ASM_APP_ON  ""
72#define ASM_APP_OFF ""
73
74/* Avoid the default in ../../gcc.c, which adds "-pthread", which is not
75   supported for gcn.  */
76#define GOMP_SELF_SPECS ""
77
78/* Use LLVM assembler and linker options.  */
79#define ASM_SPEC  "-triple=amdgcn--amdhsa -mattr=-code-object-v3 "  \
80		  "%:last_arg(%{march=*:-mcpu=%*}) " \
81		  "-filetype=obj"
82/* Add -mlocal-symbol-id=<source-file-basename> unless the user (or mkoffload)
83   passes the option explicitly on the command line.  The option also causes
84   several dump-matching tests to fail in the testsuite, so the option is not
85   added when or tree dump/compare-debug options used in the testsuite are
86   present.
87   This has the potential for surprise, but a user can still use an explicit
88   -mlocal-symbol-id=<whatever> option manually together with -fdump-tree or
89   -fcompare-debug options.  */
90#define CC1_SPEC "%{!mlocal-symbol-id=*:%{!fdump-tree-*:"	\
91		 "%{!fdump-ipa-*:%{!fcompare-debug*:-mlocal-symbol-id=%b}}}}"
92#define LINK_SPEC "--pie"
93#define LIB_SPEC  "-lc"
94
95/* Provides a _start symbol to keep the linker happy.  */
96#define STARTFILE_SPEC "crt0.o%s"
97#define ENDFILE_SPEC   ""
98#define STANDARD_STARTFILE_PREFIX_2 ""
99
100/* The LLVM assembler rejects multiple -mcpu options, so we must drop
101   all but the last.  */
102extern const char *last_arg_spec_function (int argc, const char **argv);
103#define EXTRA_SPEC_FUNCTIONS	\
104    { "last_arg", last_arg_spec_function },
105
106#undef LOCAL_INCLUDE_DIR
107
108/* FIXME: Review debug info settings.
109 *        In particular, EH_FRAME_THROUGH_COLLECT2 is probably the wrong
110 *        thing but stuff fails to build without it.
111 *        (Debug info is not a big deal until we get a debugger.)  */
112#define PREFERRED_DEBUGGING_TYPE   DWARF2_DEBUG
113#define DWARF2_DEBUGGING_INFO      1
114#define DWARF2_ASM_LINE_DEBUG_INFO 1
115#define EH_FRAME_THROUGH_COLLECT2  1
116