Skip to content

Commit

Permalink
Add objc linker option
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Nov 20, 2024
1 parent b2c30f6 commit 3679436
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ static llvm::cl::opt<bool> linkNoCpp(
"link-no-cpp", llvm::cl::ZeroOrMore, llvm::cl::Hidden,
llvm::cl::desc("Disable automatic linking with the C++ standard library."));

static llvm::cl::opt<bool> linkNoObjc(
"link-no-objc", llvm::cl::ZeroOrMore, llvm::cl::Hidden,
llvm::cl::desc("Disable automatic linking with the Objective-C runtime library."));

//////////////////////////////////////////////////////////////////////////////

namespace {
Expand All @@ -72,6 +76,7 @@ class ArgsBuilder {
virtual void addXRayLinkFlags(const llvm::Triple &triple);
virtual bool addCompilerRTArchiveLinkFlags(llvm::StringRef baseName,
const llvm::Triple &triple);
virtual void addObjcStdlibLinkFlags(const llvm::Triple &triple);

virtual void addLinker();
virtual void addUserSwitches();
Expand Down Expand Up @@ -467,6 +472,13 @@ void ArgsBuilder::addCppStdlibLinkFlags(const llvm::Triple &triple) {
}
}

void ArgsBuilder::addObjcStdlibLinkFlags(const llvm::Triple &triple) {
if (linkNoObjc)
return;

args.push_back(("-l"+getObjcLibName()).str());
}

// Adds all required link flags for PGO.
void ArgsBuilder::addProfileRuntimeLinkFlags(const llvm::Triple &triple) {
const auto searchPaths =
Expand Down Expand Up @@ -710,6 +722,7 @@ void ArgsBuilder::addDefaultPlatformLibs() {
addSoname = true;
args.push_back("-lpthread");
args.push_back("-lm");
this->addObjcStdlibLinkFlags(triple);
break;

case llvm::Triple::Solaris:
Expand Down
8 changes: 8 additions & 0 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ llvm::StringRef getMscrtLibName(const bool *useInternalToolchain) {

//////////////////////////////////////////////////////////////////////////////

llvm::StringRef getObjcLibName() {
// TODO: Support scanning for and loading alternate
// objective-c runtimes like the GNUStep runtime?
return "objc";
}

//////////////////////////////////////////////////////////////////////////////

/// Insert an LLVM bitcode file into the module
static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
llvm::LLVMContext &Context) {
Expand Down
5 changes: 5 additions & 0 deletions driver/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ llvm::StringRef getExplicitMscrtLibName();
*/
llvm::StringRef getMscrtLibName(const bool *useInternalToolchain = nullptr);

/**
* Returns the name of the Objective-C runtime library to link with.
*/
llvm::StringRef getObjcLibName();

/**
* Inserts bitcode files passed on the commandline into a module.
*/
Expand Down

0 comments on commit 3679436

Please sign in to comment.