From 60f783d92bc07fa7ca78e8efccbbc841d9f9cbcb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 7 Mar 2013 09:19:02 -0500 Subject: cmd/ld: host linking support for linux/amd64 Still to do: non-linux and non-amd64. It may work on other ELF-based amd64 systems too, but untested. "go test -ldflags -hostobj $GOROOT/misc/cgo/test" passes. Much may yet change, but this seems a reasonable checkpoint. R=iant CC=golang-dev https://golang.org/cl/7369057 --- src/cmd/ld/symtab.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/cmd/ld/symtab.c') diff --git a/src/cmd/ld/symtab.c b/src/cmd/ld/symtab.c index 89a594872e..d8b8b93289 100644 --- a/src/cmd/ld/symtab.c +++ b/src/cmd/ld/symtab.c @@ -121,7 +121,17 @@ putelfsym(Sym *x, char *s, int t, vlong addr, vlong size, int ver, Sym *go) // One pass for each binding: STB_LOCAL, STB_GLOBAL, // maybe one day STB_WEAK. - bind = (ver || (x->type & SHIDDEN)) ? STB_LOCAL : STB_GLOBAL; + bind = STB_GLOBAL; + if(ver || (x->type & SHIDDEN)) + bind = STB_LOCAL; + + // In external linking mode, we have to invoke gcc with -rdynamic + // to get the exported symbols put into the dynamic symbol table. + // To avoid filling the dynamic table with lots of unnecessary symbols, + // mark all Go symbols local (not global) in the final executable. + if(linkmode == LinkExternal && !(x->cgoexport&CgoExportStatic)) + bind = STB_LOCAL; + if(bind != elfbind) return; -- cgit v1.3-5-g9baa