@@ -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+
1523enum 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
469497private bool tryInferLdc (string compilerOrPath, string vString, out Compiler comp)
0 commit comments