Skip to content

Commit 227b18f

Browse files
scylaacchenglulu326
authored andcommitted
LoongArch: Reimplement multilib build option handling.
Library build options from --with-multilib-list used to be processed with *self_spec, which missed the driver's initial canonicalization. This caused limitations on CFLAGS override and the use of driver-only options like -m[no]-lsx. The problem is solved by promoting the injection rules of --with-multilib-list options to the first element of DRIVER_SELF_SPECS, to make them execute before the canonialization. The library-build options are also hard-coded in the driver and can be used conveniently by the builders of other non-gcc libraries via the use of -fmultiflags. Bootstrapped and tested on loongarch64-linux-gnu. ChangeLog: * config-ml.in: Remove unneeded loongarch clause. * configure.ac: Register custom makefile fragments mt-loongarch-* for loongarch targets. * configure: Regenerate. config/ChangeLog: * mt-loongarch-mlib: New file. Pass -fmultiflags when building target libraries (FLAGS_FOR_TARGET). * mt-loongarch-elf: New file. * mt-loongarch-gnu: New file. gcc/ChangeLog: * config.gcc: Pass the default ABI via TM_MULTILIB_CONFIG. * config/loongarch/loongarch-driver.h: Invoke MLIB_SELF_SPECS before the driver canonicalization routines. * config/loongarch/loongarch.h: Move definitions of CC1_SPEC etc. to loongarch-driver.h * config/loongarch/t-linux: Move multilib-related definitions to t-multilib. * config/loongarch/t-multilib: New file. Inject library build options obtained from --with-multilib-list. * config/loongarch/t-loongarch: Same.
1 parent 68cb873 commit 227b18f

12 files changed

+137
-123
lines changed

config-ml.in

-10
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,6 @@ arm-*-*)
301301
done
302302
fi
303303
;;
304-
loongarch*-*)
305-
old_multidirs="${multidirs}"
306-
multidirs=""
307-
for x in ${old_multidirs}; do
308-
case "$x" in
309-
`${CC-gcc} --print-multi-directory`) : ;;
310-
*) multidirs="${multidirs} ${x}" ;;
311-
esac
312-
done
313-
;;
314304
m68*-*-*)
315305
if [ x$enable_softfloat = xno ]
316306
then

config/mt-loongarch-elf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include $(srcdir)/config/mt-loongarch-mlib

config/mt-loongarch-gnu

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include $(srcdir)/config/mt-gnu
2+
include $(srcdir)/config/mt-loongarch-mlib

config/mt-loongarch-mlib

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FLAGS_FOR_TARGET += -fmultiflags

configure

+6
Original file line numberDiff line numberDiff line change
@@ -9683,6 +9683,12 @@ case "${target}" in
96839683
spu-*-*)
96849684
target_makefile_frag="config/mt-spu"
96859685
;;
9686+
loongarch*-*linux* | loongarch*-*gnu*)
9687+
target_makefile_frag="config/mt-loongarch-gnu"
9688+
;;
9689+
loongarch*-*elf*)
9690+
target_makefile_frag="config/mt-loongarch-elf"
9691+
;;
96869692
mips*-sde-elf* | mips*-mti-elf* | mips*-img-elf*)
96879693
target_makefile_frag="config/mt-sde"
96889694
;;

configure.ac

+6
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,12 @@ case "${target}" in
28102810
spu-*-*)
28112811
target_makefile_frag="config/mt-spu"
28122812
;;
2813+
loongarch*-*linux* | loongarch*-*gnu*)
2814+
target_makefile_frag="config/mt-loongarch-gnu"
2815+
;;
2816+
loongarch*-*elf*)
2817+
target_makefile_frag="config/mt-loongarch-elf"
2818+
;;
28132819
mips*-sde-elf* | mips*-mti-elf* | mips*-img-elf*)
28142820
target_makefile_frag="config/mt-sde"
28152821
;;

gcc/config.gcc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ loongarch*-*-linux*)
24832483
tm_file="elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h ${tm_file}"
24842484
tm_file="${tm_file} loongarch/gnu-user.h loongarch/linux.h"
24852485
extra_options="${extra_options} linux-android.opt"
2486-
tmake_file="${tmake_file} loongarch/t-linux"
2486+
tmake_file="${tmake_file} loongarch/t-multilib loongarch/t-linux"
24872487
gnu_ld=yes
24882488
gas=yes
24892489

@@ -2495,7 +2495,7 @@ loongarch*-*-linux*)
24952495
loongarch*-*-elf*)
24962496
tm_file="elfos.h newlib-stdint.h ${tm_file}"
24972497
tm_file="${tm_file} loongarch/elf.h loongarch/linux.h"
2498-
tmake_file="${tmake_file} loongarch/t-linux"
2498+
tmake_file="${tmake_file} loongarch/t-multilib loongarch/t-linux"
24992499
gnu_ld=yes
25002500
gas=yes
25012501

