On 11/22/18 3:35 PM, Joseph Myers wrote: > On Thu, 22 Nov 2018, Martin Liška wrote: > >>> (Multilib suffixes on include directories for C are more or less an >>> implementation detail of how fixed headers are arranged in the case where >>> sysroot headers suffixes are used; they aren't really expected to be a >>> stable interface such that third-party software might install anything >>> using them, but I'm not sure if this preinclude is meant to come from >>> external software or be installed by GCC. >> >> It will come from glibc-devel package, and it's expected to be installed in: >> usr/include/finclude/ for 64-bit header >> and /usr/include/finclude/32/ for the 32-bit header. > > So, to be clear, is that > > <sysroot><sysroot-headers-suffix><native-system-header-dir>/finclude/$($CC > $CFLAGS $CPPFLAGS -print-multi-directory) > > ? (Where glibc would be what uses the $CC $CFLAGS $CPPFLAGS > -print-multi-directory to determine where to install the file.) > > If so, you need to make sure that all of those pieces are properly used. > > * The sysroot and headers suffix in the case of a sysrooted toolchain. > (Sysroot headers suffixes are for e.g. the case of a toolchain with both > glibc and uClibc multilibs, so needing multiple sets of headers. Most > toolchains with multiple sysroots using the same libc only need a single > set of headers and don't use sysroot headers suffixes, only sysroot > suffixes (non-headers), with appropriate arrangements being made for all > the per-multilib headers, such as gnu/lib-names-*.h and gnu/stubs-*.h, to > be copied into the common include directory.) > > * The native system header directory (which is /include not /usr/include > for GNU Hurd, for example; see config.gcc). > > * Then finclude with the multilib (non-OS) suffix. > > And you need to consider what's right for non-sysrooted toolchains. If > native, the above is right, but without the sysroot-related components. > But what about a non-sysrooted cross toolchain? Certainly using the > native directory would be wrong there. > > Also, what's right in the multiarch directory arrangements case - should > it be > <sysroot><sysroot-headers-suffix><native-system-header-dir>/<multiarch>/finclude > > instead? Would one of the Debian / Ubuntu GCC maintainers like to > comment? > > Are there corresponding versions with /usr/local/include > (LOCAL_INCLUDE_DIR, in general), before those with > NATIVE_SYSTEM_HEADER_DIR? Even in the driver, the list of directories in > cppdefault.c should at least serve as a guide to which directories you > want to search and which get sysroots added (of course, the C++-specific > ones are irrelevant here). >
Hi. Looks the problematic is quite complex as I can understand. I prepared a patch that should hopefully follow advises provided. Thoughts? Thanks, Martin
>From b59f043ff448f06ac95981d8a61b0dd63bc58bd7 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 | 58 ++++++++++++++++++++++++++++--------------- 3 files changed, 42 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..3b8b8eaf1bb 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -9891,20 +9891,54 @@ 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_prefix (&prefixes, argv[2], NULL, 0, 0, true); +#ifdef TOOL_INCLUDE_DIR + add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/", NULL, 0, 0, true); +#endif +#ifdef NATIVE_SYSTEM_HEADER_DIR + add_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/", NULL, 0, 0, true); +#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 +9990,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