From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RDNS_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 22691 invoked from network); 23 Mar 2020 04:35:20 -0000 Received-SPF: pass (mother.openwall.net: domain of lists.openwall.com designates 195.42.179.200 as permitted sender) receiver=inbox.vuxu.org; client-ip=195.42.179.200 envelope-from= Received: from unknown (HELO mother.openwall.net) (195.42.179.200) by inbox.vuxu.org with ESMTP; 23 Mar 2020 04:35:20 -0000 Received: (qmail 9267 invoked by uid 550); 23 Mar 2020 04:35:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 9237 invoked from network); 23 Mar 2020 04:35:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mforney-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=h9zpqp0ahuvlBdZaJJpFwKscrRF9pxsVj0iqTqscBIs=; b=Y5TsH3UTJCG8F5A/R0iXynbAv64ZB/Q56UajNqxo0gdkBJ48Z6K5SmgWcsnvAnX/3e uf+f6z2a/ruw+Ij0fAyhKbp69dCILmm/WZFAFe2GVn+cHa5k3OnVV8cX8bsCv6Fz9hvq 26NvhxZCyZ4XFiDInAzNVZ7ROuQHObUGiIPPfxKPcMw7ZBghhcq8K0O2ZSjo2lruIElW 74We9uCPz4uWWW4mIA/PK1Vh+XcXAUyqLHqATq4q29cMA/vf8CVYCuoviSsMpPMuNC2q DZeoqtdR08KaWhGCHdnYtHo3Pt3EzsB6Gn5zA8wTF/2ZnyMgmX2UBth9nw9z9kFwXMRb oJ2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h9zpqp0ahuvlBdZaJJpFwKscrRF9pxsVj0iqTqscBIs=; b=ARpBi1Yy72jJwhJ4YxiXM3zajVP0iXwbsZPs5DFOo4e2GOPIycSmD5Ip/7+UCQV3mk CH/C6gBgGG2oIiyK9QSuOmmvIrs5DBd9QKOivn1oSWqrNwT97/PB3Q239/1AEKHNUYjY E2gVCQy1UMFONwROaEP8jQnLZKa/Vq/owrkWNU/2jB9vkw6SzUmEtR5vS1rFNEDjyppd Z7Xt4eF7uhuxCcTDb38ceGkcx8dckDhzPoVr1uENx17W3RhfWO7FjVa/fxYZGu/EwBD3 w/vMUIDzyWyRobMERKsXuI1fzX3uM/VZ5ol116lzU9a0xKZEABnvQehwcUCWKs5OjLIC ijOA== X-Gm-Message-State: ANhLgQ27WA94gdixzlePOwI9Uf4CabZ1n4h2fa9NcahVsSpAiELeMHBV XE7+VeHWVVwqn0nqYM0e+Ok7JlHKLBCs+Q== X-Google-Smtp-Source: ADFU+vsFsUZhBr/ssoNhhh2LwMQXtGQqEhvQLyZbWr6UmhTZ+pVHcMIUJM8z1qdnkkZgts5iMRKpbQ== X-Received: by 2002:a63:7f09:: with SMTP id a9mr19947643pgd.375.1584938102824; Sun, 22 Mar 2020 21:35:02 -0700 (PDT) From: Michael Forney To: musl@lists.openwall.com Date: Sun, 22 Mar 2020 21:34:56 -0700 Message-Id: <20200323043456.13327-1-mforney@mforney.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20181107064957.1137-1-mforney@mforney.org> References: <20181107064957.1137-1-mforney@mforney.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [musl-cross-make] [PATCH v2] litecross: Fix system header dir when building native toolchains By default, gcc will search in /usr/include relative to the sysroot, but musl is configured with an empty prefix, so headers get installed to /include. This causes gcc to fail to find the libc headers for native toolchains unless a usr -> . symlink is created manually. This is not an issue for cross toolchains because in that case, the configured sysroot is /$(TARGET) which happens to match gcc_tooldir[0], which is one of gcc's default search directories[1]. The system header directory can be configured with --with-native-system-header-dir. However, this is not quite sufficient because the stmp-fixinc target in gcc/Makefile tests for the existence of that directory relative to the configured sysroot (/)[2]. Most systems do not have /include, so this fails. Since musl's fixinc.sh is a no-op[3], we can work around this by clearing STMP_FIXINC, skipping fixincludes entirely. This removes the need for creating the usr -> . symlink in the build sysroot, and having to manually create this symlink for native toolchains (as in [4]). [0] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/configure.ac;h=b066cc609e1c2615e66307d5439f765a4f3b286b;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l6319 [1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/linux.h;h=2ea4ff92c1df9e6d6297996004360ae7eeda2075;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l180 [2] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/Makefile.in;h=20bee0494b1bad4e3ec34e2eae291cf6eadc3aa1;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l3078 [3] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=fixincludes/mkfixinc.sh;h=0f9648608e94f97ab13da223d8192cb04c255772;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l22 [4] https://git.zv.io/toolchains/musl-cross-make/-/blob/5774ca4dc5bdb813e33052023d982ee073a5c6b8/scripts/buildall#L30 --- Hi, Resending this patch because this is still an issue, and I realized that the usr -> . symlink could also be removed in the build sysroot. Anyone who has built a native toolchain with musl-cross-make has probably run into this and worked around it by creating a usr -> . symlink in the install directory manually. To demonstrate that this only currently works by accident with cross-compilers, I'll start with current musl-cross-make master, and override the sysroot to something else: $ make TARGET=aarch64-linux-musl SYSROOT=/something-else install $ echo '#include ' | ./output/bin/aarch64-linux-musl-gcc -v -x c - ignoring nonexistent directory "/tmp/musl-cross-make/output/bin/../something-else/usr/local/include" ignoring duplicate directory "/tmp/musl-cross-make/output/bin/../lib/gcc/../../lib/gcc/aarch64-linux-musl/9.2.0/../../../../aarch64-linux-musl/include" ignoring nonexistent directory "/tmp/musl-cross-make/output/bin/../something-else/usr/include" ignoring duplicate directory "/tmp/musl-cross-make/output/bin/../lib/gcc/../../lib/gcc/aarch64-linux-musl/9.2.0/include" #include "..." search starts here: #include <...> search starts here: /tmp/musl-cross-make/output/bin/../lib/gcc/aarch64-linux-musl/9.2.0/../../../../aarch64-linux-musl/include /tmp/musl-cross-make/output/bin/../lib/gcc/aarch64-linux-musl/9.2.0/include End of search list. GNU C17 (GCC) version 9.2.0 (aarch64-linux-musl) compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 32e14193b549d09fa3807c50f194d659 :1:10: fatal error: stdlib.h: No such file or directory compilation terminated. $ As you can see, gcc *is* searching for headers in the /something-else sysroot, but under the incorrect system header directory. It still searches for headers in /aarch64-linux-musl/include since that is the gcc tool directory. To demonstrate the problem with native toolchains, let's build a native toolchain and try to use it: $ make TARGET=x86_64-linux-musl NATIVE=1 install $ echo '#include ' | ./output-x86_64-linux-musl/bin/gcc -v -x c - ignoring nonexistent directory "/tmp/musl-cross-make/output-x86_64-linux-musl/bin/../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/include" ignoring nonexistent directory "/tmp/musl-cross-make/output-x86_64-linux-musl/bin/../usr/local/include" ignoring nonexistent directory "/tmp/musl-cross-make/output-x86_64-linux-musl/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/9.2.0/../../../../x86_64-linux-musl/include" ignoring nonexistent directory "/tmp/musl-cross-make/output-x86_64-linux-musl/bin/../usr/include" ignoring duplicate directory "/tmp/musl-cross-make/output-x86_64-linux-musl/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/9.2.0/include" #include "..." search starts here: #include <...> search starts here: /tmp/musl-cross-make/output-x86_64-linux-musl/bin/../lib/gcc/x86_64-linux-musl/9.2.0/include End of search list. GNU C17 (GCC) version 9.2.0 (x86_64-linux-musl) compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 60320f85342923d8a86b40331aa7a54b :1:10: fatal error: stdlib.h: No such file or directory compilation terminated. $ With the proposed patch, both of these cases are fixed. Hopefully this makes the problem clear. litecross/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/litecross/Makefile b/litecross/Makefile index 8ec0ed2..11ef946 100644 --- a/litecross/Makefile +++ b/litecross/Makefile @@ -55,6 +55,7 @@ MAKE += MULTILIB_OSDIRNAMES= MAKE += INFO_DEPS= infodir= MAKE += ac_cv_prog_lex_root=lex.yy MAKE += MAKEINFO=false +MAKE += STMP_FIXINC= FULL_BINUTILS_CONFIG = \ --disable-separate-code \ @@ -74,6 +75,7 @@ FULL_GCC_CONFIG = --enable-languages=c,c++ \ --target=$(TARGET) --prefix= \ --libdir=/lib --disable-multilib \ --with-sysroot=$(SYSROOT) \ + --with-native-system-header-dir=/include \ --enable-tls \ --disable-libmudflap --disable-libsanitizer \ --disable-gnu-indirect-function \ @@ -112,7 +114,7 @@ FULL_MUSL_CONFIG += CC="$(XGCC)" LIBCC="../obj_gcc/$(TARGET)/libgcc/libgcc.a" MUSL_VARS = AR=../obj_binutils/binutils/ar RANLIB=../obj_binutils/binutils/ranlib obj_musl/.lc_configured: | obj_gcc/gcc/.lc_built obj_musl/.lc_built: | obj_gcc/$(TARGET)/libgcc/libgcc.a -obj_gcc/gcc/.lc_built: | obj_sysroot/usr obj_sysroot/lib32 obj_sysroot/lib64 obj_sysroot/include +obj_gcc/gcc/.lc_built: | obj_sysroot/lib32 obj_sysroot/lib64 obj_sysroot/include obj_gcc/.lc_built: | obj_sysroot/.lc_libs obj_sysroot/.lc_headers obj_gcc/.lc_configured: obj_binutils/.lc_built else @@ -197,9 +199,6 @@ obj_%: obj_sysroot/include: mkdir -p $@ -obj_sysroot/usr: | obj_sysroot - ln -sf . $@ - obj_sysroot/lib32: | obj_sysroot ln -sf lib $@ -- 2.25.2