On 11/23/18 7:08 PM, Joseph Myers wrote: > On Fri, 23 Nov 2018, Martin Liška wrote: > >> Looks the problematic is quite complex as I can understand. I prepared a >> patch >> that should hopefully follow advises provided.
Hello. > > I don't see how this version ensures that NATIVE_SYSTEM_HEADER_DIR is > properly sysrooted. Note there's add_sysrooted_prefix separate from > add_prefix (but that's *not* the correct thing to use here because it uses > target_sysroot_suffix whereas you need target_sysroot_hdrs_suffix). I address that in updated version of the patch. > > The last argument to add_prefix, which you're setting to true, is > os_multilib. But using the OS multilib scheme seems wrong here, because > the OS multilib names are names like "../lib64", which only make sense in > directories called lib - you don't want to end up searching a directory > <something>/include/finclude/../lib64. Agree, does not make sense. > > In the multiarch case, do you want > <something>/include/finclude/<multiarch> or > <something>/include/<multiarch>/finclude? (This is where I'd hope Debian > / Ubuntu GCC people would comment.) > As Mathias wrote he's fine with both of these variants. I've just configure a compiler with --enable-multiarch=yes and I see that the file is eventually searched in: /usr/include/finclude/i386-linux-gnu/math-vector-fortran.h (with -m32) and /usr/include/finclude/x86_64-linux-gnu/math-vector-fortran.h (with -m64) Which looks fine to me? Thanks, Martin
>From 84202b443adc00e0847b17c07e3dbf3451e77fb9 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Tue, 20 Nov 2018 15:09:16 +0100 Subject: [PATCH] Extend locations where to seach for Fortran pre-include. --- gcc/Makefile.in | 4 +- gcc/config/gnu-user.h | 2 +- gcc/gcc.c | 99 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 83 insertions(+), 22 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 16c9ed6c5fd..c6ded7baf79 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2172,7 +2172,9 @@ DRIVER_DEFINES = \ @TARGET_SYSTEM_ROOT_DEFINE@ \ $(VALGRIND_DRIVER_DEFINES) \ $(if $(SHLIB),$(if $(filter yes,@enable_shared@),-DENABLE_SHARED_LIBGCC)) \ - -DCONFIGURE_SPECS="\"@CONFIGURE_SPECS@\"" + -DCONFIGURE_SPECS="\"@CONFIGURE_SPECS@\"" \ + -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \ + -DNATIVE_SYSTEM_HEADER_DIR=\"$(NATIVE_SYSTEM_HEADER_DIR)\" CFLAGS-gcc.o += $(DRIVER_DEFINES) -DBASEVER=$(BASEVER_s) gcc.o: $(BASEVER) diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index d0acfed5116..eff6c7d6f83 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -173,4 +173,4 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #undef TARGET_F951_OPTIONS #define TARGET_F951_OPTIONS "%{!nostdinc:\ - %:fortran-preinclude-file(-fpre-include= math-vector-fortran.h)}" + %:fortran-preinclude-file(-fpre-include= math-vector-fortran.h finclude%s/)}" diff --git a/gcc/gcc.c b/gcc/gcc.c index 4d01e1e2f3b..7c57fe03b41 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -2976,6 +2976,45 @@ add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix, add_prefix (pprefix, prefix, component, priority, require_machine_suffix, os_multilib); } + +/* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */ + +static void +add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix, + const char *component, + /* enum prefix_priority */ int priority, + int require_machine_suffix, int os_multilib) +{ + if (!IS_ABSOLUTE_PATH (prefix)) + fatal_error (input_location, "system path %qs is not absolute", prefix); + + if (target_sysroot_hdrs_suffix) + { + char *sysroot_no_trailing_dir_separator + = xstrdup (target_sysroot_hdrs_suffix); + size_t sysroot_len = strlen (target_sysroot_hdrs_suffix); + + if (sysroot_len > 0 + && target_sysroot_hdrs_suffix [sysroot_len - 1] == DIR_SEPARATOR) + sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; + + if (target_sysroot_suffix) + prefix = concat (sysroot_no_trailing_dir_separator, + target_sysroot_suffix, prefix, NULL); + else + prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); + + free (sysroot_no_trailing_dir_separator); + + /* We have to override this because GCC's notion of sysroot + moves along with GCC. */ + component = "GCC"; + } + + add_prefix (pprefix, prefix, component, priority, + require_machine_suffix, os_multilib); +} + /* Execute the command specified by the arguments on the current line of spec. When using pipes, this includes several piped-together commands @@ -9891,20 +9930,56 @@ debug_level_greater_than_spec_func (int argc, const char **argv) return NULL; } -/* The function takes 2 arguments: OPTION name and file name. +static void +path_prefix_reset (path_prefix *prefix) +{ + struct prefix_list *iter, *next; + iter = prefix->plist; + while (iter) + { + next = iter->next; + free (const_cast <char *> (iter->prefix)); + XDELETE (iter); + iter = next; + } + prefix->plist = 0; + prefix->max_len = 0; +} + +/* The function takes 3 arguments: OPTION name, file name and location + where we search for Fortran modules. When the FILE is found by find_file, return OPTION=path_to_file. */ static const char * find_fortran_preinclude_file (int argc, const char **argv) { - if (argc != 2) + char *result = NULL; + if (argc != 3) return NULL; + struct path_prefix prefixes = { 0, 0, "preinclude" }; + add_sysrooted_hdrs_prefix (&prefixes, argv[2], NULL, 0, 0, false); +#ifdef TOOL_INCLUDE_DIR + add_sysrooted_hdrs_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/", + NULL, 0, 0, false); +#endif +#ifdef NATIVE_SYSTEM_HEADER_DIR + add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/", + NULL, 0, 0, false); +#endif + const char *path = find_a_file (&include_prefixes, argv[1], R_OK, true); if (path != NULL) - return concat (argv[0], path, NULL); + result = concat (argv[0], path, NULL); + else + { + path = find_a_file (&prefixes, argv[1], R_OK, true); + if (path != NULL) + result = concat (argv[0], path, NULL); + } - return NULL; + path_prefix_reset (&prefixes); + return result; } @@ -9956,22 +10031,6 @@ convert_white_space (char *orig) return orig; } -static void -path_prefix_reset (path_prefix *prefix) -{ - struct prefix_list *iter, *next; - iter = prefix->plist; - while (iter) - { - next = iter->next; - free (const_cast <char *> (iter->prefix)); - XDELETE (iter); - iter = next; - } - prefix->plist = 0; - prefix->max_len = 0; -} - /* Restore all state within gcc.c to the initial state, so that the driver code can be safely re-run in-process. -- 2.19.1