aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.cc
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2023-12-07 13:08:27 +0100
committerIlya Leoshkevich <iii@linux.ibm.com>2024-01-05 12:24:01 +0100
commite66dc37b299cac4171b1c5b90cf6b54388bd5bc5 (patch)
treeff5a38a90075021d3262b0b4a536ba23b7665b33 /gcc/varasm.cc
parentc659dd8bfb55e02a1b97407c1c28f7a0e8f7f09b (diff)
downloadgcc-e66dc37b299cac4171b1c5b90cf6b54388bd5bc5.zip
gcc-e66dc37b299cac4171b1c5b90cf6b54388bd5bc5.tar.gz
gcc-e66dc37b299cac4171b1c5b90cf6b54388bd5bc5.tar.bz2
asan: Align .LASANPC on function boundary
GCC can emit code between the function label and the .LASANPC label, making the latter unaligned. Some architectures cannot load unaligned labels directly and require literal pool entries, which is inefficient. Move the invocation of asan_function_start to ASM_OUTPUT_FUNCTION_LABEL, which guarantees that no additional code is emitted. This allows setting the .LASANPC label alignment to the respective function alignment. Link: https://inbox.sourceware.org/gcc-patches/20240102194511.3171559-3-iii@linux.ibm.com/ Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> gcc/ChangeLog: * asan.cc (asan_function_start): Drop switch_to_section (). (asan_emit_stack_protection): Set .LASANPC alignment. * config/i386/i386.cc: Use assemble_function_label_raw () instead of ASM_OUTPUT_LABEL (). * config/s390/s390.cc (s390_asm_output_function_label): Likewise. * defaults.h (ASM_OUTPUT_FUNCTION_LABEL): Likewise. * final.cc (final_start_function_1): Drop asan_function_start (). * output.h (assemble_function_label_raw): New function. * varasm.cc (assemble_function_label_raw): Likewise.
Diffstat (limited to 'gcc/varasm.cc')
-rw-r--r--gcc/varasm.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 29ac8b1..25c1e05 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see
#include "alloc-pool.h"
#include "toplev.h"
#include "opts.h"
+#include "asan.h"
/* The (assembler) name of the first globally-visible object output. */
extern GTY(()) const char *first_global_object_name;
@@ -1835,6 +1836,19 @@ get_fnname_from_decl (tree decl)
return XSTR (x, 0);
}
+/* Output function label, possibly with accompanying metadata. No additional
+ code or data is output after the label. */
+
+void
+assemble_function_label_raw (FILE *file, const char *name)
+{
+ ASM_OUTPUT_LABEL (file, name);
+ if ((flag_sanitize & SANITIZE_ADDRESS)
+ /* Notify ASAN only about the first function label. */
+ && (in_cold_section_p == first_function_block_is_cold))
+ asan_function_start ();
+}
+
/* Output assembler code for the constant pool of a function and associated
with defining the name of the function. DECL describes the function.
NAME is the function's name. For the constant pool, we use the current