Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 7678: Added -cflag=ccflags switch. #794

Closed
wants to merge 1 commit into from

5 participants

@chadjoan

This allows arguments to be passed to the C compiler being used to drive linking.

I've also opened issue 7678 for this. (http://d.puremagic.com/issues/show_bug.cgi?id=7678)

I was prompted to make this patch because of issue 5278 remaining unresolved. (http://d.puremagic.com/issues/show_bug.cgi?id=5278)

@WalterBright

Adding more flags makes me nervous. I keep thinking there must be a better solution.

@alexrp

Well, -L is already entirely linker-dependent. Does it really matter if we add a switch to pass flags to the C compiler which are compiler-specific? I totally understand your concern, but we already have to special-case anyway, and I very much doubt we can create sensible wrapper options around all supported C compilers on all platforms.

@MartinNowak
Collaborator

The only reason we're using the compiler driver for linking instead of a linker is to select appropriate libc link parameters. Now there are only few C compiler options that affect the selected libc like -static or -fpie. All of those should be mappable to equivalent D compiler options because the linkage model is the same.
So I think it makes more sense to implement a -fPIE switch or interpreting -fPIC for executables as meaning -fPIE.
The implementation would consist of -fPIC + pass -fPIE to gcc + ?.

If that isn't feasible for now I would opt for detecting a default PIE compiler driver or simply hardcode fno-pie
here.

@andralex
Owner

I'm not an expert in this so I'll assign to @WalterBright.

@WalterBright WalterBright was assigned
@MartinNowak
Collaborator

I'll close this for now. As stated above we can achieve the particular fPIE fix by different means.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 10, 2012
  1. @chadjoan

    Added -cflag=ccflags switch. This allows arguments to be passed to th…

    chadjoan authored
    …e C compiler being used to drive linking.
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 3 deletions.
  1. +6 −1 src/link.c
  2. +12 −2 src/mars.c
  3. +10 −0 src/mars.h
View
7 src/link.c
@@ -223,7 +223,7 @@ int runLINK()
delete lnkfilename;
}
return status;
-#elif linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4
+#elif CC_DRIVES_LINKING
pid_t childpid;
int i;
int status;
@@ -342,6 +342,11 @@ int runLINK()
argv.push((char *)"-Xlinker");
argv.push(p);
}
+
+ for (size_t i = 0; i < global.params.ccswitches->dim; i++)
+ { char *p = global.params.ccswitches->tdata()[i];
+ argv.push(p);
+ }
/* Add each library, prefixing it with "-l".
* The order of libraries passed is:
View
14 src/mars.c
@@ -314,8 +314,11 @@ Usage:\n\
files.d D source files\n\
@cmdfile read arguments from cmdfile\n\
-c do not link\n\
- -cov do code coverage analysis\n\
- -D generate documentation\n\
+ -cov do code coverage analysis\n"
+#if CC_DRIVES_LINKING
+" -cflag=ccflag pass ccflag to the C compiler being used to drive linking\n"
+#endif
+" -D generate documentation\n\
-Dddocdir write documentation file to docdir directory\n\
-Dffilename write documentation file to filename\n\
-d allow deprecated features\n\
@@ -438,6 +441,7 @@ int tryMain(int argc, char *argv[])
global.params.quiet = 1;
global.params.linkswitches = new Strings();
+ global.params.ccswitches = new Strings();
global.params.libfiles = new Strings();
global.params.objfiles = new Strings();
global.params.ddocfiles = new Strings();
@@ -777,6 +781,12 @@ int tryMain(int argc, char *argv[])
{
global.params.linkswitches->push(p + 2);
}
+#if CC_DRIVES_LINKING
+ else if (memcmp(p + 1, "cflag=", 6) == 0)
+ {
+ global.params.ccswitches->push(p + 1 + 6);
+ }
+#endif
else if (memcmp(p + 1, "defaultlib=", 11) == 0)
{
global.params.defaultlibname = p + 1 + 11;
View
10 src/mars.h
@@ -122,6 +122,15 @@ void unittests();
#endif
#endif
+// On these systems the C Compiler is used to drive linking.
+// The compiler is chosen using the ${CC} environment variable, but if that is
+// not provided it will default to gcc.
+#if linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4
+#ifndef CC_DRIVES_LINKING
+#define CC_DRIVES_LINKING 1
+#endif
+#endif
+
struct OutBuffer;
@@ -230,6 +239,7 @@ struct Param
// Linker stuff
Strings *objfiles;
Strings *linkswitches;
+ Strings *ccswitches;
Strings *libfiles;
char *deffile;
char *resfile;
Something went wrong with that request. Please try again.