Permalink
Browse files

Merge pull request #2951 from kinke/externalWasmLd

Support external wasm-ld linker for WebAssembly targets
  • Loading branch information...
kinke committed Jan 8, 2019
2 parents 26b57fe + 794907b commit b8d5ac95cc2b3557ba396295b9a32adbb21ea464
Showing with 38 additions and 9 deletions.
  1. +4 −1 .circleci/config.yml
  2. +18 −6 driver/linker-gcc.cpp
  3. +1 −1 shippable.yml
  4. +12 −0 tests/baremetal/lit.local.cfg
  5. +1 −0 tests/baremetal/wasm.d
  6. +1 −0 tests/baremetal/wasm2.d
  7. +1 −1 tests/lit.site.cfg.in
@@ -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,4 +1,16 @@
import subprocess

# Define `%baremetal_args` as LDC args making sure
# * no ldc2.conf file is used (=> no implicit command-line args), and
# * the empty object.d in ./inputs is imported (=> no TypeInfo, ModuleInfo, Object...).
config.substitutions.append( ('%baremetal_args', '-conf= -I' + config.test_source_root + '/baremetal/inputs') )

# Add "link_WebAssembly" feature if we can link wasm (-link-internally or wasm-ld in PATH).
if config.ldc_with_lld:
config.available_features.add('link_WebAssembly')
else:
try:
if (subprocess.call(["wasm-ld", "--version"]) == 0):
config.available_features.add('link_WebAssembly')
except OSError:
pass
@@ -1,6 +1,7 @@
// Compile and link directly to WebAssembly.

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

extern(C): // no mangling, no arguments order reversal
@@ -1,6 +1,7 @@
// A more complex wasm example using Phobos templates (=> -betterC to keep it simple).

// REQUIRES: target_WebAssembly
// REQUIRES: link_WebAssembly
// RUN: %ldc -mtriple=wasm32-unknown-unknown-wasm -betterC %s

extern(C):
@@ -25,7 +25,7 @@ config.dynamic_compile = @LDC_DYNAMIC_COMPILE@
config.plugins_supported = "@LDC_ENABLE_PLUGINS@" == "ON"
config.gnu_make_bin = "@GNU_MAKE_BIN@"
config.ldc_host_arch = "@LDC_HOST_ARCH@"
config.ldc_with_lld = "@LDC_WITH_LLD@"
config.ldc_with_lld = "@LDC_WITH_LLD@" == "ON"

config.name = 'LDC'

0 comments on commit b8d5ac9

Please sign in to comment.