Skip to content

Commit

Permalink
Draft implementation for -Xcc=
Browse files Browse the repository at this point in the history
- No documentation.
- Reuses -preview=noXlinker test.
  • Loading branch information
CyberShadow committed Sep 26, 2019
1 parent f0bd935 commit 7a04443
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/dmd/globals.d
Expand Up @@ -264,6 +264,7 @@ extern (C++) struct Param
// Linker stuff
Array!(const(char)*) objfiles;
Array!(const(char)*) linkswitches;
Array!bool linkswitchIsForCC;
Array!(const(char)*) libfiles;
Array!(const(char)*) dllfiles;
const(char)[] deffile;
Expand Down
9 changes: 5 additions & 4 deletions src/dmd/link.d
Expand Up @@ -601,11 +601,12 @@ public int runLINK()
*/

// STEP 1
foreach (p; global.params.linkswitches)
foreach (pi, p; global.params.linkswitches)
{
if (p && p[0] && !flagIsLibraryRelated(p))
{
argv.push("-Xlinker");
if (!global.params.linkswitchIsForCC[pi])
argv.push("-Xlinker");
argv.push(p);
}
}
Expand All @@ -618,11 +619,11 @@ public int runLINK()
}

// STEP 3
foreach (p; global.params.linkswitches)
foreach (pi, p; global.params.linkswitches)
{
if (p && p[0] && flagIsLibraryRelated(p))
{
if (!startsWith(p, "-l") && !startsWith(p, "-L"))
if (!startsWith(p, "-l") && !startsWith(p, "-L") && !global.params.linkswitchIsForCC[pi])
{
// Don't need -Xlinker if switch starts with -l or -L.
// Eliding -Xlinker is significant for -L since it allows our paths
Expand Down
6 changes: 6 additions & 0 deletions src/dmd/mars.d
Expand Up @@ -2143,6 +2143,11 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
goto Lerror;
}
}
else if (startsWith(p + 1, "Xcc="))
{
params.linkswitches.push(p + 5);
params.linkswitchIsForCC.push(true);
}
else if (p[1] == 'X') // https://dlang.org/dmd.html#switch-X
{
params.doJsonGeneration = true;
Expand Down Expand Up @@ -2357,6 +2362,7 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
else if (p[1] == 'L') // https://dlang.org/dmd.html#switch-L
{
params.linkswitches.push(p + 2 + (p[2] == '='));
params.linkswitchIsForCC.push(false);
}
else if (startsWith(p + 1, "defaultlib=")) // https://dlang.org/dmd.html#switch-defaultlib
{
Expand Down
6 changes: 3 additions & 3 deletions test/dshell/test6952.d
Expand Up @@ -10,9 +10,9 @@ void main()
}

auto cmd = shellExpand("$DMD"
~ " -m$MODEL -of$OUTPUT_BASE/main$EXE -conf= -fPIC -g -v -preview=noXlinker"
~ " -m$MODEL -of$OUTPUT_BASE/main$EXE -conf= -fPIC -g -v"
~ " -I$EXTRA_FILES/test6952/ -defaultlib="
~ " -L-nostartfiles -L-nostdlib -L-nodefaultlibs $EXTRA_FILES/test6952/main.d");
~ " -Xcc=-nostartfiles -Xcc=-nostdlib -Xcc=-nodefaultlibs $EXTRA_FILES/test6952/main.d");

// Remove DFLAGS environment variable. Everything we need is explicitly stated in
// the command line above.
Expand All @@ -27,7 +27,7 @@ void main()
immutable lines = result.output.split("\n");
auto ccLine = lines.find!(a => a.startsWith("cc"))[0];

// Due to the `-preview=noXlinker` switch, the arguments prefixed with `-L` should
// Due to the `-preview=noXlinker` switch, the arguments prefixed with `-Xcc` should
// not have an additional `-Xlinker` prepended to them
assert(ccLine.find("-Xlinker -nostartfiles") == "");
assert(ccLine.find("-Xlinker -nostdlib") == "");
Expand Down

0 comments on commit 7a04443

Please sign in to comment.