]> Cypherpunks repositories - gostls13.git/commitdiff
ld: make ELF binaries with no shared library dependencies static binaries
authorRuss Cox <rsc@golang.org>
Tue, 3 May 2011 05:56:23 +0000 (01:56 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 3 May 2011 05:56:23 +0000 (01:56 -0400)
$ file $GOROOT/bin/{godoc,goyacc}
/home/rsc/g/go/bin/godoc:  ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not strpped
/home/rsc/g/go/bin/goyacc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
$

Fixes #1758.

R=iant
CC=golang-dev
https://golang.org/cl/4428079

src/cmd/ld/go.c
src/cmd/ld/lib.c
src/cmd/ld/lib.h

index e52c5cb34d3fedacc1ab6daf215aca47761516a9..a19fe460db6c91e660d9de4b99572384c8bca659 100644 (file)
@@ -454,6 +454,7 @@ loaddynimport(char *file, char *pkg, char *p, int n)
                if(strcmp(name, "_") == 0 && strcmp(def, "_") == 0) {
                        // allow #pragma dynimport _ _ "foo.so"
                        // to force a link of foo.so.
+                       havedynamic = 1;
                        adddynlib(lib);
                        continue;
                }
@@ -468,6 +469,7 @@ loaddynimport(char *file, char *pkg, char *p, int n)
                        s->dynimpname = def;
                        s->dynimpvers = q;
                        s->type = SDYNIMPORT;
+                       havedynamic = 1;
                }
        }
        return;
index 15219ba1165296b7a6b7b3a6179f0e31bbf57d73..105d982e4b1f54d0971d2c55399c2338bc44b683 100644 (file)
@@ -259,6 +259,18 @@ loadlib(void)
                        Bprint(&bso, "%5.2f autolib: %s (from %s)\n", cputime(), library[i].file, library[i].objref);
                objfile(library[i].file, library[i].pkg);
        }
+       
+       // We've loaded all the code now.
+       // If there are no dynamic libraries needed, gcc disables dynamic linking.
+       // Because of this, glibc's dynamic ELF loader occasionally (like in version 2.13)
+       // assumes that a dynamic binary always refers to at least one dynamic library.
+       // Rather than be a source of test cases for glibc, disable dynamic linking
+       // the same way that gcc would.
+       //
+       // Exception: on OS X, programs such as Shark only work with dynamic
+       // binaries, so leave it enabled on OS X (Mach-O) binaries.
+       if(!havedynamic && HEADTYPE != Hdarwin)
+               debug['d'] = 1;
 }
 
 /*
index 8b603a04a68bb1e9447f5118de06fa9f47148746..447045f01b86608c827f96842c36328c7ddd4742 100644 (file)
@@ -122,6 +122,7 @@ EXTERN      char*   outfile;
 EXTERN int32   nsymbol;
 EXTERN char*   thestring;
 EXTERN int     ndynexp;
+EXTERN int     havedynamic;
 
 EXTERN Segment segtext;
 EXTERN Segment segdata;