Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 103 additions & 3 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
#include "clang/Driver/Tapir.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -558,8 +559,6 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,

Args.AddAllArgs(CmdArgs, options::OPT_L);

getToolChain().AddTapirRuntimeLibArgs(Args, CmdArgs);

AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
// Build the input file for -filelist (list of linker input files) in case we
// need it later
Expand Down Expand Up @@ -612,6 +611,8 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (getToolChain().ShouldLinkCXXStdlib(Args))
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);

getMachOToolChain().AddLinkTapirRuntime(Args, CmdArgs);

bool NoStdOrDefaultLibs =
Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs);
bool ForceLinkBuiltins = Args.hasArg(options::OPT_fapple_link_rtlib);
Expand Down Expand Up @@ -1145,7 +1146,7 @@ void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args,
}

void DarwinClang::AddCilktoolRTLibs(const ArgList &Args,
ArgStringList &CmdArgs) const {
ArgStringList &CmdArgs) const {
if (Arg *A = Args.getLastArg(options::OPT_fcilktool_EQ)) {
StringRef Val = A->getValue();
auto RLO = RuntimeLinkOptions(RLO_AlwaysLink);
Expand Down Expand Up @@ -2639,3 +2640,102 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
void Darwin::printVerboseInfo(raw_ostream &OS) const {
CudaInstallation.print(OS);
}

void DarwinClang::AddLinkTapirRuntimeLib(const ArgList &Args,
ArgStringList &CmdArgs,
StringRef LibName,
RuntimeLinkOptions Opts,
bool IsShared) const {
SmallString<64> DarwinLibName = StringRef("lib");
DarwinLibName += LibName;
DarwinLibName += IsShared ? ".dylib" : ".a";
SmallString<128> Dir(getDriver().ResourceDir);
llvm::sys::path::append(
Dir, "lib", (Opts & RLO_IsEmbedded) ? "macho_embedded" : "darwin");

SmallString<128> P(Dir);
llvm::sys::path::append(P, DarwinLibName);

// For now, allow missing resource libraries to support developers who may
// not have compiler-rt checked out or integrated into their build (unless
// we explicitly force linking with this library).
if ((Opts & RLO_AlwaysLink) || getVFS().exists(P)) {
const char *LibArg = Args.MakeArgString(P);
if (Opts & RLO_FirstLink)
CmdArgs.insert(CmdArgs.begin(), LibArg);
else
CmdArgs.push_back(LibArg);
}

// Adding the rpaths might negatively interact when other rpaths are involved,
// so we should make sure we add the rpaths last, after all user-specified
// rpaths. This is currently true from this place, but we need to be
// careful if this function is ever called before user's rpaths are emitted.
if (Opts & RLO_AddRPath) {
assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library");

// Add @executable_path to rpath to support having the dylib copied with
// the executable.
CmdArgs.push_back("-rpath");
CmdArgs.push_back("@executable_path");

// Add the path to the resource dir to rpath to support using the dylib
// from the default location without copying.
CmdArgs.push_back("-rpath");
CmdArgs.push_back(Args.MakeArgString(Dir));
}
}

void DarwinClang::AddLinkTapirRuntime(const ArgList &Args,
ArgStringList &CmdArgs) const {
TapirTargetID TapirTarget = parseTapirTarget(Args);
if (TapirTarget == TapirTargetID::Last_TapirTargetID)
if (const Arg *A = Args.getLastArg(options::OPT_ftapir_EQ))
getDriver().Diag(diag::err_drv_invalid_value) << A->getAsString(Args)
<< A->getValue();

switch (TapirTarget) {
case TapirTargetID::Cheetah:
CmdArgs.push_back("-lcheetah");
CmdArgs.push_back("-lpthread");
break;
case TapirTargetID::OpenCilk: {
bool StaticOpenCilk = Args.hasArg(options::OPT_static_libopencilk);

auto RLO = RLO_AlwaysLink;
if (!StaticOpenCilk)
RLO = RuntimeLinkOptions(RLO | RLO_AddRPath);

// Link the correct Cilk personality fn
if (getDriver().CCCIsCXX())
AddLinkTapirRuntimeLib(Args, CmdArgs, "opencilk-personality-cpp", RLO,
!StaticOpenCilk);
else
AddLinkTapirRuntimeLib(Args, CmdArgs, "opencilk-personality-c", RLO,
!StaticOpenCilk);

// Link the opencilk runtime. We do this after linking the personality
// function, to ensure that symbols are resolved correctly when using static
// linking.
AddLinkTapirRuntimeLib(Args, CmdArgs, "opencilk", RLO, !StaticOpenCilk);

CmdArgs.push_back("-lpthread");
break;
}
case TapirTargetID::Cilk:
CmdArgs.push_back("-lcilkrts");
break;
case TapirTargetID::CilkR:
CmdArgs.push_back("-lcilkr");
CmdArgs.push_back("-lpthread");
break;
case TapirTargetID::OpenMP:
CmdArgs.push_back("-lomp");
break;
case TapirTargetID::Qthreads:
CmdArgs.push_back("-lqthread");
break;
default:
break;
}
}
14 changes: 13 additions & 1 deletion clang/lib/Driver/ToolChains/Darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const {}

/// Add the linker arguments to link a Tapir runtime library.
virtual void AddLinkTapirRuntime(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const {}

/// Add the linker arguments to link the compiler runtime library.
///
/// FIXME: This API is intended for use with embedded libraries only, and is
Expand Down Expand Up @@ -517,6 +521,9 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
void AddLinkARCArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;

void AddLinkTapirRuntime(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;

unsigned GetDefaultDwarfVersion() const override;
// Until dtrace (via CTF) and LLDB can deal with distributed debug info,
// Darwin defaults to standalone/full debug info.
Expand All @@ -534,7 +541,12 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
bool shared = true) const;

void AddCilktoolRTLibs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
llvm::opt::ArgStringList &CmdArgs) const;

void AddLinkTapirRuntimeLib(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
StringRef LibName, RuntimeLinkOptions Opts,
bool IsShared) const;

bool AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Expand Down
15 changes: 11 additions & 4 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ check_cxx_compiler_flag(--sysroot=. COMPILER_RT_HAS_SYSROOT_FLAG)
check_cxx_compiler_flag("-Werror -mcrc" COMPILER_RT_HAS_MCRC_FLAG)
check_cxx_compiler_flag(-fno-partial-inlining COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG)
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
find_library(LIBOPENCILK opencilk
PATHS
${COMPILER_RT_OUTPUT_DIR}/lib/${LLVM_DEFAULT_TARGET_TRIPLE}
${COMPILER_RT_INSTALL_PATH}/lib/${LLVM_DEFAULT_TARGET_TRIPLE})
if (NOT APPLE)
find_library(LIBOPENCILK opencilk
PATHS
${COMPILER_RT_OUTPUT_DIR}/lib/${LLVM_DEFAULT_TARGET_TRIPLE}
${COMPILER_RT_INSTALL_PATH}/lib/${LLVM_DEFAULT_TARGET_TRIPLE})
else()
find_library(LIBOPENCILK opencilk
PATHS
${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}
${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR})
endif()
if (IS_ABSOLUTE ${LIBOPENCILK})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBOPENCILK})
endif()
Expand Down
7 changes: 5 additions & 2 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,17 @@ option(LLVM_APPEND_VC_REV

set(PACKAGE_NAME LLVM)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://bugs.llvm.org/")
# set(PACKAGE_BUGREPORT "https://bugs.llvm.org/")
set(PACKAGE_BUGREPORT "https://github.com/OpenCilk/opencilk-project/issues")

set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
"Default URL where bug reports are to be submitted.")

# Configure CPack.
set(CPACK_PACKAGE_NAME "OpenCilk")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
set(CPACK_PACKAGE_VENDOR "LLVM")
# set(CPACK_PACKAGE_VENDOR "LLVM")
set(CPACK_PACKAGE_VENDOR "OpenCilk")
set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
Expand Down