~ubuntu-branches/ubuntu/trusty/golang/trusty

« back to all changes in this revision

Viewing changes to src/cmd/dist/buildruntime.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
// license that can be found in the LICENSE file.
4
4
 
5
5
#include "a.h"
6
 
#include <stdio.h>
7
6
 
8
7
/*
9
8
 * Helpers for building pkg/runtime.
20
19
{
21
20
        Buf b, out;
22
21
        
 
22
        USED(dir);
 
23
 
23
24
        binit(&b);
24
25
        binit(&out);
25
26
        
46
47
mkzgoarch(char *dir, char *file)
47
48
{
48
49
        Buf b, out;
 
50
 
 
51
        USED(dir);
49
52
        
50
53
        binit(&b);
51
54
        binit(&out);
72
75
mkzgoos(char *dir, char *file)
73
76
{
74
77
        Buf b, out;
 
78
 
 
79
        USED(dir);
75
80
        
76
81
        binit(&b);
77
82
        binit(&out);
100
105
                "#define        m(r)    4(r)\n"
101
106
        },
102
107
        {"386", "plan9",
 
108
                "// Plan 9 does not have per-process segment descriptors with\n"
 
109
                "// which to do thread-local storage. Instead, we will use a\n"
 
110
                "// fixed offset from the per-process TOS struct address for\n"
 
111
                "// the local storage. Since the process ID is contained in the\n"
 
112
                "// TOS struct, we specify an offset for that here as well.\n"
103
113
                "#define        get_tls(r)      MOVL _tos(SB), r \n"
104
114
                "#define        g(r)    -8(r)\n"
105
115
                "#define        m(r)    -4(r)\n"
 
116
                "#define        procid(r)       48(r)\n"
106
117
        },
107
118
        {"386", "linux",
108
119
                "// On Linux systems, what we call 0(GS) and 4(GS) for g and m\n"
122
133
                "// which is where these macros come into play.\n"
123
134
                "// get_tls sets up the temporary and then g and r use it.\n"
124
135
                "//\n"
125
 
                "// The final wrinkle is that get_tls needs to read from %gs:0,\n"
 
136
                "// Another wrinkle is that get_tls needs to read from %gs:0,\n"
126
137
                "// but in 8l input it's called 8(GS), because 8l is going to\n"
127
138
                "// subtract 8 from all the offsets, as described above.\n"
 
139
                "//\n"
 
140
                "// The final wrinkle is that when generating an ELF .o file for\n"
 
141
                "// external linking mode, we need to be able to relocate the\n"
 
142
                "// -8(r) and -4(r) instructions. Tag them with an extra (GS*1)\n"
 
143
                "// that is ignored by the linker except for that identification.\n"
128
144
                "#define        get_tls(r)      MOVL 8(GS), r\n"
129
 
                "#define        g(r)    -8(r)\n"
130
 
                "#define        m(r)    -4(r)\n"
 
145
                "#define        g(r)    -8(r)(GS*1)\n"
 
146
                "#define        m(r)    -4(r)(GS*1)\n"
131
147
        },
132
148
        {"386", "",
133
149
                "#define        get_tls(r)\n"
140
156
                "#define        g(r) 0(r)\n"
141
157
                "#define        m(r) 8(r)\n"
142
158
        },
 
159
        {"amd64", "plan9",
 
160
                "#define        get_tls(r)\n"
 
161
                "#define        g(r) 0(GS)\n"
 
162
                "#define        m(r) 8(GS)\n"
 
163
                "#define        procid(r) 16(GS)\n"
 
164
        },
143
165
        {"amd64", "",
144
166
                "// The offsets 0 and 8 are known to:\n"
145
167
                "//     ../../cmd/6l/pass.c:/D_GS\n"
188
210
        fatal("unknown $GOOS/$GOARCH in mkzasm");
189
211
ok:
190
212
 
191
 
        // Run 6c -DGOOS_goos -DGOARCH_goarch -Iworkdir -a proc.c
 
213
        // Run 6c -D GOOS_goos -D GOARCH_goarch -I workdir -a -n -o workdir/proc.acid proc.c
192
214
        // to get acid [sic] output.
193
215
        vreset(&argv);
194
216
        vadd(&argv, bpathf(&b, "%s/%sc", tooldir, gochar));
195
 
        vadd(&argv, bprintf(&b, "-DGOOS_%s", goos));
196
 
        vadd(&argv, bprintf(&b, "-DGOARCH_%s", goarch));
197
 
        vadd(&argv, bprintf(&b, "-I%s", workdir));
 
217
        vadd(&argv, "-D");
 
218
        vadd(&argv, bprintf(&b, "GOOS_%s", goos));
 
219
        vadd(&argv, "-D");
 
220
        vadd(&argv, bprintf(&b, "GOARCH_%s", goarch));
 
221
        vadd(&argv, "-I");
 
222
        vadd(&argv, bprintf(&b, "%s", workdir));
198
223
        vadd(&argv, "-a");
 
224
        vadd(&argv, "-n");
 
225
        vadd(&argv, "-o");
 
226
        vadd(&argv, bpathf(&b, "%s/proc.acid", workdir));
199
227
        vadd(&argv, "proc.c");
200
 
        runv(&in, dir, CheckExit, &argv);
 
228
        runv(nil, dir, CheckExit, &argv);
 
229
        readfile(&in, bpathf(&b, "%s/proc.acid", workdir));
201
230
        
202
231
        // Convert input like
203
232
        //      aggr G
222
251
                                aggr = "gobuf";
223
252
                        else if(streq(fields.p[1], "WinCall"))
224
253
                                aggr = "wincall";
 
254
                        else if(streq(fields.p[1], "SEH"))
 
255
                                aggr = "seh";
225
256
                }
226
257
                if(hasprefix(lines.p[i], "}"))
227
258
                        aggr = nil;
251
282
        "iface.c",
252
283
        "hashmap.c",
253
284
        "chan.c",
 
285
        "parfor.c",
254
286
};
255
287
 
256
288
// mkzruntimedefs writes zruntime_defs_$GOOS_$GOARCH.h,
265
297
{
266
298
        int i, skip;
267
299
        char *p;
268
 
        Buf in, b, out;
 
300
        Buf in, b, b1, out;
269
301
        Vec argv, lines, fields, seen;
270
302
        
271
303
        binit(&in);
272
304
        binit(&b);
 
305
        binit(&b1);
273
306
        binit(&out);
274
307
        vinit(&argv);
275
308
        vinit(&lines);
285
318
        );
286
319
 
287
320
        
288
 
        // Run 6c -DGOOS_goos -DGOARCH_goarch -Iworkdir -q
 
321
        // Run 6c -D GOOS_goos -D GOARCH_goarch -I workdir -q -n -o workdir/runtimedefs
289
322
        // on each of the runtimedefs C files.
290
323
        vadd(&argv, bpathf(&b, "%s/%sc", tooldir, gochar));
291
 
        vadd(&argv, bprintf(&b, "-DGOOS_%s", goos));
292
 
        vadd(&argv, bprintf(&b, "-DGOARCH_%s", goarch));
293
 
        vadd(&argv, bprintf(&b, "-I%s", workdir));
 
324
        vadd(&argv, "-D");
 
325
        vadd(&argv, bprintf(&b, "GOOS_%s", goos));
 
326
        vadd(&argv, "-D");
 
327
        vadd(&argv, bprintf(&b, "GOARCH_%s", goarch));
 
328
        vadd(&argv, "-I");
 
329
        vadd(&argv, bprintf(&b, "%s", workdir));
294
330
        vadd(&argv, "-q");
 
331
        vadd(&argv, "-n");
 
332
        vadd(&argv, "-o");
 
333
        vadd(&argv, bpathf(&b, "%s/runtimedefs", workdir));
295
334
        vadd(&argv, "");
296
335
        p = argv.p[argv.len-1];
297
336
        for(i=0; i<nelem(runtimedefs); i++) {
298
337
                argv.p[argv.len-1] = runtimedefs[i];
299
 
                runv(&b, dir, CheckExit, &argv);
 
338
                runv(nil, dir, CheckExit, &argv);
 
339
                readfile(&b, bpathf(&b1, "%s/runtimedefs", workdir));
300
340
                bwriteb(&in, &b);
301
341
        }
302
342
        argv.p[argv.len-1] = p;
338
378
 
339
379
        bfree(&in);
340
380
        bfree(&b);
 
381
        bfree(&b1);
341
382
        bfree(&out);
342
383
        vfree(&argv);
343
384
        vfree(&lines);