Skip to content

Commit

Permalink
Adjust UnixLinkerTool flags used for Apple targets. (#5164)
Browse files Browse the repository at this point in the history
Fixes #4959

I don't fully understand the static/shared distinction between these platforms/toolchains, particularly while we still have some calls to functions like `floorf`, but our tests seem to build+run+pass on macOS and Linux with these changes.
  • Loading branch information
ScottTodd authored Mar 22, 2021
1 parent 963beb9 commit 663ab93
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions iree/compiler/Dialect/HAL/Target/LLVM/internal/UnixLinkerTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,37 @@ class UnixLinkerTool : public LinkerTool {

SmallVector<std::string, 8> flags = {
getToolPath(),

// Avoids including any libc/startup files that initialize the CRT as
// we don't use any of that. Our shared libraries must be freestanding.
"-nostdlib", // -nodefaultlibs + -nostartfiles

// Statically link all dependencies so we don't have any runtime deps.
// We cannot have any imports in the module we produce.
// "-static",

// HACK: we insert mallocs and libm calls. This is *not good*.
// We need hermetic binaries that pull in no imports; the MLIR LLVM
// lowering paths introduce a bunch, though, so this is what we are
// stuck with.
"-shared",
"-undefined suppress",

"-o " + artifacts.libraryFile.path,
};

if (targetTriple.isOSDarwin() || targetTriple.isiOS()) {
// Statically link all dependencies so we don't have any runtime deps.
// We cannot have any imports in the module we produce.
flags.push_back("-static");

// Produce a Mach-O dylib file.
flags.push_back("-dylib");
flags.push_back("-flat_namespace");

// HACK: we insert libm calls. This is *not good*.
// Until the MLIR LLVM lowering paths no longer introduce these,
// we are stuck with this.
flags.push_back("-undefined suppress");
} else {
// Avoids including any libc/startup files that initialize the CRT as
// we don't use any of that. Our shared libraries must be freestanding.
flags.push_back("-nostdlib"); // -nodefaultlibs + -nostartfiles

// Statically link all dependencies so we don't have any runtime deps.
// We cannot have any imports in the module we produce.
// flags.push_back("-static");

// HACK: we insert mallocs and libm calls. This is *not good*.
// We need hermetic binaries that pull in no imports; the MLIR LLVM
// lowering paths introduce a bunch, though, so this is what we are
// stuck with.
flags.push_back("-shared");
flags.push_back("-undefined suppress");
}

// Strip debug information (only, no relocations) when not requested.
Expand Down

0 comments on commit 663ab93

Please sign in to comment.