From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11395 Path: news.gmane.org!.POSTED!not-for-mail From: Aidan Hobson Sayers Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: [PATCH 1/1] Use compiler includes for musl-clang, like musl-gcc Date: Sun, 4 Jun 2017 03:40:57 +0100 Message-ID: References: <1467825725-11116-1-git-send-email-aidanhs@cantab.net> <20160706174403.GB15995@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a113d6bd621899605511952fc" X-Trace: blaine.gmane.org 1496544092 18725 195.159.176.226 (4 Jun 2017 02:41:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 4 Jun 2017 02:41:32 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11408-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jun 04 04:41:28 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dHLTr-0004YF-UH for gllmg-musl@m.gmane.org; Sun, 04 Jun 2017 04:41:28 +0200 Original-Received: (qmail 15896 invoked by uid 550); 4 Jun 2017 02:41:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 15864 invoked from network); 4 Jun 2017 02:41:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=fscJJ7OQWf9S7eEonVfKQZFWl3M3LJChkxDqvSciVNI=; b=pqbtfvnGz6BGG+U9nYOHywprHoUam2fC/wBYsmCbhlgzoDu9j56IotBa/wXX2OiZQs qPYSEAZKWp8c0QK4Iv0M4Eoi+V6FtEcL3BSM5A0ohB43zHX3IuZJ7PbMoTGMWAXIYLOs sJKZRl0aBfiv7gmMoVvw+GhXe9s+OHy2In+AT2nHM6g9S19iIz5Sr7SGKeWJ18FVNrrE 5XWHj1YYQYPNoDrmVhroj7Yydb2cTydT+MAIkaiX/s1z100EitiHuMPULc2AlHW1Tg8z qQdGneFTvuZfT7q8N7QPpo0OlIUs/5Mk+yeyqd07b0RUMff9i4SC59NyGwUwcyfwK7MH fTVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=fscJJ7OQWf9S7eEonVfKQZFWl3M3LJChkxDqvSciVNI=; b=rus4vOMo9MocUZ3qbIOxim5f1ZXyYBEy2RXmOCH3NHrgJ9kvXYf1gzVhT+yHnVJHXi UNWaJCAud+AtO9Pb9JA44b06ARB8vIZ5tpzeMdoq0VR5r18iwmsBSyKy2eJq/zjDZfnO utPSGCaa5U9yThaBrmhA8gFt50xI/lPApiXOyF8KUY2UM17wHdWJCovPoiOw8JpOxvEu rbZyX5Kk487UNbEYtZu8RCAq+HrXcLafj7DOMv4Fe2yQSK1FR/KPMGJT3Rg4cxHwESFe bGSw9Z+dYrxnJrfKo6xcTH9kR7hCNwmxL3Vhty+G+ONAf3HkQrAytvFfTGusFW0seKj4 CfcQ== X-Gm-Message-State: AODbwcA+Hf+kLaD3Aghy0AaTiGLwwfkXqNV4X9A4advdNzbOr2Dx8n/i RkikRohEn6YsBuCSEngDy9zPkvT3LAnh X-Received: by 10.202.82.86 with SMTP id g83mr6025804oib.60.1496544077513; Sat, 03 Jun 2017 19:41:17 -0700 (PDT) Original-Sender: aidanphs@gmail.com In-Reply-To: X-Google-Sender-Auth: 1ZmXRZQRY5kwaBvrgQ2vz32Y-fU Xref: news.gmane.org gmane.linux.lib.musl.general:11395 Archived-At: --001a113d6bd621899605511952fc Content-Type: text/plain; charset="UTF-8" It was pointed out to me that it's not clear why this is the correct fix for the problem, so I'll elaborate a bit. First, it's useful to note the (working and likely well-tested) musl-gcc wrapper specs file [0], with this line of interest: -nostdinc -isystem $incdir -isystem include%s `-nostdinc` throws away all default include directories. The following `-isystem` arguments then add the musl includes directory, and re-add the compiler builtins include directory. Here are the expanded arguments when compiling my example C file with `musl-gcc -v x.c`: -nostdinc -isystem /tmp/tmp.TG88Sa26oT/musl/prefix/include -isystem /usr/lib/gcc/x86_64-linux-gnu/5/include Clang does not have an equivalent of specs file, so it uses a shell script [1]. The arguments corresponding to the gcc ones above are: -nostdinc \ --sysroot "$libc" \ -isystem "$libc_inc" This does *not* re-add the compiler builtins include directory and so some headers are inaccessible (this possibly hasn't come up before because commonly-used builtins like stdbool.h are also present in the musl include directory, leaving effectively just unwind.h and intrinsics as inaccessible). By altering `-nostdinc` to -nostdlibinc`, the compiler builtins are never removed from the include directories. Although I can't find any documentation for the priority builtins have, it's logical that they would come last and that's backed up by the include list produced by `./musl/prefix/bin/musl-clang -Wp,-v -E - search starts here: /tmp/tmp.TG88Sa26oT/musl/prefix/include /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include Without my patch, the `/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include` directory is not present. For completeness, here's the musl-gcc output snippet: #include <...> search starts here: /tmp/tmp.TG88Sa26oT/musl/prefix/include /usr/lib/gcc/x86_64-linux-gnu/5/include [0] https://git.musl-libc.org/cgit/musl/tree/tools/musl-gcc.specs.sh?id=179766aa2ef06df854bc1d9616bf6f00ce49b7f9 [1] https://git.musl-libc.org/cgit/musl/tree/tools/musl-clang.in?id=179766aa2ef06df854bc1d9616bf6f00ce49b7f9 On 29 October 2016 at 12:49, Aidan Hobson Sayers wrote: > On 6 July 2016 at 18:44, Rich Felker wrote: >> >> What happens when you #include after making this change? Do >> you get the compiler-provided one or musl's? You should be able to >> tell by running musl-clang -E foo.c >> > > Wondering where this patch is up to? > Per my (terse) previous response, stddef seems to be picked up from musl, > which I think is the correct behaviour. > --001a113d6bd621899605511952fc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It was pointed out to me that it's not clear why this = is the correct fix for the problem, so I'll elaborate a bit.

