Author: maskray Date: Mon Aug 5 23:25:32 2019 New Revision: 367981 URL: http://llvm.org/viewvc/llvm-project?rev=367981&view=rev Log: [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 Added: cfe/trunk/test/Driver/linux-musl-header-search.cpp Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=367981&r1=367980&r2=367981&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Mon Aug 5 23:25:32 2019 @@ -658,11 +658,11 @@ void Linux::AddClangSystemIncludeArgs(co if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include"); - if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { - SmallString<128> P(D.ResourceDir); - llvm::sys::path::append(P, "include"); - addSystemInclude(DriverArgs, CC1Args, P); - } + SmallString<128> ResourceDirInclude(D.ResourceDir); + llvm::sys::path::append(ResourceDirInclude, "include"); + if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && + (!getTriple().isMusl() || DriverArgs.hasArg(options::OPT_nostdlibinc))) + addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; @@ -860,6 +860,9 @@ void Linux::AddClangSystemIncludeArgs(co addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()) + addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude); } static std::string DetectLibcxxIncludePath(llvm::vfs::FileSystem &vfs, Added: cfe/trunk/test/Driver/linux-musl-header-search.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-musl-header-search.cpp?rev=367981&view=auto ============================================================================== --- cfe/trunk/test/Driver/linux-musl-header-search.cpp (added) +++ cfe/trunk/test/Driver/linux-musl-header-search.cpp Mon Aug 5 23:25:32 2019 @@ -0,0 +1,39 @@ +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-linux-musl -stdlib=libc++ \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree --gcc-toolchain= \ +// RUN: | FileCheck --check-prefix=CHECK-X86-64-LIBCXX %s + +// RESOURCE_DIR/include comes after /usr/include on linux-musl. +// This is different from a glibc-based distribution. +// CHECK-X86-64-LIBCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-X86-64-LIBCXX: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-X86-64-LIBCXX: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" +// CHECK-X86-64-LIBCXX: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// CHECK-X86-64-LIBCXX: "-internal-externc-isystem" "[[SYSROOT]]/usr/include" +// CHECK-X86-64-LIBCXX: "-internal-isystem" "[[RESOURCE_DIR]]{{/|\\\\}}include" + +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only -nobuiltininc 2>&1 \ +// RUN: -target x86_64-linux-musl \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree --gcc-toolchain= \ +// RUN: | FileCheck --check-prefix=CHECK-NOBUILTININC %s + +// CHECK-NOBUILTININC: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-NOBUILTININC-NOT: "-internal-isystem" "[[RESOURCE_DIR]]{{/|\\\\}}include" + +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only -nostdlibinc 2>&1 \ +// RUN: -target x86_64-linux-musl \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree --gcc-toolchain= \ +// RUN: | FileCheck --check-prefix=CHECK-NOSTDLIBINC %s + +// CHECK-NOSTDLIBINC: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-NOSTDLIBINC-NOT: "-internal-externc-isystem" +// CHECK-NOSTDLIBINC-NOT: "-internal-isystem" +// CHECK-NOSTDLIBINC: "-internal-isystem" "[[RESOURCE_DIR]]{{/|\\\\}}include" +// CHECK-NOSTDLIBINC-NOT: "-internal-externc-isystem" +// CHECK-NOSTDLIBINC-NOT: "-internal-isystem" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits