Skip to content

Commit cd575ab

Browse files
committed
Fixed: Identify for ld64 linker for not emitting start group
1 parent 27f69f4 commit cd575ab

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

source/redub/buildapi.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import redub.package_searching.api;
88

99

1010
///vX.X.X
11-
enum RedubVersionOnly = "v1.21.6";
11+
enum RedubVersionOnly = "v1.21.7";
1212
///Redub vX.X.X
1313
enum RedubVersionShort = "Redub "~RedubVersionOnly;
1414
///Redub vX.X.X - Description

source/redub/command_generators/linkers.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ string[] parseLinkConfiguration(const ThreadBuildData data, CompilingSession s,
1010
import redub.misc.path;
1111
import redub.building.cache;
1212
string[] commands;
13-
bool isUsingGNULinker = s.compiler.usesGnuLinker;
13+
AcceptedLinker linker = s.compiler.linker;
14+
bool emitStartGroup = s.isa != ISA.webAssembly && linker != AcceptedLinker.ld64;
1415

1516

1617
const BuildConfiguration b = data.cfg;
@@ -41,14 +42,14 @@ string[] parseLinkConfiguration(const ThreadBuildData data, CompilingSession s,
4142
if (targetType.isLinkedSeparately)
4243
{
4344
//Only linux supports start/end group and no-as-needed. OSX does not
44-
if(s.isa != ISA.webAssembly)
45+
if(emitStartGroup)
4546
{
4647
commands~= "-L--no-as-needed";
4748
commands~= "-L--start-group";
4849
}
4950
///Use library full path for the base file
5051
commands = mapAppendReverse(commands, data.extra.librariesFullPath, (string l) => "-L"~getOutputName(TargetType.staticLibrary, l, s.os));
51-
if(s.isa != ISA.webAssembly)
52+
if(emitStartGroup)
5253
commands~= "-L--end-group";
5354
commands = mapAppendPrefix(commands, linkFlags, "-L", false);
5455
commands = mapAppendPrefix(commands, libraryPaths, "-L-L", true);

source/redub/compiler_identification.d

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ enum AcceptedCompiler
1212
gxx
1313
}
1414

15+
enum AcceptedLinker
16+
{
17+
unknown,
18+
gnuld,
19+
ld64,
20+
///I know there a plenty more, but still..
21+
}
22+
1523
enum UsesGnuLinker
1624
{
1725
unknown,
@@ -32,6 +40,20 @@ AcceptedCompiler acceptedCompilerfromString(string str)
3240
throw new Exception("Invalid AcceptedCompiler string received: "~str);
3341
}
3442
}
43+
AcceptedLinker acceptedLinkerfromString(string str)
44+
{
45+
switch(str)
46+
{
47+
static foreach(mem; __traits(allMembers, AcceptedLinker))
48+
{
49+
case mem:
50+
return __traits(getMember, AcceptedLinker, mem);
51+
}
52+
default:
53+
return AcceptedLinker.unknown;
54+
}
55+
}
56+
3557

3658

3759
/**
@@ -60,7 +82,7 @@ struct Compiler
6082

6183
///Currently unused. Was used before for checking whether --start-group should be emitted or not. Since it is emitted
6284
///by default, only on webAssembly which is not, it lost its usage for now.
63-
bool usesGnuLinker = false;
85+
AcceptedLinker linker = AcceptedLinker.unknown;
6486

6587

6688
string getCompilerString() const
@@ -217,7 +239,7 @@ Compiler getCompiler(string compilerOrPath = "dmd", string compilerAssumption =
217239
if(ret == Compiler.init)
218240
ret = inferCompiler(compilerOrPath, compilerAssumption, compilersInfo, isDefault, isGlobal);
219241

220-
ret.usesGnuLinker = compilersInfo["defaultsToGnuLd"].boolean;
242+
ret.linker = acceptedLinkerfromString(compilersInfo["defaultLinker"].str);
221243

222244
//Checks for ldc.conf switches to see if it is using gnu linker by default
223245
///TODO: Might be reactivated if that issue shows again.
@@ -354,7 +376,7 @@ private Compiler getCompilerFromCache(JSONValue allCompilersInfo, string compile
354376
SemVer(arr[VERSION_].str),
355377
SemVer(arr[FRONTEND_VERSION].str),
356378
arr[VERSION_STRING].str,
357-
key, null, false, allCompilersInfo["defaultsToGnuLd"].boolean
379+
key, null, false, acceptedLinkerfromString(allCompilersInfo["defaultLinker"].str)
358380
);
359381
}
360382
}
@@ -396,10 +418,10 @@ private void saveCompilerInfo(JSONValue allCompilersInfo, ref Compiler compiler,
396418
if(!("version" in allCompilersInfo))
397419
allCompilersInfo["version"] = JSONValue(RedubVersionOnly);
398420

399-
if(!("defaultsToGnuLd" in allCompilersInfo))
400-
allCompilersInfo["defaultsToGnuLd"] = JSONValue(isDefaultLinkerGnuLd());
421+
if(!("defaultLinker" in allCompilersInfo))
422+
allCompilersInfo["defaultLinker"] = JSONValue(getDefaultLinker().to!string);
401423

402-
compiler.usesGnuLinker = allCompilersInfo["defaultsToGnuLd"].boolean;
424+
compiler.linker = acceptedLinkerfromString(allCompilersInfo["defaultLinker"].str);
403425

404426
if(!("compilers" in allCompilersInfo))
405427
allCompilersInfo["compilers"] = JSONValue.emptyObject;
@@ -453,17 +475,23 @@ private Compiler assumeCompiler(string compilerOrPath, string compilerAssumption
453475
}
454476

455477

456-
bool isDefaultLinkerGnuLd()
478+
AcceptedLinker getDefaultLinker()
457479
{
458-
version(linux)
480+
version(Posix)
459481
{
460482
import std.process;
461483
import std.string;
462484
auto res = executeShell("ld -v");
463-
return res.status == 0 && res.output.startsWith("GNU ld");
485+
if(res.status == 0)
486+
return AcceptedLinker.unknown;
487+
488+
if(res.output.startsWith("GNU ld"))
489+
return AcceptedLinker.gnuld;
490+
else if(res.output.startsWith("@(#)PROGRAM:ld"))
491+
return AcceptedLinker.ld64;
464492
}
465-
else
466-
return false;
493+
494+
return AcceptedLinker.unknown;
467495
}
468496

469497
private bool tryInferLdc(string compilerOrPath, string vString, out Compiler comp)

0 commit comments

Comments
 (0)