github.com/bgentry/go@v0.0.0-20150121062915-6cf5a733d54d/src/liblink/go.c (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // go-specific code shared across loaders (5l, 6l, 8l). 6 7 #include <u.h> 8 #include <libc.h> 9 #include <bio.h> 10 #include <link.h> 11 12 int framepointer_enabled; 13 int fieldtrack_enabled; 14 15 // Toolchain experiments. 16 // These are controlled by the GOEXPERIMENT environment 17 // variable recorded when the toolchain is built. 18 // This list is also known to cmd/gc. 19 static struct { 20 char *name; 21 int *val; 22 } exper[] = { 23 {"fieldtrack", &fieldtrack_enabled}, 24 {"basepointer", &framepointer_enabled}, 25 }; 26 27 static void 28 addexp(char *s) 29 { 30 int i; 31 32 for(i=0; i < nelem(exper); i++ ) { 33 if(strcmp(exper[i].name, s) == 0) { 34 if(exper[i].val != nil) 35 *exper[i].val = 1; 36 return; 37 } 38 } 39 40 print("unknown experiment %s\n", s); 41 exits("unknown experiment"); 42 } 43 44 void 45 linksetexp(void) 46 { 47 char *f[20]; 48 int i, nf; 49 50 // cmd/dist #defines GOEXPERIMENT for us. 51 nf = getfields(GOEXPERIMENT, f, nelem(f), 1, ","); 52 for(i=0; i<nf; i++) 53 addexp(f[i]); 54 } 55 56 char* 57 expstring(void) 58 { 59 int i; 60 static char buf[512]; 61 62 strcpy(buf, "X"); 63 for(i=0; i<nelem(exper); i++) 64 if(*exper[i].val) 65 seprint(buf+strlen(buf), buf+sizeof buf, ",%s", exper[i].name); 66 if(strlen(buf) == 1) 67 strcpy(buf, "X,none"); 68 buf[1] = ':'; 69 return buf; 70 } 71 72 // replace all "". with pkg. 73 char* 74 expandpkg(char *t0, char *pkg) 75 { 76 int n; 77 char *p; 78 char *w, *w0, *t; 79 80 n = 0; 81 for(p=t0; (p=strstr(p, "\"\".")) != nil; p+=3) 82 n++; 83 84 if(n == 0) 85 return estrdup(t0); 86 87 w0 = emallocz(strlen(t0) + strlen(pkg)*n); 88 w = w0; 89 for(p=t=t0; (p=strstr(p, "\"\".")) != nil; p=t) { 90 memmove(w, t, p - t); 91 w += p-t; 92 strcpy(w, pkg); 93 w += strlen(pkg); 94 t = p+2; 95 } 96 strcpy(w, t); 97 return w0; 98 } 99 100 void* 101 emallocz(long n) 102 { 103 void *p; 104 105 p = malloc(n); 106 if(p == nil) 107 sysfatal("out of memory"); 108 memset(p, 0, n); 109 return p; 110 } 111 112 char* 113 estrdup(char *p) 114 { 115 p = strdup(p); 116 if(p == nil) 117 sysfatal("out of memory"); 118 return p; 119 } 120 121 void* 122 erealloc(void *p, long n) 123 { 124 p = realloc(p, n); 125 if(p == nil) 126 sysfatal("out of memory"); 127 return p; 128 } 129 130 void 131 double2ieee(uint64 *ieee, float64 f) 132 { 133 memmove(ieee, &f, 8); 134 }