[Driver] Prioritize SYSROOT/usr/include over RESOURCE_DIR/include on linux-musl
authorFangrui Song <maskray@google.com>
Tue, 6 Aug 2019 06:25:32 +0000 (06:25 +0000)
committerFangrui Song <maskray@google.com>
Tue, 6 Aug 2019 06:25:32 +0000 (06:25 +0000)
commitc37022b22a8a65faf3ff4d2d37c1ff4d16b6e6a8
tree3e0bc0299ac28361205abfa7503d3db074ef54a3
parentec818d7fb3c468c9ab46663873e79772ccc77523
[Driver] Prioritize SYSROOT/usr/include over RESOURCE_DIR/include on linux-musl

On a musl-based Linux distribution, stdalign.h stdarg.h stdbool.h stddef.h stdint.h stdnoreturn.h are expected to be provided by musl (/usr/include), instead of RESOURCE_DIR/include.
Reorder RESOURCE_DIR/include to fix the search order problem.
(Currently musl doesn't provide stdatomic.h. stdatomic.h is still found in RESOURCE_DIR/include.)

gcc on musl has a similar search order:

```
 /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../include/c++/8.3.0
 /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../include/c++/8.3.0/x86_64-alpine-linux-musl
 /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../include/c++/8.3.0/backward
 /usr/local/include
 /usr/include/fortify
 /usr/include
 /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/include
```

This is different from a glibc-based distribution where RESOURCE_DIR/include is placed before SYSROOT/usr/include.

According to the maintainer of musl:

> musl does not support use/mixing of compiler-provided std headers with its headers, and intentionally has no mechanism for communicating with such headers as to which types have already been defined or still need to be defined. If the current include order, with clang's headers before the libc ones, works in some situations, it's only by accident.

Reviewed by: phosek

Differential Revision: https://reviews.llvm.org/D65699

llvm-svn: 367981
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-musl-header-search.cpp [new file with mode: 0644]