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.
6 .. index:: assembler format, output of assembler code
10 The Overall Framework of an Assembler File
11 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13 .. prevent bad page break with this line
15 This describes the overall framework of an assembly file.
17 .. index:: default_file_start
19 .. function:: void TARGET_ASM_FILE_START (void)
21 .. hook-start:TARGET_ASM_FILE_START
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.
32 .. c:var:: bool TARGET_ASM_FILE_START_APP_OFF
34 .. hook-start:TARGET_ASM_FILE_START_APP_OFF
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.
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.
50 .. c:var:: bool TARGET_ASM_FILE_START_FILE_DIRECTIVE
52 .. hook-start:TARGET_ASM_FILE_START_FILE_DIRECTIVE
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.
61 .. function:: void TARGET_ASM_FILE_END (void)
63 .. hook-start:TARGET_ASM_FILE_END
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.
70 .. function:: void file_end_indicate_exec_stack ()
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
79 .. function:: void TARGET_ASM_LTO_START (void)
81 .. hook-start:TARGET_ASM_LTO_START
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
89 .. function:: void TARGET_ASM_LTO_END (void)
91 .. hook-start:TARGET_ASM_LTO_END
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
99 .. function:: void TARGET_ASM_CODE_END (void)
101 .. hook-start:TARGET_ASM_CODE_END
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
111 .. c:macro:: ASM_COMMENT_START
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
117 .. c:macro:: ASM_APP_ON
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.
125 .. c:macro:: ASM_APP_OFF
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.
132 .. c:macro:: ASM_OUTPUT_SOURCE_FILENAME (stream, name)
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}`.
138 This macro need not be defined if the standard form of output
139 for the file format in use is appropriate.
141 .. function:: void TARGET_ASM_OUTPUT_SOURCE_FILENAME (FILE *file, const char *name)
143 .. hook-start:TARGET_ASM_OUTPUT_SOURCE_FILENAME
145 Output DWARF debugging information which indicates that filename
146 :samp:`{name}` is the current source file to the stdio stream :samp:`{file}`.
148 This target hook need not be defined if the standard form of output
149 for the file format in use is appropriate.
153 .. function:: void TARGET_ASM_OUTPUT_IDENT (const char *name)
155 .. hook-start:TARGET_ASM_OUTPUT_IDENT
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`
164 .. c:macro:: OUTPUT_QUOTED_STRING (stream, string)
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.
172 .. function:: void TARGET_ASM_NAMED_SECTION (const char *name, unsigned int flags, tree decl)
174 .. hook-start:TARGET_ASM_NAMED_SECTION
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.
184 .. function:: bool TARGET_ASM_ELF_FLAGS_NUMERIC (unsigned int flags, unsigned int *num)
186 .. hook-start:TARGET_ASM_ELF_FLAGS_NUMERIC
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
200 .. function:: section * TARGET_ASM_FUNCTION_SECTION (tree decl, enum node_frequency freq, bool startup, bool exit)
202 .. hook-start:TARGET_ASM_FUNCTION_SECTION
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.
214 .. function:: void TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS (FILE *file, tree decl, bool new_is_cold)
216 .. hook-start:TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS
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``.
226 .. c:var:: bool TARGET_HAVE_NAMED_SECTIONS
228 .. hook-start:TARGET_HAVE_NAMED_SECTIONS
232 This flag is true if the target supports ``TARGET_ASM_NAMED_SECTION``.
233 It must not be modified by command-line option processing.
235 .. _target_have_switchable_bss_sections:
237 .. c:var:: bool TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
239 .. hook-start:TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
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.
247 .. function:: unsigned int TARGET_SECTION_TYPE_FLAGS (tree decl, const char *name, int reloc)
249 .. hook-start:TARGET_SECTION_TYPE_FLAGS
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.
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__``.
263 .. function:: void TARGET_ASM_RECORD_GCC_SWITCHES (const char *)
265 .. hook-start:TARGET_ASM_RECORD_GCC_SWITCHES
267 Provides the target with the ability to record the gcc command line
268 switches provided as argument.
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
279 .. c:var:: const char * TARGET_ASM_RECORD_GCC_SWITCHES_SECTION
281 .. hook-start:TARGET_ASM_RECORD_GCC_SWITCHES_SECTION
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