@@ -5168,7 +5168,7 @@ case "${target}" in
51685168
loongarch_multilib_list_sane=no
51695169

51705170
# This one goes to TM_MULTILIB_CONFIG, for use in t-linux.
5171-
loongarch_multilib_list_make=""
5171+
loongarch_multilib_list_make="${abi_base},"
51725172

51735173
# This one goes to tm_defines, for use in loongarch-driver.c.
51745174
loongarch_multilib_list_c=""

gcc/config/loongarch/loongarch-driver.h

+42
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,39 @@ along with GCC; see the file COPYING3. If not see
2323

2424
#include "loongarch-str.h"
2525

26+
#ifndef SUBTARGET_CPP_SPEC
27+
#define SUBTARGET_CPP_SPEC ""
28+
#endif
29+
30+
#ifndef SUBTARGET_CC1_SPEC
31+
#define SUBTARGET_CC1_SPEC ""
32+
#endif
33+
34+
#ifndef SUBTARGET_ASM_SPEC
35+
#define SUBTARGET_ASM_SPEC ""
36+
#endif
37+
38+
#define EXTRA_SPECS \
39+
{"early_self_spec", ""}, \
40+
{"subtarget_cc1_spec", SUBTARGET_CC1_SPEC}, \
41+
{"subtarget_cpp_spec", SUBTARGET_CPP_SPEC}, \
42+
{"subtarget_asm_spec", SUBTARGET_ASM_SPEC},
43+
44+
45+
#undef CPP_SPEC
46+
#define CPP_SPEC \
47+
"%(subtarget_cpp_spec)"
48+
49+
#undef CC1_SPEC
50+
#define CC1_SPEC \
51+
"%{G*} %{,ada:-gnatea %{mabi=*} -gnatez} " \
52+
"%(subtarget_cc1_spec)"
53+
54+
#undef ASM_SPEC
55+
#define ASM_SPEC \
56+
"%{mabi=*} %(subtarget_asm_spec)"
57+
58+
2659
extern const char*
2760
la_driver_init (int argc, const char **argv);
2861

@@ -45,7 +78,16 @@ driver_get_normalized_m_opts (int argc, const char **argv);
4578
#define LA_SET_PARM_SPEC(NAME) \
4679
" %{m" OPTSTR_##NAME "=*: %:set_m_parm(" OPTSTR_##NAME " %*)}" \
4780

81+
/* For MLIB_SELF_SPECS. */
82+
#include "loongarch-multilib.h"
83+
84+
#ifndef MLIB_SELF_SPECS
85+
#define MLIB_SELF_SPECS ""
86+
#endif
87+
4888
#define DRIVER_HANDLE_MACHINE_OPTIONS \
89+
" %(early_self_spec)", \
90+
MLIB_SELF_SPECS \
4991
" %:driver_init()" \
5092
" %{c|S|E|nostdlib: %:set_no_link()}" \
5193
" %{nostartfiles: %{nodefaultlibs: %:set_no_link()}}" \

gcc/config/loongarch/loongarch.h

-50
Original file line numberDiff line numberDiff line change
@@ -64,56 +64,6 @@ along with GCC; see the file COPYING3. If not see
6464
#define NM_FLAGS "-Bn"
6565
#endif
6666

67-
/* SUBTARGET_ASM_SPEC is always passed to the assembler. It may be
68-
overridden by subtargets. */
69-
70-
#ifndef SUBTARGET_ASM_SPEC
71-
#define SUBTARGET_ASM_SPEC ""
72-
#endif
73-
74-
#undef ASM_SPEC
75-
#define ASM_SPEC "%{mabi=*} %{subtarget_asm_spec}"
76-
77-
/* Extra switches sometimes passed to the linker. */
78-
79-
#ifndef LINK_SPEC
80-
#define LINK_SPEC ""
81-
#endif /* LINK_SPEC defined */
82-
83-
/* Specs for the compiler proper. */
84-
85-
/* CC1_SPEC is the set of arguments to pass to the compiler proper. */
86-
87-
#undef CC1_SPEC
88-
#define CC1_SPEC "%{,ada:-gnatea} %{m*} \
89-
%{G*} \
90-
%(subtarget_cc1_spec) %{,ada:-gnatez}"
91-
92-
/* Preprocessor specs. */
93-
94-
/* SUBTARGET_CPP_SPEC is passed to the preprocessor. It may be
95-
overridden by subtargets. */
96-
#ifndef SUBTARGET_CPP_SPEC
97-
#define SUBTARGET_CPP_SPEC ""
98-
#endif
99-
100-
#define CPP_SPEC "%(subtarget_cpp_spec)"
101-
102-
/* This macro defines names of additional specifications to put in the specs
103-
that can be used in various specifications like CC1_SPEC. Its definition
104-
is an initializer with a subgrouping for each command option.
105-
106-
Each subgrouping contains a string constant, that defines the
107-
specification name, and a string constant that used by the GCC driver
108-
program.
109-
110-
Do not define this macro if it does not need to do anything. */
111-
112-
#define EXTRA_SPECS \
113-
{"subtarget_cc1_spec", SUBTARGET_CC1_SPEC}, \
114-
{"subtarget_cpp_spec", SUBTARGET_CPP_SPEC}, \
115-
{"subtarget_asm_spec", SUBTARGET_ASM_SPEC},
116-
11767
/* Registers may have a prefix which can be ignored when matching
11868
user asm and register definitions. */
11969
#ifndef REGISTER_PREFIX

