Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
{
const targetFileName = getTargetFileName(settings, platform);

const p = platform.platform;
final switch (settings.targetType) {
case TargetType.autodetect: assert(false, "Invalid target type: autodetect");
case TargetType.none: assert(false, "Invalid target type: none");
Expand All @@ -259,6 +260,14 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
break;
case TargetType.object:
settings.addDFlags("-c");

// When using wasm-ld on output objects, we need to explicitly
// not strip dead symbols, otherwise we'll get a linker error.
// as wasm-ld only works on relocatable objects.
if (p.canFind("wasm")) {
settings.addDFlags("--disable-linker-strip-dead");
settings.addLFlags("-r");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't quite seem like the right place to add the dflags per platform, since there is also no other such check here, but I haven't been able to check the code in other compiler wrappers here yet, perhaps consider just disregarding this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requirement only applies to the object target type. Couldn't find anywhere better to put it given that .o files have to be reloctable and can't be section gc'd. If these flags aren't there for the object type then you will be unable to use wasm-ld and/or emscripten to link your module with eg. Emscripten ports or other external libraries.

}
break;
}

Expand Down Expand Up @@ -287,10 +296,17 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
import std.string;
auto tpath = NativePath(settings.targetPath) ~ getTargetFileName(settings, platform);
auto args = ["-of"~tpath.toNativeString()];
const p = platform.platform;

args ~= objects;
args ~= settings.sourceFiles;
if (platform.platform.canFind("linux"))
args ~= "-L--no-as-needed"; // avoids linker errors due to libraries being specified in the wrong order

// Avoids linker errors due to libraries being specified in the wrong order.
// However, the wasm-ld linker does not have --no-as-needed and emscripten is
// implicitly treated as a "linux" platform.
if (p.canFind("linux") && !p.canFind("emscripten"))
args ~= "-L--no-as-needed";

args ~= lflagsToDFlags(settings.lflags);
args ~= settings.dflags.filter!(f => isLinkerDFlag(f)).array;

Expand Down Expand Up @@ -321,8 +337,8 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
arg = arg[1 .. $]; // normalize to 1 leading hyphen

switch (arg) {
case "-g", "-gc", "-m32", "-m64", "-shared", "-lib",
"-betterC", "-disable-linker-strip-dead", "-static":
case "-g", "-gc", "-m32", "-m64", "-mwasm64", "-shared", "-lib",
"-betterC", "-disable-linker-strip-dead", "-static", "-r":
return true;
default:
return arg.startsWith("-L")
Expand Down
5 changes: 5 additions & 0 deletions source/dub/platform.d
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum string platformCheck = q{
version(MinGW) ret ~= "mingw";
version(PlayStation4) ret ~= "playstation4";
version(WebAssembly) ret ~= "wasm";
version(Emscripten) ret ~= "emscripten";
return ret;
};

Expand Down Expand Up @@ -102,6 +103,10 @@ enum string archCheck = q{
version(LoongArch64) ret ~= "loongarch64";
version(LoongArch_SoftFloat) ret ~= "loongarch_softfloat";
version(LoongArch_HardFloat) ret ~= "loongarch_hardfloat";
version(WebAssembly) {
version(D_LP64) ret ~= "wasm64";
else ret ~= "wasm32";
}
return ret;
};

Expand Down