mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Aidan Hobson Sayers <aidanhs@cantab.net>
To: musl@lists.openwall.com
Subject: Re: Re: [PATCH 1/1] Use compiler includes for musl-clang, like musl-gcc
Date: Sun, 4 Jun 2017 03:40:57 +0100	[thread overview]
Message-ID: <CA+jXYnRFMFGW8jLM=Qp0r+Bp6E8M2_YMaUm0xJL2z1Y5j6h4dQ@mail.gmail.com> (raw)
In-Reply-To: <CA+jXYnQ9XGgOOd7yxrWSuHfgSEasjrjrFL11+17dmLdZfRPeQA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2647 bytes --]

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 - </dev/null` after applying my
patch:

#include <...> 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 <aidanhs@cantab.net> wrote:

> On 6 July 2016 at 18:44, Rich Felker <dalias@libc.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.
>

[-- Attachment #2: Type: text/html, Size: 4623 bytes --]

      reply	other threads:[~2017-06-04  2:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 17:22 Aidan Hobson Sayers
2016-07-06 17:44 ` Rich Felker
2016-07-06 17:47   ` Aidan Hobson Sayers
2016-10-29 11:49   ` Aidan Hobson Sayers
2017-06-04  2:40     ` Aidan Hobson Sayers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+jXYnRFMFGW8jLM=Qp0r+Bp6E8M2_YMaUm0xJL2z1Y5j6h4dQ@mail.gmail.com' \
    --to=aidanhs@cantab.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).