Commit 296d6871 authored by Russ Cox's avatar Russ Cox

ld: make ELF binaries with no shared library dependencies static binaries

$ 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
parent a3baf7f9
...@@ -454,6 +454,7 @@ loaddynimport(char *file, char *pkg, char *p, int n) ...@@ -454,6 +454,7 @@ loaddynimport(char *file, char *pkg, char *p, int n)
if(strcmp(name, "_") == 0 && strcmp(def, "_") == 0) { if(strcmp(name, "_") == 0 && strcmp(def, "_") == 0) {
// allow #pragma dynimport _ _ "foo.so" // allow #pragma dynimport _ _ "foo.so"
// to force a link of foo.so. // to force a link of foo.so.
havedynamic = 1;
adddynlib(lib); adddynlib(lib);
continue; continue;
} }
...@@ -468,6 +469,7 @@ loaddynimport(char *file, char *pkg, char *p, int n) ...@@ -468,6 +469,7 @@ loaddynimport(char *file, char *pkg, char *p, int n)
s->dynimpname = def; s->dynimpname = def;
s->dynimpvers = q; s->dynimpvers = q;
s->type = SDYNIMPORT; s->type = SDYNIMPORT;
havedynamic = 1;
} }
} }
return; return;
......
...@@ -259,6 +259,18 @@ loadlib(void) ...@@ -259,6 +259,18 @@ loadlib(void)
Bprint(&bso, "%5.2f autolib: %s (from %s)\n", cputime(), library[i].file, library[i].objref); Bprint(&bso, "%5.2f autolib: %s (from %s)\n", cputime(), library[i].file, library[i].objref);
objfile(library[i].file, library[i].pkg); 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;
} }
/* /*
......
...@@ -122,6 +122,7 @@ EXTERN char* outfile; ...@@ -122,6 +122,7 @@ EXTERN char* outfile;
EXTERN int32 nsymbol; EXTERN int32 nsymbol;
EXTERN char* thestring; EXTERN char* thestring;
EXTERN int ndynexp; EXTERN int ndynexp;
EXTERN int havedynamic;
EXTERN Segment segtext; EXTERN Segment segtext;
EXTERN Segment segdata; EXTERN Segment segdata;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment