Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Driver/ToolChains/FreeBSD.cpp
//===--- FreeBSD.cpp - FreeBSD ToolChain Implementations --------*- C++ -*-===// | //===--- FreeBSD.cpp - FreeBSD ToolChain Implementations --------*- C++ -*-===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "FreeBSD.h" | #include "FreeBSD.h" | ||||
#include "Arch/ARM.h" | #include "Arch/ARM.h" | ||||
#include "Arch/Mips.h" | #include "Arch/Mips.h" | ||||
#include "Arch/Sparc.h" | #include "Arch/Sparc.h" | ||||
#include "CommonArgs.h" | #include "CommonArgs.h" | ||||
#include "clang/Config/config.h" | |||||
#include "clang/Driver/Compilation.h" | #include "clang/Driver/Compilation.h" | ||||
#include "clang/Driver/DriverDiagnostic.h" | #include "clang/Driver/DriverDiagnostic.h" | ||||
#include "clang/Driver/Options.h" | #include "clang/Driver/Options.h" | ||||
#include "clang/Driver/SanitizerArgs.h" | #include "clang/Driver/SanitizerArgs.h" | ||||
#include "llvm/Option/ArgList.h" | #include "llvm/Option/ArgList.h" | ||||
#include "llvm/Support/VirtualFileSystem.h" | #include "llvm/Support/VirtualFileSystem.h" | ||||
using namespace clang::driver; | using namespace clang::driver; | ||||
▲ Show 20 Lines • Show All 381 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
unsigned FreeBSD::GetDefaultDwarfVersion() const { | unsigned FreeBSD::GetDefaultDwarfVersion() const { | ||||
if (getTriple().getOSMajorVersion() < 12) | if (getTriple().getOSMajorVersion() < 12) | ||||
return 2; | return 2; | ||||
return 4; | return 4; | ||||
} | } | ||||
void FreeBSD::AddClangSystemIncludeArgs( | |||||
const llvm::opt::ArgList &DriverArgs, | |||||
llvm::opt::ArgStringList &CC1Args) const { | |||||
const Driver &D = getDriver(); | |||||
if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) | |||||
return; | |||||
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { | |||||
SmallString<128> Dir(D.ResourceDir); | |||||
llvm::sys::path::append(Dir, "include"); | |||||
addSystemInclude(DriverArgs, CC1Args, Dir.str()); | |||||
} | |||||
if (DriverArgs.hasArg(options::OPT_nostdlibinc)) | |||||
return; | |||||
// Check for configure-time C include directories. | |||||
StringRef CIncludeDirs(C_INCLUDE_DIRS); | |||||
if (CIncludeDirs != "") { | |||||
SmallVector<StringRef, 5> dirs; | |||||
CIncludeDirs.split(dirs, ":"); | |||||
for (StringRef dir : dirs) { | |||||
StringRef Prefix = | |||||
llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : ""; | |||||
addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); | |||||
} | |||||
return; | |||||
} | |||||
addExternCSystemInclude(DriverArgs, CC1Args, | |||||
MaskRay: I think Fuchsia way of checking `if (!D.SysRoot.empty()) {` before adding `/usr/include` is… | |||||
It's /usr/include on FreeBSD. I'm confused by the Fuchsia code—does it not add /include if the sysroot is empty? Appears not... $ clang-15 -### -c -target arm64-fuchsia -xc /dev/null clang version 15.0.3 Target: arm64-unknown-fuchsia Thread model: posix InstalledDir: /opt/local/libexec/llvm-15/bin (in-process) "/opt/local/libexec/llvm-15/bin/clang" "-cc1" "-triple" "arm64-unknown-fuchsia" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "null" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-abi" "aapcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-target-linker-version" "556.6" "-fcoverage-compilation-dir=/Users/matt" "-resource-dir" "/opt/local/libexec/llvm-15/lib/clang/15.0.3" "-I/usr/local/include" "-internal-isystem" "/opt/local/libexec/llvm-15/lib/clang/15.0.3/include" "-fdebug-compilation-dir=/Users/matt" "-ferror-limit" "19" "-fsanitize=shadow-call-stack" "-stack-protector" "2" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-target-feature" "+outline-atomics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "null.o" "-x" "c" "/dev/null" $ clang-15 -### -c -target arm64-fuchsia --sysroot /foo -xc /dev/null clang version 15.0.3 Target: arm64-unknown-fuchsia Thread model: posix InstalledDir: /opt/local/libexec/llvm-15/bin (in-process) "/opt/local/libexec/llvm-15/bin/clang" "-cc1" "-triple" "arm64-unknown-fuchsia" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "null" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-abi" "aapcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-target-linker-version" "556.6" "-fcoverage-compilation-dir=/Users/matt" "-resource-dir" "/opt/local/libexec/llvm-15/lib/clang/15.0.3" "-isysroot" "/foo" "-internal-isystem" "/opt/local/libexec/llvm-15/lib/clang/15.0.3/include" "-internal-externc-isystem" "/foo/include" "-fdebug-compilation-dir=/Users/matt" "-ferror-limit" "19" "-fsanitize=shadow-call-stack" "-stack-protector" "2" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-target-feature" "+outline-atomics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "null.o" "-x" "c" "/dev/null" I don't know anything about Fuchsia, but isn't that wrong? Certainly for FreeBSD we'd want to add an unprefixed /usr/include normally... mhjacobson: It's `/usr/include` on FreeBSD.
I'm confused by the Fuchsia code—does it not add `/include` if… | |||||
concat(D.SysRoot, "/usr/include")); | |||||
} | |||||
void FreeBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, | void FreeBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, | ||||
llvm::opt::ArgStringList &CC1Args) const { | llvm::opt::ArgStringList &CC1Args) const { | ||||
addSystemInclude(DriverArgs, CC1Args, | addSystemInclude(DriverArgs, CC1Args, | ||||
concat(getDriver().SysRoot, "/usr/include/c++/v1")); | concat(getDriver().SysRoot, "/usr/include/c++/v1")); | ||||
} | } | ||||
void FreeBSD::addLibStdCxxIncludePaths( | void FreeBSD::addLibStdCxxIncludePaths( | ||||
const llvm::opt::ArgList &DriverArgs, | const llvm::opt::ArgList &DriverArgs, | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
I think Fuchsia way of checking if (!D.SysRoot.empty()) { before adding /usr/include is probably better. Is it /include or /usr/include ?