~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/cmd/6l/obj.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
};
59
59
 
60
60
/*
61
 
 *      -Hplan9x32 -T4136 -R4096        is plan9 64-bit format
62
 
 *      -Hplan9 -T4128 -R4096           is plan9 32-bit format
 
61
 *      -Hplan9x32 -T4128 -R4096        is plan9 32-bit format
 
62
 *      -Hplan9 -T0x200028 -R0x200000   is plan9 64-bit format
63
63
 *      -Helf -T0x80110000 -R4096       is ELF32
64
64
 *      -Hdarwin -Tx -Rx                is apple MH-exec
65
65
 *      -Hlinux -Tx -Rx                 is linux elf-exec
67
67
 *      -Hnetbsd -Tx -Rx                is NetBSD elf-exec
68
68
 *      -Hopenbsd -Tx -Rx               is OpenBSD elf-exec
69
69
 *      -Hwindows -Tx -Rx               is MS Windows PE32+
70
 
 *
71
 
 *      options used: 189BLQSWabcjlnpsvz
72
70
 */
73
71
 
74
72
void
75
 
usage(void)
76
 
{
77
 
        fprint(2, "usage: 6l [-options] [-E entry] [-H head] [-I interpreter] [-L dir] [-T text] [-R rnd] [-r path] [-o out] main.6\n");
78
 
        exits("usage");
79
 
}
80
 
 
81
 
void
82
73
main(int argc, char *argv[])
83
74
{
84
 
        int c;
85
 
        char *name, *val;
86
 
 
87
75
        Binit(&bso, 1, OWRITE);
88
76
        listinit();
89
77
        memset(debug, 0, sizeof(debug));
94
82
        INITDAT = -1;
95
83
        INITRND = -1;
96
84
        INITENTRY = 0;
 
85
        LIBINITENTRY = 0;
 
86
        linkmode = LinkAuto;
97
87
        nuxiinit();
98
88
 
99
 
        ARGBEGIN {
100
 
        default:
101
 
                c = ARGC();
102
 
                if(c == 'l')
103
 
                        usage();
104
 
                if(c >= 0 && c < sizeof(debug))
105
 
                        debug[c]++;
106
 
                break;
107
 
        case 'o': /* output to (next arg) */
108
 
                outfile = EARGF(usage());
109
 
                break;
110
 
        case 'E':
111
 
                INITENTRY = EARGF(usage());
112
 
                break;
113
 
        case 'H':
114
 
                HEADTYPE = headtype(EARGF(usage()));
115
 
                break;
116
 
        case 'I':
117
 
                interpreter = EARGF(usage());
118
 
                break;
119
 
        case 'L':
120
 
                Lflag(EARGF(usage()));
121
 
                break;
122
 
        case 'T':
123
 
                INITTEXT = atolwhex(EARGF(usage()));
124
 
                break;
125
 
        case 'D':
126
 
                INITDAT = atolwhex(EARGF(usage()));
127
 
                break;
128
 
        case 'R':
129
 
                INITRND = atolwhex(EARGF(usage()));
130
 
                break;
131
 
        case 'r':
132
 
                rpath = EARGF(usage());
133
 
                break;
134
 
        case 'V':
135
 
                print("%cl version %s\n", thechar, getgoversion());
136
 
                errorexit();
137
 
        case 'X':
138
 
                name = EARGF(usage());
139
 
                val = EARGF(usage());
140
 
                addstrdata(name, val);
141
 
                break;
142
 
        } ARGEND
 
89
        flagcount("1", "use alternate profiling code", &debug['1']);
 
90
        flagcount("8", "assume 64-bit addresses", &debug['8']);
 
91
        flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo);
 
92
        flagint64("D", "addr: data address", &INITDAT);
 
93
        flagstr("E", "sym: entry symbol", &INITENTRY);
 
94
        flagfn1("I", "interp: set ELF interp", setinterp);
 
95
        flagfn1("L", "dir: add dir to library path", Lflag);
 
96
        flagfn1("H", "head: header type", setheadtype);
 
97
        flagcount("K", "add stack underflow checks", &debug['K']);
 
98
        flagcount("O", "print pc-line tables", &debug['O']);
 
99
        flagcount("Q", "debug byte-register code gen", &debug['Q']);
 
100
        flagint32("R", "rnd: address rounding", &INITRND);
 
101
        flagcount("S", "check type signatures", &debug['S']);
 
102
        flagint64("T", "addr: text address", &INITTEXT);
 
103
        flagfn0("V", "print version and exit", doversion);
 
104
        flagcount("W", "disassemble input", &debug['W']);
 
105
        flagfn2("X", "name value: define string data", addstrdata);
 
106
        flagcount("Z", "clear stack frame on entry", &debug['Z']);
 
107
        flagcount("a", "disassemble output", &debug['a']);
 
108
        flagcount("c", "dump call graph", &debug['c']);
 
109
        flagcount("d", "disable dynamic executable", &debug['d']);
 
110
        flagstr("extld", "linker to run in external mode", &extld);
 
111
        flagstr("extldflags", "flags for external linker", &extldflags);
 
112
        flagcount("f", "ignore version mismatch", &debug['f']);
 
113
        flagcount("g", "disable go package data checks", &debug['g']);
 
114
        flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
 
115
        flagstr("k", "sym: set field tracking symbol", &tracksym);
 
