diff --git a/tests/plugins/plugin_phobos_usage.d b/tests/plugins/plugin_phobos_usage.d new file mode 100644 index 0000000000..c426a9fe2e --- /dev/null +++ b/tests/plugins/plugin_phobos_usage.d @@ -0,0 +1,30 @@ +// Test usage of Phobos (used to result in dlopen missing symbols, because LDC itself did not have that Phobos symbol) + +// REQUIRES: Plugins + +// RUN: split-file %s %t --leading-lines +// RUN: %buildplugin %t/plugin.d -of=%t/plugin%so --buildDir=%t/build +// RUN: %ldc -wi -c -o- --plugin=%t/plugin%so %t/testcase.d 2>&1 | FileCheck %t/testcase.d + +//--- plugin.d +import dmd.dmodule : Module; +import dmd.errors; +import dmd.location; + +import std.experimental.allocator.mallocator; + +extern(C) void runSemanticAnalysis(Module m) { + auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4); + scope(exit) Mallocator.instance.deallocate(buffer); + + if (m.md) { + warning(m.md.loc, "It works!"); + } +} + +//--- testcase.d +// CHECK: testcase.d([[@LINE+1]]): Warning: It works! +module testcase; +int testfunction(int i) { + return i * 2; +} diff --git a/tools/ldc-build-plugin.d.in b/tools/ldc-build-plugin.d.in index 84fd25ff35..d580f80c92 100644 --- a/tools/ldc-build-plugin.d.in +++ b/tools/ldc-build-plugin.d.in @@ -16,6 +16,9 @@ else version (TVOS) else version (WatchOS) version = Darwin; +version (linux) version = LDCLinkedWithSharedRuntime; +version (FreeBSD) version = LDCLinkedWithSharedRuntime; + struct Config { string ldcExecutable; string buildDir; @@ -140,7 +143,6 @@ void build() { "--d-version=IN_LLVM", "-J" ~ buildPath(config.ldcSourceDir, "dmd", "res"), "--shared", - "--defaultlib=", "--od=" ~ config.buildDir ]; @@ -148,6 +150,12 @@ void build() { args ~= "-L-Wl,-undefined,dynamic_lookup"; } + // When LDC is linked with shared runtime, don't link it again into the plugin to avoid two runtimes being loaded. + // Only link with phobos. + version (LDCLinkedWithSharedRuntime) { + args ~= "--defaultlib=phobos2-ldc"; + } + args ~= config.ldcArgs; exec(args);