Permalink
Browse files

Support external wasm-ld linker for WebAssembly targets

Overridable with `-linker`.
  • Loading branch information...
kinke committed Dec 22, 2018
1 parent 4487722 commit c7b17368c361b54cd8c05e3dea03312f247d791c
Showing with 24 additions and 9 deletions.
  1. +4 −1 .circleci/config.yml
  2. +18 −6 driver/linker-gcc.cpp
  3. +1 −1 shippable.yml
  4. +1 −1 tests/baremetal/wasm.d
@@ -129,7 +129,10 @@ commonSteps: &commonSteps
- run:
name: Run LIT testsuite
when: always
command: cd ../ninja-ldc && ctest -V -R lit-tests
command: |
cd ../ninja-ldc
# Temporarily add LLVM bin dir to PATH, so that e.g. wasm-ld is found.
PATH=$PWD/../llvm-$LLVM_VERSION/bin:$PATH ctest -V -R lit-tests
- run:
name: Run DMD testsuite
when: always
@@ -703,22 +703,34 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
}
#endif

// find gcc for linking
const std::string tool = getGcc();
// build command-line for gcc-compatible linker driver
// exception: invoke (ld-compatible) linker directly for WebAssembly targets
std::string tool;
std::unique_ptr<ArgsBuilder> argsBuilder;
#if LDC_LLVM_VER >= 500
if (global.params.targetTriple->isOSBinFormatWasm()) {
tool = getProgram("wasm-ld", &opts::linker);
argsBuilder = llvm::make_unique<LdArgsBuilder>();
} else {
#endif
tool = getGcc();
argsBuilder = llvm::make_unique<ArgsBuilder>();
#if LDC_LLVM_VER >= 500
}
#endif

// build arguments
ArgsBuilder argsBuilder;
argsBuilder.build(outputPath, defaultLibNames);
argsBuilder->build(outputPath, defaultLibNames);

Logger::println("Linking with: ");
Stream logstr = Logger::cout();
for (const auto &arg : argsBuilder.args) {
for (const auto &arg : argsBuilder->args) {
if (!arg.empty()) {
logstr << "'" << arg << "' ";
}
}
logstr << "\n"; // FIXME where's flush ?

// try to call linker
return executeToolAndWait(tool, argsBuilder.args, global.params.verbose);
return executeToolAndWait(tool, argsBuilder->args, global.params.verbose);
}
@@ -89,7 +89,7 @@ build:
# Build and run LDC D unittests
- ctest --output-on-failure -R ldc2-unittest
# Run LIT testsuite, ignore the errors
- ctest -V -R lit-tests || true
- PATH=$PWD/../llvm/bin:$PATH ctest -V -R lit-tests || true
# Run DMD testsuite (non-debug only for now), ignore the errors
- DMD_TESTSUITE_MAKE_ARGS='-j16 -k' ctest -V -R dmd-testsuite -E "-debug$" || true
# Run druntime/Phobos unittests (non-debug only for now, excl. hanging core.thread), ignore the errors
@@ -1,7 +1,7 @@
// Compile and link directly to WebAssembly.

// REQUIRES: target_WebAssembly
// RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -link-internally %s %baremetal_args
// RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm %s %baremetal_args

extern(C): // no mangling, no arguments order reversal

0 comments on commit c7b1736

Please sign in to comment.