[m-rev.] diff: align functions on word boundaries with clang
Julien Fischer
jfischer at opturion.com
Sat May 4 16:51:20 AEST 2024
Align functions on word boundaries with clang.
Function trailing with tagged trail entries does not work unless the functions
are aligned on word boundaries. In trailing grades with GCC, we have long
passed an option (-falign-functions) to force this to happen. Do the same for
clang, which supports the same option. This fixes the failure of function
trailing tests on Apple Silicon based machines.
(This does not appear an issue on Intel-based Macs.)
scripts/mgnuc.in:
compiler/compile_target_code.m:
Tell clang to align functions on word boundaries in trailing grades.
Julien.
diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index d7acfdac8..0f6d2ec5a 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -409,22 +409,23 @@ gather_c_compiler_flags(Globals, PIC, AllCFlags) :-
UseTrail = yes,
% With tagged trail entries function trailing will not work unless the
% C functions stored on the trail are aligned on word boundaries (or a
- % multiple thereof). The assemblers on some systems, and some gcc
- % optimisation settings, do not align functions, so we need to
+ % multiple thereof). The assemblers on some systems, and some gcc or
+ % clang optimisation settings, do not align functions, so we need to
% explicitly pass -falign-functions in trailing grades to ensure that
% C functions are appropriately aligned.
%
% Note that this will also affect the untagged version of the trail,
% but that shouldn't matter.
(
- C_CompilerType = cc_gcc(_, _, _),
+ ( C_CompilerType = cc_gcc(_, _, _)
+ ; C_CompilerType = cc_clang(_)
+ ),
globals.lookup_int_option(Globals, bytes_per_word, BytesPerWord),
C_FnAlignOpt = string.format("-falign-functions=%d ",
[i(BytesPerWord)])
;
% XXX Check whether we need to do anything for these C compilers?
- ( C_CompilerType = cc_clang(_)
- ; C_CompilerType = cc_cl_x86(_)
+ ( C_CompilerType = cc_cl_x86(_)
; C_CompilerType = cc_cl_x64(_)
),
C_FnAlignOpt = ""
diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in
index 1ba02f593..8ddefe653 100644
--- a/scripts/mgnuc.in
+++ b/scripts/mgnuc.in
@@ -393,8 +393,8 @@ case ${use_trail} in
# See the comment in compile_c_file/7 in compiler/compile_target_code.m
# for an explanation of this.
case ${COMPILER} in
- gcc) FN_ALIGN_OPTS="-falign-functions=${BYTES_PER_WORD}" ;;
- *) FN_ALIGN_OPTS="" ;;
+ gcc|clang) FN_ALIGN_OPTS="-falign-functions=${BYTES_PER_WORD}" ;;
+ *) FN_ALIGN_OPTS="" ;;
esac
;;
false)
More information about the reviews
mailing list