]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: don't pass -rdynamic to external linker if -static is used
authorIan Lance Taylor <iant@golang.org>
Thu, 17 Apr 2014 03:28:53 +0000 (20:28 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 17 Apr 2014 03:28:53 +0000 (20:28 -0700)
Fixes #7800.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/87790051

src/cmd/ld/lib.c

index 78b8cf2badd3949f1181e007f2f90c9325088e9f..29de54e3cf8914035a08e8dd2137945f37aa808e 100644 (file)
@@ -654,6 +654,20 @@ hostlink(void)
                if(*p == '\0')
                        break;
                argv[argc++] = p;
+
+               // clang, unlike GCC, passes -rdynamic to the linker
+               // even when linking with -static, causing a linker
+               // error when using GNU ld.  So take out -rdynamic if
+               // we added it.  We do it in this order, rather than
+               // only adding -rdynamic later, so that -extldflags
+               // can override -rdynamic without using -static.
+               if(iself && strncmp(p, "-static", 7) == 0 && (p[7]==' ' || p[7]=='\0')) {
+                       for(i=0; i<argc; i++) {
+                               if(strcmp(argv[i], "-rdynamic") == 0)
+                                       argv[i] = "-static";
+                       }
+               }
+
                p = strchr(p + 1, ' ');
        }