Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Closed
wants to merge 1 commit into from

5 participants

cjoan Walter Bright Alex Rønne Petersen Martin Nowak Andrei Alexandrescu
cjoan

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)

Walter Bright
Owner

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

Alex Rønne Petersen

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.

Martin Nowak
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.

Andrei Alexandrescu
Owner

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

Martin Nowak
Collaborator

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

Martin Nowak MartinNowak closed this March 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 10, 2012
cjoan Added -cflag=ccflags switch. This allows arguments to be passed to th…
…e C compiler being used to drive linking.
b4ce4cd
This page is out of date. Refresh to see the latest.
7  src/link.c
@@ -223,7 +223,7 @@ int runLINK()
@@ -342,6 +342,11 @@ int runLINK()
14  src/mars.c
@@ -314,8 +314,11 @@ Usage:\n\
314 314
   files.d        D source files\n\
315 315
   @cmdfile       read arguments from cmdfile\n\
316 316
   -c             do not link\n\
317  
-  -cov           do code coverage analysis\n\
318  
-  -D             generate documentation\n\
  317
+  -cov           do code coverage analysis\n"
  318
+#if CC_DRIVES_LINKING
  319
+"  -cflag=ccflag  pass ccflag to the C compiler being used to drive linking\n"
  320
+#endif
  321
+"  -D             generate documentation\n\
319 322
   -Dddocdir      write documentation file to docdir directory\n\
320 323
   -Dffilename    write documentation file to filename\n\
321 324
   -d             allow deprecated features\n\
@@ -438,6 +441,7 @@ int tryMain(int argc, char *argv[])
438 441
     global.params.quiet = 1;
439 442
 
440 443
     global.params.linkswitches = new Strings();
  444
+    global.params.ccswitches = new Strings();
441 445
     global.params.libfiles = new Strings();
442 446
     global.params.objfiles = new Strings();
443 447
     global.params.ddocfiles = new Strings();
@@ -777,6 +781,12 @@ int tryMain(int argc, char *argv[])
777 781
             {
778 782
                 global.params.linkswitches->push(p + 2);
779 783
             }
  784
+#if CC_DRIVES_LINKING
  785
+            else if (memcmp(p + 1, "cflag=", 6) == 0)
  786
+            {
  787
+                global.params.ccswitches->push(p + 1 + 6);
  788
+            }
  789
+#endif
780 790
             else if (memcmp(p + 1, "defaultlib=", 11) == 0)
781 791
             {
782 792
                 global.params.defaultlibname = p + 1 + 11;
10  src/mars.h
@@ -122,6 +122,15 @@ void unittests();
122 122
 #endif
123 123
 #endif
124 124
 
  125
+// On these systems the C Compiler is used to drive linking.
  126
+// The compiler is chosen using the ${CC} environment variable, but if that is
  127
+//   not provided it will default to gcc.
  128
+#if linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4
  129
+#ifndef CC_DRIVES_LINKING
  130
+#define CC_DRIVES_LINKING 1
  131
+#endif
  132
+#endif
  133
+
125 134
 
126 135
 struct OutBuffer;
127 136
 
@@ -230,6 +239,7 @@ struct Param
230 239
     // Linker stuff
231 240
     Strings *objfiles;
232 241
     Strings *linkswitches;
  242
+    Strings *ccswitches;
233 243
     Strings *libfiles;
234 244
     char *deffile;
235 245
     char *resfile;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.