]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: keep build version around in binaries
authorKeith Randall <khr@golang.org>
Tue, 22 Jul 2014 03:52:11 +0000 (20:52 -0700)
committerKeith Randall <khr@golang.org>
Tue, 22 Jul 2014 03:52:11 +0000 (20:52 -0700)
So we can tell from a binary which version of
Go built it.

LGTM=minux, rsc
R=golang-codereviews, minux, khr, rsc, dave
CC=golang-codereviews
https://golang.org/cl/117040043

src/cmd/dist/buildruntime.c
src/pkg/runtime/proc.c

index 4e5295b658b1970bfd96f0ff02b00551f957acca..b16b5756ccd58e94ff0469a3555f3d66d42b651f 100644 (file)
@@ -30,7 +30,8 @@ mkzversion(char *dir, char *file)
                "package runtime\n"
                "\n"
                "const defaultGoroot = `%s`\n"
-               "const theVersion = `%s`\n", goroot_final, goversion));
+               "const theVersion = `%s`\n"
+               "var buildVersion = theVersion\n", goroot_final, goversion));
 
        writefile(&out, file, 0);
        
index 21b036eaeaf4ed563515f3fb24e6c5041db42413..55c58442bace1144302d0818acd57d8d4b90bb22 100644 (file)
@@ -129,6 +129,8 @@ static bool exitsyscallfast(void);
 static bool haveexperiment(int8*);
 static void allgadd(G*);
 
+extern String runtime·buildVersion;
+
 // The bootstrap sequence is:
 //
 //     call osinit
@@ -188,6 +190,13 @@ runtime·schedinit(void)
                runtime·copystack = false;
 
        mstats.enablegc = 1;
+
+       if(runtime·buildVersion.str == nil) {
+               // Condition should never trigger.  This code just serves
+               // to ensure runtime·buildVersion is kept in the resulting binary.
+               runtime·buildVersion.str = (uint8*)"unknown";
+               runtime·buildVersion.len = 7;
+       }
 }
 
 extern void main·init(void);