]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: don't emit unreachable dynimport symbols in ELF symtab.
authorShenghou Ma <minux.ma@gmail.com>
Sun, 23 Feb 2014 21:20:40 +0000 (16:20 -0500)
committerShenghou Ma <minux.ma@gmail.com>
Sun, 23 Feb 2014 21:20:40 +0000 (16:20 -0500)
Fix build for Dragonfly BSD.
Fixes #7318.
Fixes #7367.

LGTM=jsing, iant
R=jsing, iant, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/64340043

misc/cgo/testso/cgoso_c.c
misc/cgo/testso/cgoso_unix.go [new file with mode: 0644]
src/cmd/ld/data.c
src/cmd/ld/symtab.c

index 27155c27f7b6c2782f5e06fdebf643cd28f9801f..9b77a76fcf0161ec03fbe19c09ad5f5231e92d44 100644 (file)
@@ -17,6 +17,7 @@ __declspec(dllexport) void sofunc(void);
 #else
 extern void goCallback(void);
 void setCallback(void *f) { (void)f; }
+__thread int tlsvar = 12345;
 #endif
 
 void sofunc(void)
diff --git a/misc/cgo/testso/cgoso_unix.go b/misc/cgo/testso/cgoso_unix.go
new file mode 100644 (file)
index 0000000..e86f992
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux netbsd
+
+package cgosotest
+
+/*
+extern int __thread tlsvar;
+int *getTLS() { return &tlsvar; }
+*/
+import "C"
+
+func init() {
+       if v := *C.getTLS(); v != 12345 {
+               println("got", v)
+               panic("BAD TLS value")
+       }
+}
index 8acb72331c23cea124ef0f5b39ac731a1a8ff559..8c6cfed86275e63be209de96f00e8b301796e03a 100644 (file)
@@ -303,7 +303,7 @@ void
 dynrelocsym(LSym *s)
 {
        Reloc *r;
-       
+
        if(HEADTYPE == Hwindows) {
                LSym *rel, *targ;
 
@@ -312,6 +312,8 @@ dynrelocsym(LSym *s)
                        return;
                for(r=s->r; r<s->r+s->nr; r++) {
                        targ = r->sym;
+                       if(!targ->reachable)
+                               diag("internal inconsistency: dynamic symbol %s is not reachable.", targ->name);
                        if(r->sym->plt == -2 && r->sym->got != -2) { // make dynimport JMP table for PE object files.
                                targ->plt = rel->size;
                                r->sym = rel;
@@ -340,8 +342,11 @@ dynrelocsym(LSym *s)
        }
 
        for(r=s->r; r<s->r+s->nr; r++) {
-               if(r->sym != S && r->sym->type == SDYNIMPORT || r->type >= 256)
+               if(r->sym != S && r->sym->type == SDYNIMPORT || r->type >= 256) {
+                       if(!r->sym->reachable)
+                               diag("internal inconsistency: dynamic symbol %s is not reachable.", r->sym->name);
                        adddynrel(s, r);
+               }
        }
 }
 
index c585f96e0ffb3af9e999d76f0a8759139c5d37bf..d26ea0d04ef5533656f47498a4ead26885b26875 100644 (file)
@@ -197,7 +197,7 @@ asmelfsym(void)
        genasmsym(putelfsym);
        
        for(s=ctxt->allsym; s!=S; s=s->allsym) {
-               if(s->type != SHOSTOBJ && s->type != SDYNIMPORT)
+               if(s->type != SHOSTOBJ && !(s->type == SDYNIMPORT && s->reachable))
                        continue;
                if(s->type == SDYNIMPORT)
                        name = s->extname;