First, it's useful to note the (working and likely well-tested= ) musl-gcc wrapper specs file [0], with this line of interest:

-nostdin= c -isystem $incdir -isystem include%s

`-nostdinc` = throws away all default include directories. The following `-isystem` argum= ents then add the musl includes directory, and re-add the compiler builtins= include directory. Here are the expanded arguments when compiling my examp= le C file with `musl-gcc -v x.c`:

-nostdinc -isystem /t= mp/tmp.TG88Sa26oT/musl/prefix/include -isystem /usr/lib/gcc/x86_64-linux-gn= u/5/include

Clang does not have an eq= uivalent of specs file, so it uses a shell script [1]. The arguments corres= ponding to the gcc ones above are:

=C2=A0 =C2=A0 -= nostdinc \
=C2=A0 =C2=A0 --sysroot "$libc" \=
=C2=A0 =C2=A0 -isystem "$libc_inc"

This does *not* re-add the compile= r builtins include directory and so some headers are inaccessible (this pos= sibly hasn't come up before because commonly-used builtins like stdbool= .h are also present in the musl include directory, leaving effectively just= unwind.h and intrinsics as inaccessible).

By alte= ring `-nostdinc` to -nostdlibinc`, the compiler builtins are never removed = from the include directories. Although I can't find any documentation f= or the priority builtins have, it's logical that they would come last a= nd that's backed up by the include list produced by `./musl/prefix/bin/= musl-clang -Wp,-v -E - </dev/null` after applying my patch:
<= br>
#include <...> search starts here:
=C2=A0/tmp/tmp.TG88Sa26oT/musl/prefix/include
<= div>
=C2=A0/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
<= /div>

Without my patch, the `/usr/lib/llvm= -3.8/bin/../lib/clang/3.8.0/include` directory is not present. For complete= ness, here's the musl-gcc output snippet:

#include <...= > search starts here:
=C2=A0/tmp/tmp.TG88Sa26oT/mus= l/prefix/include
=C2=A0/usr/lib/gcc/x86_64-linux-gnu/5= /include

On 29 October 2016 at 12:49, Aidan = Hobson Sayers <aidanhs@cantab.net> wrote:
On 6 July 2016 at 18:44, Rich Felker <dalias@l= ibc.org> wrote:
What happens when you #include <stddef.h>= after making this change? Do
you get the compiler-provided one or musl's? You should be able to
tell by running musl-clang -E foo.c

Wondering where this patch is up to?
Per = my (terse) previous response, stddef seems to be picked up from musl, which= I think is the correct behaviour.

--001a113d6bd621899605511952fc--