From 77adc39ef3ec65e20e427a19678d515d92a91d5f Mon Sep 17 00:00:00 2001 From: doko Date: Wed, 14 Nov 2012 21:29:15 +0000 Subject: [PATCH] 2012-11-14 Matthias Klose * doc/invoke.texi: Document -print-multiarch. * doc/install.texi: Document --enable-multiarch. * doc/fragments.texi: Document MULTILIB_OSDIRNAMES, MULTIARCH_DIRNAME. * configure.ac: Add --enable-multiarch option. * configure: Regenerate. * Makefile.in (s-mlib): Pass MULTIARCH_DIRNAME to genmultilib. enable_multiarch, with_float: New macros. if_multiarch: New macro, define in terms of enable_multiarch. * genmultilib: Add new argument for the multiarch name. * gcc.c (multiarch_dir): Define. (for_each_path): Search for multiarch suffixes. (driver_handle_option): Handle multiarch option. (do_spec_1): Pass -imultiarch if defined. (main): Print multiarch. (set_multilib_dir): Separate multilib and multiarch names from multilib_select. (print_multilib_info): Ignore multiarch names in multilib_select. * incpath.c (add_standard_paths): Search the multiarch include dirs. * cppdefault.h (default_include): Document multiarch in multilib member. * cppdefault.c: [LOCAL_INCLUDE_DIR, STANDARD_INCLUDE_DIR] Add an include directory for multiarch directories. * common.opt: New options --print-multiarch and -imultilib. * config.gcc (tmake_file): Include i386/t-linux. (tmake_file): Include i386/t-kfreebsd. (tmake_file): Include i386/t-gnu. * config/i386/t-linux64: Add multiarch names in MULTILIB_OSDIRNAMES, define MULTIARCH_DIRNAME. * config/i386/t-gnu: New file. * config/i386/t-kfreebsd: Likewise. * config/i386/t-linux: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193508 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 36 +++++++++++++++++ gcc/Makefile.in | 15 ++++++- gcc/common.opt | 10 +++++ gcc/config.gcc | 11 +++-- gcc/config/i386/t-gnu | 1 + gcc/config/i386/t-kfreebsd | 5 +++ gcc/config/i386/t-linux | 1 + gcc/config/i386/t-linux64 | 6 +-- gcc/configure | 39 ++++++++++++++++-- gcc/configure.ac | 25 ++++++++++++ gcc/cppdefault.c | 2 + gcc/cppdefault.h | 8 ++-- gcc/doc/fragments.texi | 60 ++++++++++++++++++++++++++++ gcc/doc/install.texi | 9 +++++ gcc/doc/invoke.texi | 5 +++ gcc/gcc.c | 82 ++++++++++++++++++++++++++++++++------ gcc/genmultilib | 15 +++++-- gcc/incpath.c | 16 +++++++- 18 files changed, 316 insertions(+), 30 deletions(-) create mode 100644 gcc/config/i386/t-gnu create mode 100644 gcc/config/i386/t-kfreebsd create mode 100644 gcc/config/i386/t-linux diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3930faf4f105..0c9b78933bc2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,39 @@ +2012-11-14 Matthias Klose + + * doc/invoke.texi: Document -print-multiarch. + * doc/install.texi: Document --enable-multiarch. + * doc/fragments.texi: Document MULTILIB_OSDIRNAMES, MULTIARCH_DIRNAME. + * configure.ac: Add --enable-multiarch option. + * configure: Regenerate. + * Makefile.in (s-mlib): Pass MULTIARCH_DIRNAME to genmultilib. + enable_multiarch, with_float: New macros. + if_multiarch: New macro, define in terms of enable_multiarch. + * genmultilib: Add new argument for the multiarch name. + * gcc.c (multiarch_dir): Define. + (for_each_path): Search for multiarch suffixes. + (driver_handle_option): Handle multiarch option. + (do_spec_1): Pass -imultiarch if defined. + (main): Print multiarch. + (set_multilib_dir): Separate multilib and multiarch names + from multilib_select. + (print_multilib_info): Ignore multiarch names in multilib_select. + * incpath.c (add_standard_paths): Search the multiarch include dirs. + * cppdefault.h (default_include): Document multiarch in multilib + member. + * cppdefault.c: [LOCAL_INCLUDE_DIR, STANDARD_INCLUDE_DIR] Add an + include directory for multiarch directories. + * common.opt: New options --print-multiarch and -imultilib. + * config.gcc (tmake_file): + Include i386/t-linux. + (tmake_file): + Include i386/t-kfreebsd. + (tmake_file): Include i386/t-gnu. + * config/i386/t-linux64: Add multiarch names in + MULTILIB_OSDIRNAMES, define MULTIARCH_DIRNAME. + * config/i386/t-gnu: New file. + * config/i386/t-kfreebsd: Likewise. + * config/i386/t-linux: Likewise. + 2012-11-14 Jan Hubicka * tree.c (set_call_expr_flags): New function. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 79a971fbf365..fb2fd8657a39 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -530,6 +530,18 @@ extra_modes_file=@extra_modes_file@ extra_opt_files=@extra_opt_files@ host_hook_obj=@out_host_hook_obj@ +# Multiarch support +enable_multiarch = @enable_multiarch@ +with_float = @with_float@ +ifeq ($(enable_multiarch),yes) + if_multiarch = $(1) +else ifeq ($(enable_multiarch),auto) + # SYSTEM_HEADER_DIR is makefile syntax, cannot be evaluated in configure.ac + if_multiarch = $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib/*/crti.o),$(1)) +else + if_multiarch = +endif + # ------------------------ # Installation directories # ------------------------ @@ -1809,10 +1821,11 @@ s-mlib: $(srcdir)/genmultilib Makefile "$(MULTILIB_EXCLUSIONS)" \ "$(MULTILIB_OSDIRNAMES)" \ "$(MULTILIB_REQUIRED)" \ + "$(MULTIARCH_DIRNAME)" \ "@enable_multilib@" \ > tmp-mlib.h; \ else \ - $(SHELL) $(srcdir)/genmultilib '' '' '' '' '' '' '' '' no\ + $(SHELL) $(srcdir)/genmultilib '' '' '' '' '' '' '' '' "$(MULTIARCH_DIRNAME)" no \ > tmp-mlib.h; \ fi $(SHELL) $(srcdir)/../move-if-change tmp-mlib.h multilib.h diff --git a/gcc/common.opt b/gcc/common.opt index f33b3b7eac32..0a7c953942e3 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -348,6 +348,9 @@ Driver Alias(print-multi-lib) -print-multi-os-directory Driver Alias(print-multi-os-directory) +-print-multiarch +Driver Alias(print-multiarch) + -print-prog-name Driver Separate Alias(print-prog-name=) @@ -2357,6 +2360,10 @@ iplugindir= Common Joined Var(plugindir_string) Init(0) -iplugindir= Set to be the default plugin directory +imultiarch +Common Joined Separate RejectDriver Var(imultiarch) Init(0) +-imultiarch Set to be the multiarch include subdirectory + l Driver Joined Separate @@ -2413,6 +2420,9 @@ Driver Var(print_multi_lib) print-multi-os-directory Driver Var(print_multi_os_directory) + +print-multiarch +Driver Var(print_multiarch) print-prog-name= Driver JoinedOrMissing Var(print_prog_name) diff --git a/gcc/config.gcc b/gcc/config.gcc index b0f6f1d0c4aa..665a7436349e 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -3640,9 +3640,14 @@ case ${target} in i[34567]86-*-darwin* | x86_64-*-darwin*) ;; - i[34567]86-*-linux* | x86_64-*-linux* | \ - i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \ - i[34567]86-*-gnu*) + i[34567]86-*-linux* | x86_64-*-linux*) + tmake_file="$tmake_file i386/t-linux" + ;; + i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu) + tmake_file="$tmake_file i386/t-kfreebsd" + ;; + i[34567]86-*-gnu*) + tmake_file="$tmake_file i386/t-gnu" ;; i[34567]86-*-solaris2* | x86_64-*-solaris2.1[0-9]*) ;; diff --git a/gcc/config/i386/t-gnu b/gcc/config/i386/t-gnu new file mode 100644 index 000000000000..5f946c71604f --- /dev/null +++ b/gcc/config/i386/t-gnu @@ -0,0 +1 @@ +MULTIARCH_DIRNAME = $(call if_multiarch,i386-gnu) diff --git a/gcc/config/i386/t-kfreebsd b/gcc/config/i386/t-kfreebsd new file mode 100644 index 000000000000..b4310df8afbb --- /dev/null +++ b/gcc/config/i386/t-kfreebsd @@ -0,0 +1,5 @@ +MULTIARCH_DIRNAME = $(call if_multiarch,i386-kfreebsd-gnu) + +# MULTILIB_OSDIRNAMES are set in t-linux64. +KFREEBSD_OS = $(filter kfreebsd%, $(word 3, $(subst -, ,$(target)))) +MULTILIB_OSDIRNAMES := $(subst linux,$(KFREEBSD_OS),$(MULTILIB_OSDIRNAMES)) diff --git a/gcc/config/i386/t-linux b/gcc/config/i386/t-linux new file mode 100644 index 000000000000..155314c08a7c --- /dev/null +++ b/gcc/config/i386/t-linux @@ -0,0 +1 @@ +MULTIARCH_DIRNAME = $(call if_multiarch,i386-linux-gnu) diff --git a/gcc/config/i386/t-linux64 b/gcc/config/i386/t-linux64 index b5d39855a706..dfaf2763d893 100644 --- a/gcc/config/i386/t-linux64 +++ b/gcc/config/i386/t-linux64 @@ -34,6 +34,6 @@ comma=, MULTILIB_OPTIONS = $(subst $(comma),/,$(TM_MULTILIB_CONFIG)) MULTILIB_DIRNAMES = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS))) -MULTILIB_OSDIRNAMES = m64=../lib64 -MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib) -MULTILIB_OSDIRNAMES+= mx32=../libx32 +MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-linux-gnu) +MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-linux-gnu) +MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x32-linux-gnu) diff --git a/gcc/configure b/gcc/configure index 3f1ca7411c05..cdfbaad4d9ed 100755 --- a/gcc/configure +++ b/gcc/configure @@ -765,6 +765,8 @@ SYSROOT_CFLAGS_FOR_TARGET enable_shared enable_fixed_point enable_decimal_float +with_float +enable_multiarch enable_multilib coverage_flags valgrind_command @@ -874,6 +876,7 @@ enable_coverage enable_gather_detailed_mem_stats with_stabs enable_multilib +enable_multiarch enable___cxa_atexit enable_decimal_float enable_fixed_point @@ -1574,6 +1577,7 @@ Optional Features: --enable-gather-detailed-mem-stats enable detailed memory allocation stats gathering --enable-multilib enable library support for multiple ABIs + --enable-multiarch enable support for multiarch paths --enable-__cxa_atexit enable __cxa_atexit for C++ --enable-decimal-float={no,yes,bid,dpd} enable decimal float extension to C. Selecting 'bid' @@ -7016,6 +7020,36 @@ fi +# Determine whether or not multiarch is enabled. +# Check whether --enable-multiarch was given. +if test "${enable_multiarch+set}" = set; then : + enableval=$enable_multiarch; case "${withval}" in +yes|no|auto) enable_multiarch=$withval;; +*) as_fn_error "bad value ${withval} given for --enable-multiarch option" "$LINENO" 5 ;; +esac +else + enable_multiarch=auto +fi + +if test x${enable_multiarch} = xauto; then + if test x${with_native_system_header_dir} != x; then + ma_msg_suffix=", disabled auto check (configured with --native-system-header-dir)" + enable_multiarch=no + fi + if test x$host != x$target && test "x$with_sysroot" = x; then + ma_msg_suffix=", disabled auto check (cross build configured without --with-sysroot)" + enable_multiarch=no + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for multiarch configuration" >&5 +$as_echo_n "checking for multiarch configuration... " >&6; } + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_multiarch$ma_msg_suffix" >&5 +$as_echo "$enable_multiarch$ma_msg_suffix" >&6; } + +# needed for setting the multiarch name for soft-float/hard-float ABIs + + # Enable __cxa_atexit for C++. # Check whether --enable-__cxa_atexit was given. if test "${enable___cxa_atexit+set}" = set; then : @@ -7038,7 +7072,6 @@ else case $target in powerpc*-*-linux* | i?86*-*-linux* | x86_64*-*-linux* | s390*-*-linux* | \ - i?86*-*-gnu* | \ i?86*-*-mingw* | x86_64*-*-mingw* | \ i?86*-*-cygwin*) enable_decimal_float=yes @@ -17786,7 +17819,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 17789 "configure" +#line 17822 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -17892,7 +17925,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 17895 "configure" +#line 17928 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index efddb7a46b31..ac25623976ef 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -613,6 +613,31 @@ AC_ARG_ENABLE(multilib, [], [enable_multilib=yes]) AC_SUBST(enable_multilib) +# Determine whether or not multiarch is enabled. +AC_ARG_ENABLE(multiarch, +[AS_HELP_STRING([--enable-multiarch], + [enable support for multiarch paths])], +[case "${withval}" in +yes|no|auto) enable_multiarch=$withval;; +*) AC_MSG_ERROR(bad value ${withval} given for --enable-multiarch option) ;; +esac], [enable_multiarch=auto]) +if test x${enable_multiarch} = xauto; then + if test x${with_native_system_header_dir} != x; then + ma_msg_suffix=", disabled auto check (configured with --native-system-header-dir)" + enable_multiarch=no + fi + if test x$host != x$target && test "x$with_sysroot" = x; then + ma_msg_suffix=", disabled auto check (cross build configured without --with-sysroot)" + enable_multiarch=no + fi +fi +AC_MSG_CHECKING(for multiarch configuration) +AC_SUBST(enable_multiarch) +AC_MSG_RESULT($enable_multiarch$ma_msg_suffix) + +# needed for setting the multiarch name for soft-float/hard-float ABIs +AC_SUBST(with_float) + # Enable __cxa_atexit for C++. AC_ARG_ENABLE(__cxa_atexit, [AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])], diff --git a/gcc/cppdefault.c b/gcc/cppdefault.c index 927083e939df..99c4c8814dfe 100644 --- a/gcc/cppdefault.c +++ b/gcc/cppdefault.c @@ -63,6 +63,7 @@ const struct default_include cpp_include_defaults[] #endif #ifdef LOCAL_INCLUDE_DIR /* /usr/local/include comes before the fixincluded header files. */ + { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 }, #endif #ifdef PREFIX_INCLUDE_DIR @@ -90,6 +91,7 @@ const struct default_include cpp_include_defaults[] #endif #ifdef NATIVE_SYSTEM_HEADER_DIR /* /usr/include comes dead last. */ + { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 }, { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 }, #endif { 0, 0, 0, 0, 0, 0 } diff --git a/gcc/cppdefault.h b/gcc/cppdefault.h index 657c4abce213..7f58a1be3108 100644 --- a/gcc/cppdefault.h +++ b/gcc/cppdefault.h @@ -43,9 +43,11 @@ struct default_include C++. */ const char add_sysroot; /* FNAME should be prefixed by cpp_SYSROOT. */ - const char multilib; /* FNAME should have the multilib path - specified with -imultilib - appended. */ + const char multilib; /* FNAME should have appended + - the multilib path specified with -imultilib + when set to 1, + - the multiarch path specified with + -imultiarch, when set to 2. */ }; extern const struct default_include cpp_include_defaults[]; diff --git a/gcc/doc/fragments.texi b/gcc/doc/fragments.texi index f53df29603e0..28cef689f157 100644 --- a/gcc/doc/fragments.texi +++ b/gcc/doc/fragments.texi @@ -93,6 +93,12 @@ Write one element in @code{MULTILIB_DIRNAMES} for each element in default value will be @code{MULTILIB_OPTIONS}, with all slashes treated as spaces. +@code{MULTILIB_DIRNAMES} describes the multilib directories using GCC +conventions and is applied to directories that are part of the GCC +installation. When multilib-enabled, the compiler will add a +subdirectory of the form @var{prefix}/@var{multilib} before each +directory in the search path for libraries and crt files. + For example, if @code{MULTILIB_OPTIONS} is set to @samp{m68000/m68020 msoft-float}, then the default value of @code{MULTILIB_DIRNAMES} is @samp{m68000 m68020 msoft-float}. You may specify a different value if @@ -152,6 +158,60 @@ compiler. In that case, set @code{MULTILIB_EXTRA_OPTS} to be the list of options to be used for all builds. If you set this, you should probably set @code{CRTSTUFF_T_CFLAGS} to a dash followed by it. +@findex MULTILIB_OSDIRNAMES +@item MULTILIB_OSDIRNAMES +If @code{MULTILIB_OPTIONS} is used, this variable specifies +a list of subdirectory names, that are used to modify the search +path depending on the chosen multilib. Unlike @code{MULTILIB_DIRNAMES}, +@code{MULTILIB_OSDIRNAMES} describes the multilib directories using +operating systems conventions, and is applied to the directories such as +@code{lib} or those in the @env{LIBRARY_PATH} environment variable. +The format is either the same as of +@code{MULTILIB_DIRNAMES}, or a set of mappings. When it is the same +as @code{MULTILIB_DIRNAMES}, it describes the multilib directories +using operating system conventions, rather than GCC conventions. When it is a set +of mappings of the form @var{gccdir}=@var{osdir}, the left side gives +the GCC convention and the right gives the equivalent OS defined +location. If the @var{osdir} part begins with a @samp{!}, +GCC will not search in the non-multilib directory and use +exclusively the multilib directory. Otherwise, the compiler will +examine the search path for libraries and crt files twice; the first +time it will add @var{multilib} to each directory in the search path, +the second it will not. + +For configurations that support both multilib and multiarch, +@code{MULTILIB_OSDIRNAMES} also encodes the multiarch name, thus +subsuming @code{MULTIARCH_DIRNAME}. The multiarch name is appended to +each directory name, separated by a colon (e.g. +@samp{../lib32:i386-linux-gnu}). + +Each multiarch subdirectory will be searched before the corresponding OS +multilib directory, for example @samp{/lib/i386-linux-gnu} before +@samp{/lib/../lib32}. The multiarch name will also be used to modify the +system header search path, as explained for @code{MULTIARCH_DIRNAME}. + +@findex MULTIARCH_DIRNAME +@item MULTIARCH_DIRNAME +This variable specifies the multiarch name for configurations that are +multiarch-enabled but not multilibbed configurations. + +The multiarch name is used to augment the search path for libraries, crt +files and system header files with additional locations. The compiler +will add a multiarch subdirectory of the form +@var{prefix}/@var{multiarch} before each directory in the library and +crt search path. It will also add two directories +@code{LOCAL_INCLUDE_DIR}/@var{multiarch} and +@code{NATIVE_SYSTEM_HEADER_DIR}/@var{multiarch}) to the system header +search path, respectively before @code{LOCAL_INCLUDE_DIR} and +@code{NATIVE_SYSTEM_HEADER_DIR}. + +@code{MULTIARCH_DIRNAME} is not used for configurations that support +both multilib and multiarch. In that case, multiarch names are encoded +in @code{MULTILIB_OSDIRNAMES} instead. + +More documentation about multiarch can be found at +@uref{http://wiki.debian.org/Multiarch}. + @findex SPECS @item SPECS Unfortunately, setting @code{MULTILIB_EXTRA_OPTS} is not enough, since diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index f158eb2f9e2a..7396158acea5 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1033,6 +1033,15 @@ libraries to support different target variants, calling conventions, etc.@: should not be built. The default is to build a predefined set of them. +@item --enable-multiarch +Specify whether to enable or disable multiarch support. The default is +to check for glibc start files in a multiarch location, and enable it +if the files are found. The auto detection is enabled for native builds, +and for cross builds configured with @option{--with-sysroot}, and without +@option{--with-native-system-header-dir}. +More documentation about multiarch can be found at +@uref{http://wiki.debian.org/Multiarch}. + Some targets provide finer-grained control over which multilibs are built (e.g., @option{--disable-softfloat}): @table @code diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 6f03a5570878..e019e3d2cdb6 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6336,6 +6336,11 @@ sibling directories this prints e.g.@: @file{../lib64}, @file{../lib} or @file{../lib32}, or if OS libraries are present in @file{lib/@var{subdir}} subdirectories it prints e.g.@: @file{amd64}, @file{sparcv9} or @file{ev6}. +@item -print-multiarch +@opindex print-multiarch +Print the path to OS libraries for the selected multiarch, +relative to some @file{lib} subdirectory. + @item -print-prog-name=@var{program} @opindex print-prog-name Like @option{-print-file-name}, but searches for a program such as @samp{cpp}. diff --git a/gcc/gcc.c b/gcc/gcc.c index 210277130f5f..e584319369e9 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -1163,6 +1163,11 @@ static const char *multilib_dir; set_multilib_dir based on the compilation options. */ static const char *multilib_os_dir; + +/* Subdirectory to use for locating libraries in multiarch conventions. Set by + set_multilib_dir based on the compilation options. */ + +static const char *multiarch_dir; /* Structure to keep track of the specs that have been defined so far. These are accessed using %(specname) in a compiler or link @@ -2094,6 +2099,7 @@ for_each_path (const struct path_prefix *paths, struct prefix_list *pl; const char *multi_dir = NULL; const char *multi_os_dir = NULL; + const char *multiarch_suffix = NULL; const char *multi_suffix; const char *just_multi_suffix; char *path = NULL; @@ -2111,11 +2117,14 @@ for_each_path (const struct path_prefix *paths, } if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0) multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL); + if (multiarch_dir) + multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL); while (1) { size_t multi_dir_len = 0; size_t multi_os_dir_len = 0; + size_t multiarch_len = 0; size_t suffix_len; size_t just_suffix_len; size_t len; @@ -2124,16 +2133,15 @@ for_each_path (const struct path_prefix *paths, multi_dir_len = strlen (multi_dir); if (multi_os_dir) multi_os_dir_len = strlen (multi_os_dir); + if (multiarch_suffix) + multiarch_len = strlen (multiarch_suffix); suffix_len = strlen (multi_suffix); just_suffix_len = strlen (just_multi_suffix); if (path == NULL) { len = paths->max_len + extra_space + 1; - if (suffix_len > multi_os_dir_len) - len += suffix_len; - else - len += multi_os_dir_len; + len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len); path = XNEWVEC (char, len); } @@ -2162,6 +2170,16 @@ for_each_path (const struct path_prefix *paths, break; } + /* Now try the multiarch path. */ + if (!skip_multi_dir + && !pl->require_machine_suffix && multiarch_dir) + { + memcpy (path + len, multiarch_suffix, multiarch_len + 1); + ret = callback (path, callback_info); + if (ret) + break; + } + /* Now try the base path. */ if (!pl->require_machine_suffix && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) @@ -2990,6 +3008,9 @@ display_help (void) fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout); fputs (_(" -print-file-name= Display the full path to library \n"), stdout); fputs (_(" -print-prog-name= Display the full path to compiler component \n"), stdout); + fputs (_("\ + -print-multiarch Display the target's normalized GNU triplet, used as\n\ + a component in the library path\n"), stdout); fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout); fputs (_("\ -print-multi-lib Display the mapping between command line options and\n\ @@ -3274,6 +3295,7 @@ driver_handle_option (struct gcc_options *opts, case OPT_print_multi_directory: case OPT_print_sysroot: case OPT_print_multi_os_directory: + case OPT_print_multiarch: case OPT_print_sysroot_headers_suffix: case OPT_time: case OPT_wrapper: @@ -4924,6 +4946,15 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) do_spec_1 (" ", 0, NULL); } + if (multiarch_dir) + { + do_spec_1 ("-imultiarch", 1, NULL); + /* Make this a separate argument. */ + do_spec_1 (" ", 0, NULL); + do_spec_1 (multiarch_dir, 1, NULL); + do_spec_1 (" ", 0, NULL); + } + if (gcc_exec_prefix) { do_spec_1 ("-iprefix", 1, NULL); @@ -6593,6 +6624,15 @@ main (int argc, char **argv) return (0); } + if (print_multiarch) + { + if (multiarch_dir == NULL) + printf ("\n"); + else + printf ("%s\n", multiarch_dir); + return (0); + } + if (print_sysroot) { if (target_system_root) @@ -7364,7 +7404,9 @@ default_arg (const char *p, int len) options are present, then we will ignore this completely. Passing that, gcc will consider each multilib_select in turn using the same rules for matching the options. If a match is found, that subdirectory - will be used. */ + will be used. + A subdirectory name is optionally followed by a colon and the corresponding + multiarch name. */ static void set_multilib_dir (void) @@ -7576,10 +7618,25 @@ set_multilib_dir (void) q++; if (q < end) { - char *new_multilib_os_dir = XNEWVEC (char, end - q); - memcpy (new_multilib_os_dir, q + 1, end - q - 1); - new_multilib_os_dir[end - q - 1] = '\0'; - multilib_os_dir = new_multilib_os_dir; + const char *q2 = q + 1, *ml_end = end; + char *new_multilib_os_dir; + + while (q2 < end && *q2 != ':') + q2++; + if (*q2 == ':') + ml_end = q2; + new_multilib_os_dir = XNEWVEC (char, ml_end - q); + memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1); + new_multilib_os_dir[ml_end - q - 1] = '\0'; + multilib_os_dir = *new_multilib_os_dir ? new_multilib_os_dir : "."; + + if (q2 < end && *q2 == ':') + { + char *new_multiarch_dir = XNEWVEC (char, end - q2); + memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1); + new_multiarch_dir[end - q2 - 1] = '\0'; + multiarch_dir = new_multiarch_dir; + } break; } } @@ -7639,9 +7696,10 @@ print_multilib_info (void) } /* When --disable-multilib was used but target defines - MULTILIB_OSDIRNAMES, entries starting with .: are there just - to find multilib_os_dir, so skip them from output. */ - if (this_path[0] == '.' && this_path[1] == ':') + MULTILIB_OSDIRNAMES, entries starting with .: (and not starting + with .:: for multiarch configurations) are there just to find + multilib_os_dir, so skip them from output. */ + if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':') skip = 1; /* Check for matches with the multilib_exclusions. We don't bother diff --git a/gcc/genmultilib b/gcc/genmultilib index dc4751b0439b..09b63465b26a 100644 --- a/gcc/genmultilib +++ b/gcc/genmultilib @@ -84,6 +84,8 @@ # This argument can be used together with MULTILIB_EXCEPTIONS and will take # effect after the MULTILIB_EXCEPTIONS. +# The optional ninth argument is the multiarch name. + # The last option should be "yes" if multilibs are enabled. If it is not # "yes", all GCC multilib dir names will be ".". @@ -133,7 +135,8 @@ extra=$5 exclusions=$6 osdirnames=$7 multilib_required=$8 -enable_multilib=$9 +multiarch=$9 +enable_multilib=${10} echo "static const char *const multilib_raw[] = {" @@ -261,6 +264,9 @@ fi # names. toosdirnames= defaultosdirname= +if [ -n "${multiarch}" ]; then + defaultosdirname=::${multiarch} +fi if [ -n "${osdirnames}" ]; then set x ${osdirnames} shift @@ -268,6 +274,9 @@ if [ -n "${osdirnames}" ]; then case "$1" in .=*) defaultosdirname=`echo $1 | sed 's|^.=|:|'` + if [ -n "${multiarch}" ]; then + defaultosdirname=${defaultosdirname}:${multiarch} + fi shift ;; *=*) @@ -353,13 +362,13 @@ for combo in ${combinations}; do dirout=`echo ${combo} | sed -e 's/=/-/g'` fi # Remove the leading and trailing slashes. - dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/$||g'` + dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'` # Use the OS directory names rather than the option names. if [ -n "${toosdirnames}" ]; then osdirout=`echo ${combo} | sed ${toosdirnames}` # Remove the leading and trailing slashes. - osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/$||g'` + osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'` if [ "x${enable_multilib}" != xyes ]; then dirout=".:${osdirout}" disable_multilib=yes diff --git a/gcc/incpath.c b/gcc/incpath.c index 6693bf524503..efcd2c75e573 100644 --- a/gcc/incpath.c +++ b/gcc/incpath.c @@ -150,8 +150,14 @@ add_standard_paths (const char *sysroot, const char *iprefix, if (!filename_ncmp (p->fname, cpp_GCC_INCLUDE_DIR, len)) { char *str = concat (iprefix, p->fname + len, NULL); - if (p->multilib && imultilib) + if (p->multilib == 1 && imultilib) str = concat (str, dir_separator_str, imultilib, NULL); + else if (p->multilib == 2) + { + if (!imultiarch) + continue; + str = concat (str, dir_separator_str, imultiarch, NULL); + } add_path (str, SYSTEM, p->cxx_aware, false); } } @@ -203,8 +209,14 @@ add_standard_paths (const char *sysroot, const char *iprefix, else str = update_path (p->fname, p->component); - if (p->multilib && imultilib) + if (p->multilib == 1 && imultilib) str = concat (str, dir_separator_str, imultilib, NULL); + else if (p->multilib == 2) + { + if (!imultiarch) + continue; + str = concat (str, dir_separator_str, imultiarch, NULL); + } add_path (str, SYSTEM, p->cxx_aware, false); } -- 2.39.5