]> git.ipfire.org Git - thirdparty/gcc.git/blob
d0dfe7dd55857f0a93cf3531676f413479b117ac
[thirdparty/gcc.git] /
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: assembler format, output of assembler code
7
8 .. _file-framework:
9
10 The Overall Framework of an Assembler File
11 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12
13 .. prevent bad page break with this line
14
15 This describes the overall framework of an assembly file.
16
17 .. index:: default_file_start
18
19 .. function:: void TARGET_ASM_FILE_START (void)
20
21 .. hook-start:TARGET_ASM_FILE_START
22
23 Output to ``asm_out_file`` any text which the assembler expects to
24 find at the beginning of a file. The default behavior is controlled
25 by two flags, documented below. Unless your target's assembler is
26 quite unusual, if you override the default, you should call
27 ``default_file_start`` at some point in your target hook. This
28 lets other target files rely on these variables.
29
30 .. hook-end
31
32 .. c:var:: bool TARGET_ASM_FILE_START_APP_OFF
33
34 .. hook-start:TARGET_ASM_FILE_START_APP_OFF
35
36 If this flag is true, the text of the macro ``ASM_APP_OFF`` will be
37 printed as the very first line in the assembly file, unless
38 :option:`-fverbose-asm` is in effect. (If that macro has been defined
39 to the empty string, this variable has no effect.) With the normal
40 definition of ``ASM_APP_OFF``, the effect is to notify the GNU
41 assembler that it need not bother stripping comments or extra
42 whitespace from its input. This allows it to work a bit faster.
43
44 The default is false. You should not set it to true unless you have
45 verified that your port does not generate any extra whitespace or
46 comments that will cause GAS to issue errors in NO_APP mode.
47
48 .. hook-end
49
50 .. c:var:: bool TARGET_ASM_FILE_START_FILE_DIRECTIVE
51
52 .. hook-start:TARGET_ASM_FILE_START_FILE_DIRECTIVE
53
54 If this flag is true, ``output_file_directive`` will be called
55 for the primary source file, immediately after printing
56 ``ASM_APP_OFF`` (if that is enabled). Most ELF assemblers expect
57 this to be done. The default is false.
58
59 .. hook-end
60
61 .. function:: void TARGET_ASM_FILE_END (void)
62
63 .. hook-start:TARGET_ASM_FILE_END
64
65 Output to ``asm_out_file`` any text which the assembler expects
66 to find at the end of a file. The default is to output nothing.
67
68 .. hook-end
69
70 .. function:: void file_end_indicate_exec_stack ()
71
72 Some systems use a common convention, the :samp:`.note.GNU-stack`
73 special section, to indicate whether or not an object file relies on
74 the stack being executable. If your system uses this convention, you
75 should define ``TARGET_ASM_FILE_END`` to this function. If you
76 need to do other things in that hook, have your hook function call
77 this function.
78
79 .. function:: void TARGET_ASM_LTO_START (void)
80
81 .. hook-start:TARGET_ASM_LTO_START
82
83 Output to ``asm_out_file`` any text which the assembler expects
84 to find at the start of an LTO section. The default is to output
85 nothing.
86
87 .. hook-end
88
89 .. function:: void TARGET_ASM_LTO_END (void)
90
91 .. hook-start:TARGET_ASM_LTO_END
92
93 Output to ``asm_out_file`` any text which the assembler expects
94 to find at the end of an LTO section. The default is to output
95 nothing.
96
97 .. hook-end
98
99 .. function:: void TARGET_ASM_CODE_END (void)
100
101 .. hook-start:TARGET_ASM_CODE_END
102
103 Output to ``asm_out_file`` any text which is needed before emitting
104 unwind info and debug info at the end of a file. Some targets emit
105 here PIC setup thunks that cannot be emitted at the end of file,
106 because they couldn't have unwind info then. The default is to output
107 nothing.
108
109 .. hook-end
110
111 .. c:macro:: ASM_COMMENT_START
112
113 A C string constant describing how to begin a comment in the target
114 assembler language. The compiler assumes that the comment will end at
115 the end of the line.
116
117 .. c:macro:: ASM_APP_ON
118
119 A C string constant for text to be output before each ``asm``
120 statement or group of consecutive ones. Normally this is
121 ``"#APP"``, which is a comment that has no effect on most
122 assemblers but tells the GNU assembler that it must check the lines
123 that follow for all valid assembler constructs.
124
125 .. c:macro:: ASM_APP_OFF
126
127 A C string constant for text to be output after each ``asm``
128 statement or group of consecutive ones. Normally this is
129 ``"#NO_APP"``, which tells the GNU assembler to resume making the
130 time-saving assumptions that are valid for ordinary compiler output.
131
132 .. c:macro:: ASM_OUTPUT_SOURCE_FILENAME (stream, name)
133
134 A C statement to output COFF information or DWARF debugging information
135 which indicates that filename :samp:`{name}` is the current source file to
136 the stdio stream :samp:`{stream}`.
137
138 This macro need not be defined if the standard form of output
139 for the file format in use is appropriate.
140
141 .. function:: void TARGET_ASM_OUTPUT_SOURCE_FILENAME (FILE *file, const char *name)
142
143 .. hook-start:TARGET_ASM_OUTPUT_SOURCE_FILENAME
144
145 Output DWARF debugging information which indicates that filename
146 :samp:`{name}` is the current source file to the stdio stream :samp:`{file}`.
147
148 This target hook need not be defined if the standard form of output
149 for the file format in use is appropriate.
150
151 .. hook-end
152
153 .. function:: void TARGET_ASM_OUTPUT_IDENT (const char *name)
154
155 .. hook-start:TARGET_ASM_OUTPUT_IDENT
156
157 Output a string based on :samp:`{name}`, suitable for the :samp:`#ident`
158 directive, or the equivalent directive or pragma in non-C-family languages.
159 If this hook is not defined, nothing is output for the :samp:`#ident`
160 directive.
161
162 .. hook-end
163
164 .. c:macro:: OUTPUT_QUOTED_STRING (stream, string)
165
166 A C statement to output the string :samp:`{string}` to the stdio stream
167 :samp:`{stream}`. If you do not call the function ``output_quoted_string``
168 in your config files, GCC will only call it to output filenames to
169 the assembler source. So you can use it to canonicalize the format
170 of the filename using this macro.
171
172 .. function:: void TARGET_ASM_NAMED_SECTION (const char *name, unsigned int flags, tree decl)
173
174 .. hook-start:TARGET_ASM_NAMED_SECTION
175
176 Output assembly directives to switch to section :samp:`{name}`. The section
177 should have attributes as specified by :samp:`{flags}`, which is a bit mask
178 of the ``SECTION_*`` flags defined in :samp:`output.h`. If :samp:`{decl}`
179 is non-NULL, it is the ``VAR_DECL`` or ``FUNCTION_DECL`` with which
180 this section is associated.
181
182 .. hook-end
183
184 .. function:: bool TARGET_ASM_ELF_FLAGS_NUMERIC (unsigned int flags, unsigned int *num)
185
186 .. hook-start:TARGET_ASM_ELF_FLAGS_NUMERIC
187
188 This hook can be used to encode ELF section flags for which no letter
189 code has been defined in the assembler. It is called by
190 ``default_asm_named_section`` whenever the section flags need to be
191 emitted in the assembler output. If the hook returns true, then the
192 numerical value for ELF section flags should be calculated from
193 :samp:`{flags}` and saved in :samp:`{*num}` ; the value is printed out instead of the
194 normal sequence of letter codes. If the hook is not defined, or if it
195 returns false, then :samp:`{num}` is ignored and the traditional letter sequence
196 is emitted.
197
198 .. hook-end
199
200 .. function:: section * TARGET_ASM_FUNCTION_SECTION (tree decl, enum node_frequency freq, bool startup, bool exit)
201
202 .. hook-start:TARGET_ASM_FUNCTION_SECTION
203
204 Return preferred text (sub)section for function :samp:`{decl}`.
205 Main purpose of this function is to separate cold, normal and hot
206 functions. :samp:`{startup}` is true when function is known to be used only
207 at startup (from static constructors or it is ``main()``).
208 :samp:`{exit}` is true when function is known to be used only at exit
209 (from static destructors).
210 Return NULL if function should go to default text section.
211
212 .. hook-end
213
214 .. function:: void TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS (FILE *file, tree decl, bool new_is_cold)
215
216 .. hook-start:TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS
217
218 Used by the target to emit any assembler directives or additional
219 labels needed when a function is partitioned between different
220 sections. Output should be written to :samp:`{file}`. The function
221 decl is available as :samp:`{decl}` and the new section is 'cold' if
222 :samp:`{new_is_cold}` is ``true``.
223
224 .. hook-end
225
226 .. c:var:: bool TARGET_HAVE_NAMED_SECTIONS
227
228 .. hook-start:TARGET_HAVE_NAMED_SECTIONS
229
230 .. hook-end
231
232 This flag is true if the target supports ``TARGET_ASM_NAMED_SECTION``.
233 It must not be modified by command-line option processing.
234
235 .. _target_have_switchable_bss_sections:
236
237 .. c:var:: bool TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
238
239 .. hook-start:TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
240
241 This flag is true if we can create zeroed data by switching to a BSS
242 section and then using ``ASM_OUTPUT_SKIP`` to allocate the space.
243 This is true on most ELF targets.
244
245 .. hook-end
246
247 .. function:: unsigned int TARGET_SECTION_TYPE_FLAGS (tree decl, const char *name, int reloc)
248
249 .. hook-start:TARGET_SECTION_TYPE_FLAGS
250
251 Choose a set of section attributes for use by ``TARGET_ASM_NAMED_SECTION``
252 based on a variable or function decl, a section name, and whether or not the
253 declaration's initializer may contain runtime relocations. :samp:`{decl}` may be
254 null, in which case read-write data should be assumed.
255
256 The default version of this function handles choosing code vs data,
257 read-only vs read-write data, and ``flag_pic``. You should only
258 need to override this if your target has special flags that might be
259 set via ``__attribute__``.
260
261 .. hook-end
262
263 .. function:: void TARGET_ASM_RECORD_GCC_SWITCHES (const char *)
264
265 .. hook-start:TARGET_ASM_RECORD_GCC_SWITCHES
266
267 Provides the target with the ability to record the gcc command line
268 switches provided as argument.
269
270 By default this hook is set to NULL, but an example implementation is
271 provided for ELF based targets. Called :samp:`{elf_record_gcc_switches}`,
272 it records the switches as ASCII text inside a new, string mergeable
273 section in the assembler output file. The name of the new section is
274 provided by the ``TARGET_ASM_RECORD_GCC_SWITCHES_SECTION`` target
275 hook.
276
277 .. hook-end
278
279 .. c:var:: const char * TARGET_ASM_RECORD_GCC_SWITCHES_SECTION
280
281 .. hook-start:TARGET_ASM_RECORD_GCC_SWITCHES_SECTION
282
283 This is the name of the section that will be created by the example
284 ELF implementation of the ``TARGET_ASM_RECORD_GCC_SWITCHES`` target
285 hook.
286
287 .. hook-end