Commit d4a9bbef authored by Shenghou Ma's avatar Shenghou Ma

cmd/ld: don't emit unreachable dynimport symbols in ELF symtab.

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
parent d4b6a198
...@@ -17,6 +17,7 @@ __declspec(dllexport) void sofunc(void); ...@@ -17,6 +17,7 @@ __declspec(dllexport) void sofunc(void);
#else #else
extern void goCallback(void); extern void goCallback(void);
void setCallback(void *f) { (void)f; } void setCallback(void *f) { (void)f; }
__thread int tlsvar = 12345;
#endif #endif
void sofunc(void) void sofunc(void)
......
// 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")
}
}
...@@ -312,6 +312,8 @@ dynrelocsym(LSym *s) ...@@ -312,6 +312,8 @@ dynrelocsym(LSym *s)
return; return;
for(r=s->r; r<s->r+s->nr; r++) { for(r=s->r; r<s->r+s->nr; r++) {
targ = r->sym; 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. if(r->sym->plt == -2 && r->sym->got != -2) { // make dynimport JMP table for PE object files.
targ->plt = rel->size; targ->plt = rel->size;
r->sym = rel; r->sym = rel;
...@@ -340,9 +342,12 @@ dynrelocsym(LSym *s) ...@@ -340,9 +342,12 @@ dynrelocsym(LSym *s)
} }
for(r=s->r; r<s->r+s->nr; r++) { 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); adddynrel(s, r);
} }
}
} }
void void
......
...@@ -197,7 +197,7 @@ asmelfsym(void) ...@@ -197,7 +197,7 @@ asmelfsym(void)
genasmsym(putelfsym); genasmsym(putelfsym);
for(s=ctxt->allsym; s!=S; s=s->allsym) { 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; continue;
if(s->type == SDYNIMPORT) if(s->type == SDYNIMPORT)
name = s->extname; name = s->extname;
......
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