]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: don't automatically mark symbols created by -X as reachable
authorIan Lance Taylor <iant@golang.org>
Sun, 28 Sep 2014 15:27:05 +0000 (08:27 -0700)
committerIan Lance Taylor <iant@golang.org>
Sun, 28 Sep 2014 15:27:05 +0000 (08:27 -0700)
This fixes the bug in which the linker reports "missing Go
type information" when a -X option refers to a symbol that is
not used.

Fixes #8821.

LGTM=rsc
R=rsc, r
CC=golang-codereviews
https://golang.org/cl/151000043

src/cmd/ld/data.c
src/cmd/ld/lib.c
test/linkx.go

index 89226bfe28a2d5eaaa62e9dae1acaec9c8a1b26e..9983a9281cb07f6238d421719d8aa78f5ccbe35e 100644 (file)
@@ -620,6 +620,7 @@ addstrdata(char *name, char *value)
 {
        LSym *s, *sp;
        char *p;
+       uchar reachable;
 
        p = smprint("%s.str", name);
        sp = linklookup(ctxt, p, 0);
@@ -630,13 +631,17 @@ addstrdata(char *name, char *value)
        s = linklookup(ctxt, name, 0);
        s->size = 0;
        s->dupok = 1;
+       reachable = s->reachable;
        addaddr(ctxt, s, sp);
        adduint32(ctxt, s, strlen(value));
        if(PtrSize == 8)
                adduint32(ctxt, s, 0);  // round struct to pointer width
 
-       // in case reachability has already been computed
-       sp->reachable = s->reachable;
+       // addstring, addaddr, etc., mark the symbols as reachable.
+       // In this case that is not necessarily true, so stick to what
+       // we know before entering this function.
+       s->reachable = reachable;
+       sp->reachable = reachable;
 }
 
 vlong
index 3edf7253d473b8cf0634e5fe677682471adc2aa1..f889aba8a98db5a033742180a6c6eb1846b51097 100644 (file)
@@ -222,8 +222,10 @@ loadlib(void)
                // Since we are simulating the import, we have to provide this string.
                cgostrsym = "go.string.\"runtime/cgo\"";
                if(linkrlookup(ctxt, cgostrsym, 0) == nil) {
+                       s = linklookup(ctxt, cgostrsym, 0);
+                       s->type = SRODATA;
+                       s->reachable = 1;
                        addstrdata(cgostrsym, "runtime/cgo");
-                       linklookup(ctxt, cgostrsym, 0)->type = SRODATA;
                }
        }
 
index 36d16aec9bcdc067a9a891ccb5b31acaf01a9a74..06888a229ae4d1c55a1a57966ea3f90d6d4f0cab 100644 (file)
@@ -1,4 +1,4 @@
-// $G $D/$F.go && $L -X main.tbd hello -X main.overwrite trumped $F.$A && ./$A.out
+// $G $D/$F.go && $L -X main.tbd hello -X main.overwrite trumped -X main.nosuchsymbol neverseen $F.$A && ./$A.out
 
 // NOTE: This test is not run by 'run.go' and so not run by all.bash.
 // To run this test you must use the ./run shell script.