gcc/config/loongarch/t-linux

+7-59
Original file line numberDiff line numberDiff line change
@@ -16,68 +16,16 @@
1616
# along with GCC; see the file COPYING3. If not see
1717
# <http://www.gnu.org/licenses/>.
1818

19-
# Multilib
20-
MULTILIB_OPTIONS = mabi=lp64d/mabi=lp64f/mabi=lp64s
21-
MULTILIB_DIRNAMES = base/lp64d base/lp64f base/lp64s
22-
23-
# The GCC driver always gets all abi-related options on the command line.
24-
# (see loongarch-driver.c:driver_get_normalized_m_opts)
25-
comma=,
26-
MULTILIB_REQUIRED = $(foreach mlib,$(subst $(comma), ,$(TM_MULTILIB_CONFIG)),\
27-
$(firstword $(subst /, ,$(mlib))))
28-
29-
SPECS = specs.install
30-
31-
# temporary self_spec when building libraries (e.g. libgcc)
32-
gen_mlib_spec = $(if $(word 2,$1),\
33-
%{$(firstword $1):$(patsubst %,-%,$(wordlist 2,$(words $1),$1))})
34-
35-
# clean up the result of DRIVER_SELF_SPEC to avoid conflict
36-
lib_build_self_spec = %<march=* %<mtune=* %<mcmodel=* %<mfpu=* %<msimd=*
37-
38-
# append user-specified build options from --with-multilib-list
39-
lib_build_self_spec += $(foreach mlib,\
40-
$(subst $(comma), ,$(TM_MULTILIB_CONFIG)),\
41-
$(call gen_mlib_spec,$(subst /, ,$(mlib))))
42-
43-
specs: specs.install
44-
sed '/^*self_spec:$$/{ n;s/^$$/$(lib_build_self_spec)/g; }' $< > $@
45-
46-
# Do some preparation before regression tests:
47-
# remove lib-build-specs / make symlinks for the toplevel multilib variant
48-
49-
LA_DEFAULT_MULTISUBDIR = $(shell $(GCC_FOR_TARGET) --print-multi-dir)
50-
.PHONY: remove-lib-specs
51-
check check-host check-target $(CHECK_TARGETS) $(lang_checks): remove-lib-specs
52-
remove-lib-specs:
53-
-mv -f specs.install specs 2>/dev/null
54-
-mv $(LA_DEFAULT_MULTISUBDIR)/* ./
55-
-mkdir -p ../$(target_noncanonical)/`dirname $(LA_DEFAULT_MULTISUBDIR)`
56-
-$(LN_S) .. ../$(target_noncanonical)/$(LA_DEFAULT_MULTISUBDIR)
57-
58-
# Multiarch
59-
ifneq ($(call if_multiarch,yes),yes)
60-
# Define LA_DISABLE_MULTIARCH if multiarch is disabled.
61-
tm_defines += LA_DISABLE_MULTIARCH
62-
else
63-
# Only define MULTIARCH_DIRNAME when multiarch is enabled,
64-
# or it would always introduce ${target} into the search path.
65-
MULTIARCH_DIRNAME = $(LA_MULTIARCH_TRIPLET)
66-
endif
19+
MULTIOSDIR_lp64d := ../lib64$(call if_multiarch,:loongarch64-linux-gnu)
20+
MULTIOSDIR_lp64f := ../lib64/f32$(call if_multiarch,:loongarch64-linux-gnuf32)
21+
MULTIOSDIR_lp64s := ../lib64/sf$(call if_multiarch,:loongarch64-linux-gnusf)
6722

6823
# Don't define MULTILIB_OSDIRNAMES if multilib is disabled.
6924
ifeq ($(filter LA_DISABLE_MULTILIB,$(tm_defines)),)
7025

71-
MULTILIB_OSDIRNAMES = \
72-
mabi.lp64d=../lib64$\
73-
$(call if_multiarch,:loongarch64-linux-gnu)
74-
75-
MULTILIB_OSDIRNAMES += \
76-
mabi.lp64f=../lib64/f32$\
77-
$(call if_multiarch,:loongarch64-linux-gnuf32)
78-
79-
MULTILIB_OSDIRNAMES += \
80-
mabi.lp64s=../lib64/sf$\
81-
$(call if_multiarch,:loongarch64-linux-gnusf)
26+
MULTILIB_OSDIRNAMES = .=$(MULTIOSDIR_$(mlib_default))
27+
MULTILIB_OSDIRNAMES += mabi.lp64d=$(MULTIOSDIR_lp64d)
28+
MULTILIB_OSDIRNAMES += mabi.lp64f=$(MULTIOSDIR_lp64f)
29+
MULTILIB_OSDIRNAMES += mabi.lp64s=$(MULTIOSDIR_lp64s)
8230

8331
endif

gcc/config/loongarch/t-loongarch

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# along with GCC; see the file COPYING3. If not see
1717
# <http://www.gnu.org/licenses/>.
1818

19-
TM_H += $(srcdir)/config/loongarch/loongarch-driver.h
19+
TM_H += loongarch-multilib.h $(srcdir)/config/loongarch/loongarch-driver.h
2020
OPTIONS_H_EXTRA += $(srcdir)/config/loongarch/loongarch-def.h \
2121
$(srcdir)/config/loongarch/loongarch-tune.h
2222

gcc/config/loongarch/t-multilib

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (C) 2023 Free Software Foundation, Inc.
2+
#
3+
# This file is part of GCC.
4+
#
5+
# GCC is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 3, or (at your option)
8+
# any later version.
9+
#
10+
# GCC is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with GCC; see the file COPYING3. If not see
17+
# <http://www.gnu.org/licenses/>.
18+
19+
# Helper definitions
20+
comma=,
21+
null :=
22+
space := $(null) #
23+
exclude_1st = $(wordlist 2,$(words $1),$1)
24+
25+
# Common definitions
26+
mlib_all := lp64d lp64f lp64s
27+
$(foreach i,$(mlib_all),$(eval MULTISUBDIR_$i := base/$i))
28+
29+
mlib_default := $(firstword $(subst $(comma), ,$(TM_MULTILIB_CONFIG)))
30+
mlib_all := $(filter-out $(mlib_default),$(mlib_all))
31+
32+
MULTILIB_OPTIONS := $(subst $(space),/,$(foreach i,$(mlib_all),mabi=$(i)))
33+
MULTILIB_DIRNAMES := $(foreach i,$(mlib_all),$(MULTISUBDIR_$(i)))
34+
35+
# Customize builds with --with-multilib-list
36+
MULTILIB_REQUIRED := $(foreach i,$(call exclude_1st,\
37+
$(subst $(comma), ,$(TM_MULTILIB_CONFIG))),\
38+
$(firstword $(subst /, ,$(i))))
39+
40+
## spec rules for building libraries, triggered by -fmultiflags
41+
gen_mlib_spec = $(if $(word 2,$1),\
42+
%{$(firstword $1):$(patsubst %,-%,$(call exclude_1st,$1)}))
43+
44+
lib_build_spec = $(foreach mlib,\
45+
$(call exclude_1st,$(subst $(comma), ,$(TM_MULTILIB_CONFIG))),\
46+
$(call gen_mlib_spec,$(subst /, ,$(mlib))))
47+
48+
default_mlib_spec := %{fmultiflags:%{!mabi=*:-mabi=$(mlib_default)}}
49+
lib_build_spec := %{fmultiflags:$(lib_build_spec)}
50+
51+
ifneq ($(TM_MULTILIB_CONFIG),)
52+
loongarch-multilib.h:
53+
@echo "#define MLIB_SELF_SPECS" \
54+
"\"$(default_mlib_spec)\"," \
55+
"\"$(lib_build_spec)\"," > $@
56+
else
57+
loongarch-multilib.h: ; @touch $@
58+
endif
59+
60+
# Multiarch
61+
ifneq ($(call if_multiarch,yes),yes)
62+
# Define LA_DISABLE_MULTIARCH if multiarch is disabled.
63+
tm_defines += LA_DISABLE_MULTIARCH
64+
else
65+
# Only define MULTIARCH_DIRNAME when multiarch is enabled,
66+
# or it would always introduce ${target} into the search path.
67+
MULTIARCH_DIRNAME = $(LA_MULTIARCH_TRIPLET)
68+
endif

0 commit comments

Comments
 (0)