116
        flagcount("n", "dump symbol table", &debug['n']);
 
117
        flagstr("o", "outfile: set output file", &outfile);
 
118
        flagcount("p", "insert profiling code", &debug['p']);
 
119
        flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath);
 
120
        flagcount("race", "enable race detector", &flag_race);
 
121
        flagcount("s", "disable symbol table", &debug['s']);
 
122
        flagcount("shared", "generate shared object", &flag_shared);
 
123
        flagstr("tmpdir", "leave temporary files in this directory", &tmpdir);
 
124
        flagcount("u", "reject unsafe packages", &debug['u']);
 
125
        flagcount("v", "print link trace", &debug['v']);
 
126
        flagcount("w", "disable DWARF generation", &debug['w']);
 
127
        
 
128
        flagparse(&argc, &argv, usage);
143
129
 
144
130
        if(argc != 1)
145
131
                usage();
149
135
        if(HEADTYPE == -1)
150
136
                HEADTYPE = headtype(goos);
151
137
 
 
138
        // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
 
139
        // Go was built; see ../../make.bash.
 
140
        if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0)
 
141
                linkmode = LinkInternal;
 
142
 
 
143
        switch(HEADTYPE) {
 
144
        default:
 
145
                if(linkmode == LinkAuto)
 
146
                        linkmode = LinkInternal;
 
147
                if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0)
 
148
                        sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
 
149
                break;
 
150
        case Hdarwin:
 
151
        case Hfreebsd:
 
152
        case Hlinux:
 
153
        case Hnetbsd:
 
154
        case Hopenbsd:
 
155
                break;
 
156
        }
 
157
 
152
158
        if(outfile == nil) {
153
159
                if(HEADTYPE == Hwindows)
154
160
                        outfile = "6.out.exe";
163
169
                diag("unknown -H option");
164
170
                errorexit();
165
171
        case Hplan9x32: /* plan 9 */
166
 
                HEADR = 32L+8L;
 
172
                HEADR = 32L;
167
173
                if(INITTEXT == -1)
168
174
                        INITTEXT = 4096+HEADR;
169
175
                if(INITDAT == -1)
172
178
                        INITRND = 4096;
173
179
                break;
174
180
        case Hplan9x64: /* plan 9 */
175
 
                HEADR = 32L;
 
181
                HEADR = 32L + 8L;
176
182
                if(INITTEXT == -1)
177
 
                        INITTEXT = 4096+32;
 
183
                        INITTEXT = 0x200000+HEADR;
178
184
                if(INITDAT == -1)
179
185
                        INITDAT = 0;
180
186
                if(INITRND == -1)
181
 
                        INITRND = 4096;
 
187
                        INITRND = 0x200000;
182
188
                break;
183
189
        case Helf:      /* elf32 executable */
184
190
                HEADR = rnd(52L+3*32L, 16);
291
297
        reloc();
292
298
        asmb();
293
299
        undef();
 
300
        hostlink();
294
301
        if(debug['v']) {
295
302
                Bprint(&bso, "%5.2f cpu time\n", cputime());
296
303
                Bprint(&bso, "%d symbols\n", nsymbol);
421
428
        ntext = 0;
422
429
        eof = Boffset(f) + len;
423
430
        src[0] = 0;
 
431
        pn = estrdup(pn); // we keep it in Sym* references
424
432
 
425
433
newloop:
426
434
        memset(h, 0, sizeof(h));
506
514
        p->line = Bget4(f);
507
515
        p->back = 2;
508
516
        p->mode = mode;
509
 
        p->ft = 0;
510
 
        p->tt = 0;
511
517
        zaddr(pn, f, &p->from, h);
512
518
        fromgotype = adrgotype;
513
519
        zaddr(pn, f, &p->to, h);
597
603
                pc++;
598
604
                goto loop;
599
605
 
 
606
        case ALOCALS:
 
607
                if(skip)
 
608
                        goto casdef;
 
609
                cursym->locals = p->to.offset;
 
610
                pc++;
 
611
                goto loop;
 
612
        
 
613
        case ATYPE:
 
614
                if(skip)
 
615
                        goto casdef;
 
616
                pc++;
 
617
                goto loop;
 
618
 
600
619
        case ATEXT:
601
620
                s = p->from.sym;
602
621
                if(s->text != nil) {
640
659
                }
641
660
                s->type = STEXT;
642
661
                s->value = pc;
 
662
                s->args = p->to.offset >> 32;
643
663
                lastp = p;
644
664
                p->pc = pc++;
645
665
                goto loop;
677
697
                        sprint(literal, "$%ux", ieeedtof(&p->from.ieee));
678
698
                        s = lookup(literal, 0);
679
699
                        if(s->type == 0) {
680
 
                                s->type = SDATA;
 
700
                                s->type = SRODATA;
681
701
                                adduint32(s, ieeedtof(&p->from.ieee));
682
702
                                s->reachable = 0;
683
703
                        }
711
731
                                p->from.ieee.l, p->from.ieee.h);
712
732
                        s = lookup(literal, 0);
713
733
                        if(s->type == 0) {
714
 
                                s->type = SDATA;
 
734
                                s->type = SRODATA;
715
735
                                adduint32(s, p->from.ieee.l);
716
736
                                adduint32(s, p->from.ieee.h);
717
737
                                s->reachable = 0;