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);
#else
extern void goCallback(void);
void setCallback(void *f) { (void)f; }
__thread int tlsvar = 12345;
#endif
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")
}
}
......@@ -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);
}
}
}
......
......@@ -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;
......
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