LoongArch processors may not support memory accesses without natural alignments. Building libraries with -mstrict-align may help with toolchain binary compatiblity and performance on these implementations (e.g. Loongson 2K1000LA).
With this patch, no significant performance degredation is observed on current mainstream LoongArch processors. gcc/ChangeLog: * gcc/config/t-linux: add -mstrict-align via self_specs when building GCC libraries. --- gcc/config/loongarch/t-linux | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/config/loongarch/t-linux b/gcc/config/loongarch/t-linux index 75bb430c555..2a170d600a9 100644 --- a/gcc/config/loongarch/t-linux +++ b/gcc/config/loongarch/t-linux @@ -35,6 +35,9 @@ gen_mlib_spec = $(if $(word 2,$1),\ # clean up the result of DRIVER_SELF_SPEC to avoid conflict lib_build_self_spec = %<march=* %<mtune=* %<mcmodel=* %<mfpu=* %<msimd=* +# build libraries with -mstrict-align by default +lib_build_self_spec += -mstrict-align + # append user-specified build options from --with-multilib-list lib_build_self_spec += $(foreach mlib,$(subst $(comma), ,$(TM_MULTILIB_CONFIG)),\ $(call gen_mlib_spec,$(subst /, ,$(mlib)))) -- 2.41.0