void main(int argc, char *argv[]) { int c; char *a; char name[LIBNAMELEN]; Binit(&bso, 1, OWRITE); cout = -1; listinit(); outfile = 0; nerrors = 0; curtext = P; HEADTYPE = -1; INITTEXT = -1; INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'L': addlibpath(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'P': a = ARGF(); if(a) INITTEXTP = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); /* do something about setting INITTEXT */ break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) usage(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; a = getenv("ccroot"); if(a != nil && *a != '\0') { if(!fileexists(a)) { diag("nonexistent $ccroot: %s", a); errorexit(); } }else a = ""; snprint(name, sizeof(name), "%s/%s/lib", a, thestring); addlibpath(name); if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 0; if(debug['B']) HEADTYPE = 1; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* no header */ case 6: /* no header, padded segments */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 1: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 2: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 3: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 4: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 5: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case 7: /* elf executable */ HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; } if (INITTEXTP == -1) INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%lux -D0x%lux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; textp = P; datap = P; pc = 0; dtype = 4; if(outfile == 0) outfile = "5.out"; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else if(!(*INITENTRY >= '0' && *INITENTRY <= '9')) lookup(INITENTRY, 0)->type = SXREF; while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) goto out; if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ initdiv(); import(); HEADTYPE = 2; INITTEXT = INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } else divsig(); export();
void main(int argc, char *argv[]) { int c; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); break; case 'I': interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND if(argc != 1) usage(); mywhatsys(); // get goos if(HEADTYPE == -1) HEADTYPE = headtype(goos); if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = "8.out.exe"; else outfile = "8.out"; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hgarbunix: /* this is garbage */ HEADR = 20L+56L; if(INITTEXT == -1) INITTEXT = 0x40004CL; if(INITDAT == -1) INITDAT = 0x10000000L; if(INITRND == -1) INITRND = 0; break; case Hunixcoff: /* is unix coff */ HEADR = 0xd0L; if(INITTEXT == -1) INITTEXT = 0xd0; if(INITDAT == -1) INITDAT = 0x400000; if(INITRND == -1) INITRND = 0; break; case Hplan9x32: /* plan 9 */ tlsoffset = -8; HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+32; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hmsdoscom: /* MS-DOS .COM */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hmsdosexe: /* fake MS-DOS .EXE */ HEADR = 0x200; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; HEADR += (INITTEXT & 0xFFFF); if(debug['v']) Bprint(&bso, "HEADR = 0x%d\n", HEADR); break; case Hdarwin: /* apple MACH */ /* * OS X system constant - offset from %gs to our TLS. * Explained in ../../libcgo/darwin_386.c. */ tlsoffset = 0x468; machoinit(); HEADR = INITIAL_MACHO_HEADR; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hlinux: /* elf32 executable */ case Hfreebsd: /* * ELF uses TLS offsets negative from %gs. * Translate 0(GS) and 4(GS) into -8(GS) and -4(GS). * Also known to ../../pkg/runtime/linux/386/sys.s * and ../../libcgo/linux_386.c. */ tlsoffset = -8; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x08048000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hwindows: /* PE executable */ peinit(); HEADR = PEFILEHEADR; if(INITTEXT == -1) INITTEXT = PEBASE+PESECTHEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = PESECTALIGN; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); instinit(); zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; pcstr = "%.6ux "; nuxiinit(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); deadcode(); patch(); follow(); doelf(); if(HEADTYPE == Hdarwin) domacho(); if(HEADTYPE == Hwindows) dope(); dostkoff(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); span(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { int i, c; char *a; char name[LIBNAMELEN]; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = "8.out"; HEADTYPE = -1; INITTEXT = -1; INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'L': addlibpath(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'P': a = ARGF(); if(a) INITTEXTP = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])){ a = ARGF(); if(strcmp(a, "*") == 0) allexport = 1; else readundefs(a, SEXPORT); } break; case 'u': /* produce dynamically loadable module */ dlm = 1; debug['l']++; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) usage(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; a = getenv("ccroot"); if(a != nil && *a != '\0') { if(!fileexists(a)) { diag("nonexistent $ccroot: %s", a); errorexit(); } }else a = ""; snprint(name, sizeof(name), "%s/%s/lib", a, thestring); addlibpath(name); if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 1; if(debug['B']) HEADTYPE = 2; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* this is garbage */ HEADR = 20L+56L; if(INITTEXT == -1) INITTEXT = 0x40004CL; if(INITDAT == -1) INITDAT = 0x10000000L; if(INITRND == -1) INITRND = 0; break; case 1: /* is unix coff */ HEADR = 0xd0L; if(INITTEXT == -1) INITTEXT = 0xd0; if(INITDAT == -1) INITDAT = 0x400000; if(INITRND == -1) INITRND = 0; break; case 2: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+32; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 3: /* MS-DOS .COM */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 4: /* fake MS-DOS .EXE */ HEADR = 0x200; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; HEADR += (INITTEXT & 0xFFFF); if(debug['v']) Bprint(&bso, "HEADR = 0x%ld\n", HEADR); break; case 5: /* elf executable */ HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0x80100020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if (INITTEXTP == -1) INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%ld -T0x%lux -D0x%lux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); for(i=1; optab[i].as; i++) if(i != optab[i].as) { diag("phase error in optab: %d", i); errorexit(); } for(i=0; i<Ymax; i++) ycover[i*Ymax + i] = 1; ycover[Yi0*Ymax + Yi8] = 1; ycover[Yi1*Ymax + Yi8] = 1; ycover[Yi0*Ymax + Yi32] = 1; ycover[Yi1*Ymax + Yi32] = 1; ycover[Yi8*Ymax + Yi32] = 1; ycover[Yal*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrb] = 1; ycover[Ycx*Ymax + Yrb] = 1; ycover[Yrx*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrx] = 1; ycover[Ycx*Ymax + Yrx] = 1; ycover[Yax*Ymax + Yrl] = 1; ycover[Ycx*Ymax + Yrl] = 1; ycover[Yrx*Ymax + Yrl] = 1; ycover[Yf0*Ymax + Yrf] = 1; ycover[Yal*Ymax + Ymb] = 1; ycover[Ycl*Ymax + Ymb] = 1; ycover[Yax*Ymax + Ymb] = 1; ycover[Ycx*Ymax + Ymb] = 1; ycover[Yrx*Ymax + Ymb] = 1; ycover[Yrb*Ymax + Ymb] = 1; ycover[Ym*Ymax + Ymb] = 1; ycover[Yax*Ymax + Yml] = 1; ycover[Ycx*Ymax + Yml] = 1; ycover[Yrx*Ymax + Yml] = 1; ycover[Yrl*Ymax + Yml] = 1; ycover[Ym*Ymax + Yml] = 1; for(i=0; i<D_NONE; i++) { reg[i] = -1; if(i >= D_AL && i <= D_BH) reg[i] = (i-D_AL) & 7; if(i >= D_AX && i <= D_DI) reg[i] = (i-D_AX) & 7; if(i >= D_F0 && i <= D_F0+7) reg[i] = (i-D_F0) & 7; } zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; pcstr = "%.6lux "; nuxiinit(); histgen = 0; textp = P; datap = P; edatap = P; pc = 0; dtype = 4; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else if(!(*INITENTRY >= '0' && *INITENTRY <= '9')) lookup(INITENTRY, 0)->type = SXREF; while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) errorexit(); if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void main(int argc, char *argv[]) { int c; char *p, *name, *val; Binit(&bso, 1, OWRITE); listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; nuxiinit(); p = getenv("GOARM"); if(p != nil && strcmp(p, "5") == 0) debug['F'] = 1; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'I': debug['I'] = 1; // denote cmdline interpreter override interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); case 'X': name = EARGF(usage()); val = EARGF(usage()); addstrdata(name, val); break; } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(HEADTYPE == -1) HEADTYPE = Hlinux; switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hnetbsd: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ debug['d'] = 0; // with dynamic linking tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m // this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing if(debug['F']) mark(rlookup("_sfloat", 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); noops(); dostkcheck(); span(); addexport(); // textaddress() functionality is handled in span() pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { int i, c; char *a; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = "6.out"; Lflag("."); HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'L': Lflag(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; debug['l']++; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) { usage(); } if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; if(HEADTYPE == -1) { if(debug['B']) HEADTYPE = 2; if(debug['9']) HEADTYPE = 2; } Lflag(smprint("%s/amd64/lib", (a = getenv("NXM")) == 0 ? "" : a)); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 2: /* plan 9 */ HEADR = 32L+8L; if(INITTEXT == -1) INITTEXT = 0x200000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x200000; break; case 3: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 5: /* elf32 executable */ HEADR = rnd(52L+3*32L, 16); if(INITTEXT == -1) INITTEXT = 0xf0110000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H%ld -T0x%llux -D0x%llux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); for(i=1; optab[i].as; i++) { c = optab[i].as; if(opindex[c] != nil) { diag("phase error in optab: %d (%A)", i, c); errorexit(); } opindex[c] = &optab[i]; } for(i=0; i<Ymax; i++) ycover[i*Ymax + i] = 1; ycover[Yi0*Ymax + Yi8] = 1; ycover[Yi1*Ymax + Yi8] = 1; ycover[Yi0*Ymax + Ys32] = 1; ycover[Yi1*Ymax + Ys32] = 1; ycover[Yi8*Ymax + Ys32] = 1; ycover[Yi0*Ymax + Yi32] = 1; ycover[Yi1*Ymax + Yi32] = 1; ycover[Yi8*Ymax + Yi32] = 1; ycover[Ys32*Ymax + Yi32] = 1; ycover[Yi0*Ymax + Yi64] = 1; ycover[Yi1*Ymax + Yi64] = 1; ycover[Yi8*Ymax + Yi64] = 1; ycover[Ys32*Ymax + Yi64] = 1; ycover[Yi32*Ymax + Yi64] = 1; ycover[Yal*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrb] = 1; ycover[Ycx*Ymax + Yrb] = 1; ycover[Yrx*Ymax + Yrb] = 1; ycover[Yrl*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Ycx] = 1; ycover[Yax*Ymax + Yrx] = 1; ycover[Ycx*Ymax + Yrx] = 1; ycover[Yax*Ymax + Yrl] = 1; ycover[Ycx*Ymax + Yrl] = 1; ycover[Yrx*Ymax + Yrl] = 1; ycover[Yf0*Ymax + Yrf] = 1; ycover[Yal*Ymax + Ymb] = 1; ycover[Ycl*Ymax + Ymb] = 1; ycover[Yax*Ymax + Ymb] = 1; ycover[Ycx*Ymax + Ymb] = 1; ycover[Yrx*Ymax + Ymb] = 1; ycover[Yrb*Ymax + Ymb] = 1; ycover[Yrl*Ymax + Ymb] = 1; ycover[Ym*Ymax + Ymb] = 1; ycover[Yax*Ymax + Yml] = 1; ycover[Ycx*Ymax + Yml] = 1; ycover[Yrx*Ymax + Yml] = 1; ycover[Yrl*Ymax + Yml] = 1; ycover[Ym*Ymax + Yml] = 1; ycover[Yax*Ymax + Ymm] = 1; ycover[Ycx*Ymax + Ymm] = 1; ycover[Yrx*Ymax + Ymm] = 1; ycover[Yrl*Ymax + Ymm] = 1; ycover[Ym*Ymax + Ymm] = 1; ycover[Ymr*Ymax + Ymm] = 1; ycover[Yax*Ymax + Yxm] = 1; ycover[Ycx*Ymax + Yxm] = 1; ycover[Yrx*Ymax + Yxm] = 1; ycover[Yrl*Ymax + Yxm] = 1; ycover[Ym*Ymax + Yxm] = 1; ycover[Yxr*Ymax + Yxm] = 1; for(i=0; i<D_NONE; i++) { reg[i] = -1; if(i >= D_AL && i <= D_R15B) { reg[i] = (i-D_AL) & 7; if(i >= D_SPB && i <= D_DIB) regrex[i] = 0x40; if(i >= D_R8B && i <= D_R15B) regrex[i] = Rxr | Rxx | Rxb; } if(i >= D_AH && i<= D_BH) reg[i] = 4 + ((i-D_AH) & 7); if(i >= D_AX && i <= D_R15) { reg[i] = (i-D_AX) & 7; if(i >= D_R8) regrex[i] = Rxr | Rxx | Rxb; } if(i >= D_F0 && i <= D_F0+7) reg[i] = (i-D_F0) & 7; if(i >= D_M0 && i <= D_M0+7) reg[i] = (i-D_M0) & 7; if(i >= D_X0 && i <= D_X0+15) { reg[i] = (i-D_X0) & 7; if(i >= D_X0+8) regrex[i] = Rxr | Rxx | Rxb; } if(i >= D_CR+8 && i <= D_CR+15) regrex[i] = Rxr; } zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; zprg.mode = 64; pcstr = "%.6llux "; nuxiinit(); histgen = 0; textp = P; datap = P; edatap = P; pc = 0; dtype = 4; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s", outfile); errorexit(); } version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else if(!(*INITENTRY >= '0' && *INITENTRY <= '9')) lookup(INITENTRY, 0)->type = SXREF; while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) errorexit(); if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = 0; INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void main(int argc, char *argv[]) { linkarchinit(); ctxt = linknew(thelinkarch); ctxt->thechar = thechar; ctxt->thestring = thestring; ctxt->diag = diag; ctxt->bso = &bso; Binit(&bso, 1, OWRITE); listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; linkmode = LinkAuto; nuxiinit(); if(thechar == '5' && ctxt->goarm == 5) debug['F'] = 1; flagcount("1", "use alternate profiling code", &debug['1']); if(thechar == '6') flagcount("8", "assume 64-bit addresses", &debug['8']); flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo); flagint64("D", "addr: data address", &INITDAT); flagstr("E", "sym: entry symbol", &INITENTRY); if(thechar == '5') flagcount("G", "debug pseudo-ops", &debug['G']); flagfn1("I", "interp: set ELF interp", setinterp); flagfn1("L", "dir: add dir to library path", Lflag); flagfn1("H", "head: header type", setheadtype); flagcount("K", "add stack underflow checks", &debug['K']); if(thechar == '5') flagcount("M", "disable software div/mod", &debug['M']); flagcount("O", "print pc-line tables", &debug['O']); flagcount("Q", "debug byte-register code gen", &debug['Q']); if(thechar == '5') flagcount("P", "debug code generation", &debug['P']); flagint32("R", "rnd: address rounding", &INITRND); flagcount("S", "check type signatures", &debug['S']); flagint64("T", "addr: text address", &INITTEXT); flagfn0("V", "print version and exit", doversion); flagcount("W", "disassemble input", &debug['W']); flagfn2("X", "name value: define string data", addstrdata); flagcount("Z", "clear stack frame on entry", &debug['Z']); flagcount("a", "disassemble output", &debug['a']); flagcount("c", "dump call graph", &debug['c']); flagcount("d", "disable dynamic executable", &debug['d']); flagstr("extld", "linker to run in external mode", &extld); flagstr("extldflags", "flags for external linker", &extldflags); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix); flagstr("k", "sym: set field tracking symbol", &tracksym); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagcount("n", "dump symbol table", &debug['n']); flagstr("o", "outfile: set output file", &outfile); flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); flagcount("race", "enable race detector", &flag_race); flagcount("s", "disable symbol table", &debug['s']); if(thechar == '5' || thechar == '6') flagcount("shared", "generate shared object (implies -linkmode external)", &flag_shared); flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); flagcount("u", "reject unsafe packages", &debug['u']); flagcount("v", "print link trace", &debug['v']); flagcount("w", "disable DWARF generation", &debug['w']); flagparse(&argc, &argv, usage); ctxt->bso = &bso; ctxt->debugdivmod = debug['M']; ctxt->debugfloat = debug['F']; ctxt->debughist = debug['O']; ctxt->debugpcln = debug['O']; ctxt->debugread = debug['W']; ctxt->debugstack = debug['K']; ctxt->debugvlog = debug['v']; if(argc != 1) usage(); if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = smprint("%c.out.exe", thechar); else outfile = smprint("%c.out", thechar); } libinit(); // creates outfile if(HEADTYPE == -1) HEADTYPE = headtype(goos); ctxt->headtype = HEADTYPE; if (headstring == nil) headstring = headstr(HEADTYPE); archinit(); ctxt->debugfloat = debug['F']; if(debug['v']) Bprint(&bso, "HEADER = -H%d -T0x%llux -D0x%llux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath(ctxt, "command line", "command line", argv[0], "main"); loadlib(); if(thechar == '5') { // mark some functions that are only referenced after linker code editing if(debug['F']) mark(linkrlookup(ctxt, "_sfloat", 0)); mark(linklookup(ctxt, "runtime.read_tls_fallback", 0)); } deadcode(); callgraph(); paramspace = "SP"; /* (FP) now (SP) on output */ doelf(); if(HEADTYPE == Hdarwin) domacho(); dostkcheck(); if(HEADTYPE == Hwindows) dope(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); hostlink(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", ctxt->nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Addr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); Bprint(&bso, "%lld liveness data\n", liveness); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { int c; char *a; char name[LIBNAMELEN]; Binit(&bso, 1, OWRITE); cout = -1; listinit(); outfile = 0; nerrors = 0; curtext = P; HEADTYPE = -1; INITTEXT = -1; INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'L': addlibpath(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'P': a = ARGF(); if(a) INITTEXTP = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) usage(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; a = getenv("ccroot"); if(a != nil && *a != '\0') { if(!fileexists(a)) { diag("nonexistent $ccroot: %s", a); errorexit(); } }else a = ""; snprint(name, sizeof(name), "%s/%s/lib", a, thestring); addlibpath(name); r0iszero = debug['0'] == 0; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 0; if(debug['B']) HEADTYPE = 1; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* boot */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0x200000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096L; break; case 1: /* plan 9 q.out */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 2: /* plan 9 */ HEADR = 32L+8L; if(INITTEXT == -1) INITTEXT = 0x100000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x100000; break; case 3: /* raw */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) { INITDAT = 0; INITRND = 4; } if(INITRND == -1) INITRND = 0; break; case 5: /* elf executable */ HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0x00400000L+HEADR; if(INITDAT == -1) INITDAT = 0x10000000; if(INITRND == -1) INITRND = 0; break; case 9: /* ELF64 executable */ case 10: HEADR = rnd(Ehdr64sz+3*Phdr64sz, 16); if(INITTEXT == -1) INITTEXT = 0x100000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x100000; break; } if (INITTEXTP == -1) INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%x -T0x%llux -D0x%llux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.from3 = zprg.from; zprg.to = zprg.from; buildop(); histgen = 0; textp = P; datap = P; pc = 0; dtype = 4; if(outfile == 0) outfile = "9.out"; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else { /* * It's possibly a number handed in by -En (this is * the test made by entryvalue() when creating the appropriate * header). Calling lookup() on that will create the symbol 'n' * printing an undef() diagnostic later. */ a = INITENTRY; if(!(*a >= '0' && *a <= '9')) lookup(INITENTRY, 0)->type = SXREF; } while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) goto out; if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = 0; INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void main(int argc, char *argv[]) { char *p; Sym *s; Binit(&bso, 1, OWRITE); listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; linkmode = LinkAuto; nuxiinit(); p = getgoarm(); if(p != nil) goarm = atoi(p); else goarm = 6; if(goarm == 5) debug['F'] = 1; flagcount("1", "use alternate profiling code", &debug['1']); flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo); flagstr("E", "sym: entry symbol", &INITENTRY); flagint32("D", "addr: data address", &INITDAT); flagcount("G", "debug pseudo-ops", &debug['G']); flagfn1("I", "interp: set ELF interp", setinterp); flagfn1("L", "dir: add dir to library path", Lflag); flagfn1("H", "head: header type", setheadtype); flagcount("K", "add stack underflow checks", &debug['K']); flagcount("M", "disable software div/mod", &debug['M']); flagcount("O", "print pc-line tables", &debug['O']); flagcount("P", "debug code generation", &debug['P']); flagint32("R", "rnd: address rounding", &INITRND); flagint32("T", "addr: text address", &INITTEXT); flagfn0("V", "print version and exit", doversion); flagcount("W", "disassemble input", &debug['W']); flagfn2("X", "name value: define string data", addstrdata); flagcount("Z", "clear stack frame on entry", &debug['Z']); flagcount("a", "disassemble output", &debug['a']); flagcount("c", "dump call graph", &debug['c']); flagcount("d", "disable dynamic executable", &debug['d']); flagstr("extld", "linker to run in external mode", &extld); flagstr("extldflags", "flags for external linker", &extldflags); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); flagstr("k", "sym: set field tracking symbol", &tracksym); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagcount("n", "dump symbol table", &debug['n']); flagstr("o", "outfile: set output file", &outfile); flagcount("p", "insert profiling code", &debug['p']); flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); flagcount("race", "enable race detector", &flag_race); flagcount("s", "disable symbol table", &debug['s']); flagcount("shared", "generate shared object (implies -linkmode external)", &flag_shared); flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); flagcount("u", "reject unsafe packages", &debug['u']); flagcount("v", "print link trace", &debug['v']); flagcount("w", "disable DWARF generation", &debug['w']); flagparse(&argc, &argv, usage); if(argc != 1) usage(); if(flag_shared) linkmode = LinkExternal; mywhatsys(); if(HEADTYPE == -1) HEADTYPE = headtype(goos); // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // Go was built; see ../../make.bash. if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0) linkmode = LinkInternal; switch(HEADTYPE) { default: if(linkmode == LinkAuto) linkmode = LinkInternal; if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0) sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE)); break; case Hlinux: break; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ case Hfreebsd: case Hnetbsd: debug['d'] = 0; // with dynamic linking tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m // this number is known to ../../pkg/runtime/rt0_*_arm.s elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); // embed goarm to runtime.goarm s = lookup("runtime.goarm", 0); s->dupok = 1; adduint8(s, goarm); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing if(debug['F']) mark(rlookup("_sfloat", 0)); mark(lookup("runtime.read_tls_fallback", 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); // 5l -Z means zero the stack frame on entry. // This slows down function calls but can help avoid // false positives in garbage collection. if(debug['Z']) dozerostk(); noops(); // generate stack split prolog, handle div/mod, etc. dostkcheck(); span(); addexport(); // textaddress() functionality is handled in span() pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); hostlink(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { int c; char *a; Binit(&bso, 1, OWRITE); cout = -1; listinit(); outfile = 0; nerrors = 0; curtext = P; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) { diag("usage: ql [-options] objects"); errorexit(); } if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; r0iszero = debug['0'] == 0; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 0; if(debug['B']) HEADTYPE = 1; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* boot */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0x200000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096L; break; case 1: /* Be boot format (PEF) */ HEADR = 208L; if(INITTEXT == -1) INITTEXT = 0x100000; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 2: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0x100020; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x100000; break; case 3: /* raw */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) { INITDAT = 0; INITRND = 4; } if(INITRND == -1) INITRND = 0; break; case 4: /* aix unix xcoff executable */ HEADR = 20L+72L+3*40L; if(INITTEXT == -1) INITTEXT = 0x1000000L+HEADR; if(INITDAT == -1) INITDAT = 0x20000000; if(INITRND == -1) INITRND = 0; break; case 5: /* elf executable */ case 6: /* elf for virtex 4 */ HEADR = rnd(52L+3*32L, 16); if(INITTEXT == -1) INITTEXT = 0x00400000L+HEADR; if(INITDAT == -1) INITDAT = 0x10000000; if(INITRND == -1) INITRND = 0; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%x -T0x%lux -D0x%lux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.from3 = zprg.from; zprg.to = zprg.from; buildop(); histgen = 0; textp = P; datap = P; pc = 0; dtype = 4; if(outfile == 0) outfile = "q.out"; cout = create(outfile, 1, 0775); if(cout < 0) { diag("%s: cannot create", outfile); errorexit(); } nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else lookup(INITENTRY, 0)->type = SXREF; while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) goto out; if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void main(int argc, char *argv[]) { int c, i; char *p; Binit(&bso, 1, OWRITE); cout = -1; listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; p = getenv("GOARM"); if(p != nil && strcmp(p, "5") == 0) debug['F'] = 1; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'I': interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = Hnoheader; if(debug['B']) HEADTYPE = Hrisc; if(debug['9']) HEADTYPE = Hplan9x32; HEADTYPE = Hlinux; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hnetbsd: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ debug['d'] = 1; // no dynamic linking elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing // TODO(kaib): this doesn't work, the prog can't be found in runtime for(i=0; i<nelem(linkername); i++) mark(lookup(linkername[i], 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); noops(); dostkcheck(); span(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { Binit(&bso, 1, OWRITE); listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; LIBINITENTRY = 0; linkmode = LinkInternal; // TODO: LinkAuto once everything works. nuxiinit(); flagcount("1", "use alternate profiling code", &debug['1']); flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo); flagstr("E", "sym: entry symbol", &INITENTRY); flagint32("D", "addr: data address", &INITDAT); flagfn1("I", "interp: set ELF interp", setinterp); flagfn1("L", "dir: add dir to library path", Lflag); flagfn1("H", "head: header type", setheadtype); flagcount("K", "add stack underflow checks", &debug['K']); flagcount("O", "print pc-line tables", &debug['O']); flagcount("Q", "debug byte-register code gen", &debug['Q']); flagint32("R", "rnd: address rounding", &INITRND); flagcount("S", "check type signatures", &debug['S']); flagint32("T", "addr: text address", &INITTEXT); flagfn0("V", "print version and exit", doversion); flagcount("W", "disassemble input", &debug['W']); flagfn2("X", "name value: define string data", addstrdata); flagcount("Z", "clear stack frame on entry", &debug['Z']); flagcount("a", "disassemble output", &debug['a']); flagcount("c", "dump call graph", &debug['c']); flagcount("d", "disable dynamic executable", &debug['d']); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagstr("k", "sym: set field tracking symbol", &tracksym); flagstr("o", "outfile: set output file", &outfile); flagcount("p", "insert profiling code", &debug['p']); flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); flagcount("race", "enable race detector", &flag_race); flagcount("s", "disable symbol table", &debug['s']); flagcount("n", "dump symbol table", &debug['n']); flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); flagcount("u", "reject unsafe packages", &debug['u']); flagcount("v", "print link trace", &debug['v']); flagcount("w", "disable DWARF generation", &debug['w']); // TODO: link mode flag flagparse(&argc, &argv, usage); if(argc != 1) usage(); mywhatsys(); // get goos if(HEADTYPE == -1) HEADTYPE = headtype(goos); switch(HEADTYPE) { default: if(linkmode == LinkAuto) linkmode = LinkInternal; if(linkmode == LinkExternal) sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE)); break; case Hdarwin: case Hfreebsd: case Hlinux: case Hnetbsd: case Hopenbsd: break; } if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = "8.out.exe"; else outfile = "8.out"; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hgarbunix: /* this is garbage */ HEADR = 20L+56L; if(INITTEXT == -1) INITTEXT = 0x40004CL; if(INITDAT == -1) INITDAT = 0x10000000L; if(INITRND == -1) INITRND = 0; break; case Hunixcoff: /* is unix coff */ HEADR = 0xd0L; if(INITTEXT == -1) INITTEXT = 0xd0; if(INITDAT == -1) INITDAT = 0x400000; if(INITRND == -1) INITRND = 0; break; case Hplan9x32: /* plan 9 */ tlsoffset = -8; HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+32; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hmsdoscom: /* MS-DOS .COM */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hmsdosexe: /* fake MS-DOS .EXE */ HEADR = 0x200; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; HEADR += (INITTEXT & 0xFFFF); if(debug['v']) Bprint(&bso, "HEADR = 0x%d\n", HEADR); break; case Hdarwin: /* apple MACH */ /* * OS X system constant - offset from %gs to our TLS. * Explained in ../../pkg/runtime/cgo/gcc_darwin_386.c. */ tlsoffset = 0x468; machoinit(); HEADR = INITIAL_MACHO_HEADR; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hlinux: /* elf32 executable */ case Hfreebsd: case Hnetbsd: case Hopenbsd: /* * ELF uses TLS offsets negative from %gs. * Translate 0(GS) and 4(GS) into -8(GS) and -4(GS). * Also known to ../../pkg/runtime/sys_linux_386.s * and ../../pkg/runtime/cgo/gcc_linux_386.c. */ tlsoffset = -8; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x08048000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hwindows: /* PE executable */ peinit(); HEADR = PEFILEHEADR; if(INITTEXT == -1) INITTEXT = PEBASE+PESECTHEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = PESECTALIGN; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); instinit(); zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; pcstr = "%.6ux "; histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); deadcode(); patch(); follow(); doelf(); if(HEADTYPE == Hdarwin) domacho(); if(HEADTYPE == Hwindows) dope(); dostkoff(); dostkcheck(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); span(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); hostlink(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { int c, i; Binit(&bso, 1, OWRITE); cout = -1; listinit(); nerrors = 0; curtext = P; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = atolwhex(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = 0; if(debug['B']) HEADTYPE = 1; if(debug['9']) HEADTYPE = 2; HEADTYPE = 6; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 1: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 2: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 3: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 4: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 5: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case 6: /* arm elf */ debug['d'] = 1; // no dynamic linking elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x8000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%lux -D0x%lux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); thumbbuildop(); // could build on demand histgen = 0; textp = P; datap = P; edatap = P; pc = 0; dtype = 4; nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing // TODO(kaib): this doesn't work, the prog can't be found in runtime for(i=0; i<nelem(linkername); i++) mark(lookup(linkername[i], 0)); deadcode(); firstp = firstp->link; if(firstp == P) goto out; if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ initdiv(); import(); HEADTYPE = 2; INITTEXT = INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } else divsig(); export();
Link* linknew(LinkArch *arch) { Link *ctxt; char *p; char buf[1024]; nuxiinit(); ctxt = emallocz(sizeof *ctxt); ctxt->arch = arch; ctxt->version = HistVersion; ctxt->goroot = getgoroot(); ctxt->goroot_final = getenv("GOROOT_FINAL"); if(ctxt->goroot_final != nil && ctxt->goroot_final[0] == '\0') ctxt->goroot_final = nil; p = getgoarch(); if(strcmp(p, arch->name) != 0) sysfatal("invalid goarch %s (want %s)", p, arch->name); if(getwd(buf, sizeof buf) == 0) strcpy(buf, "/???"); if(yy_isalpha(buf[0]) && buf[1] == ':') { // On Windows. ctxt->windows = 1; // Canonicalize path by converting \ to / (Windows accepts both). for(p=buf; *p; p++) if(*p == '\\') *p = '/'; } ctxt->pathname = strdup(buf); ctxt->headtype = headtype(getgoos()); if(ctxt->headtype < 0) sysfatal("unknown goos %s", getgoos()); // Record thread-local storage offset. // TODO(rsc): Move tlsoffset back into the linker. switch(ctxt->headtype) { default: sysfatal("unknown thread-local storage offset for %s", headstr(ctxt->headtype)); case Hplan9: ctxt->tlsoffset = -2*ctxt->arch->ptrsize; break; case Hwindows: break; case Hlinux: case Hfreebsd: case Hnetbsd: case Hopenbsd: case Hdragonfly: case Hsolaris: /* * ELF uses TLS offset negative from FS. * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS). * Known to low-level assembly in package runtime and runtime/cgo. */ ctxt->tlsoffset = -2*ctxt->arch->ptrsize; break; case Hnacl: switch(ctxt->arch->thechar) { default: sysfatal("unknown thread-local storage offset for nacl/%s", ctxt->arch->name); case '6': ctxt->tlsoffset = 0; break; case '8': ctxt->tlsoffset = -8; break; } break; case Hdarwin: /* * OS X system constants - offset from 0(GS) to our TLS. * Explained in ../../pkg/runtime/cgo/gcc_darwin_*.c. */ switch(ctxt->arch->thechar) { default: sysfatal("unknown thread-local storage offset for darwin/%s", ctxt->arch->name); case '6': ctxt->tlsoffset = 0x8a0; break; case '8': ctxt->tlsoffset = 0x468; break; } break; } // On arm, record goarm. if(ctxt->arch->thechar == '5') { p = getgoarm(); if(p != nil) ctxt->goarm = atoi(p); else ctxt->goarm = 6; } return ctxt; }
void main(int argc, char *argv[]) { int i, c; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'H': HEADTYPE = atolwhex(EARGF(usage())); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND if(argc != 1) usage(); mywhatsys(); // get goos if(HEADTYPE == -1) { HEADTYPE = 2; if(strcmp(goos, "linux") == 0) HEADTYPE = 7; else if(strcmp(goos, "darwin") == 0) HEADTYPE = 6; else if(strcmp(goos, "nacl") == 0) HEADTYPE = 8; else if(strcmp(goos, "freebsd") == 0) HEADTYPE = 9; else if(strcmp(goos, "mingw") == 0) HEADTYPE = 10; else if(strcmp(goos, "pchw") == 0) HEADTYPE = 11; else print("goos is not known: %s\n", goos); } if(outfile == nil) { if(HEADTYPE == 10) outfile = "8.out.exe"; else outfile = "8.out"; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 0: /* this is garbage */ HEADR = 20L+56L; if(INITTEXT == -1) INITTEXT = 0x40004CL; if(INITDAT == -1) INITDAT = 0x10000000L; if(INITRND == -1) INITRND = 0; break; case 1: /* is unix coff */ HEADR = 0xd0L; if(INITTEXT == -1) INITTEXT = 0xd0; if(INITDAT == -1) INITDAT = 0x400000; if(INITRND == -1) INITRND = 0; break; case 2: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+32; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 3: /* MS-DOS .COM */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case 4: /* fake MS-DOS .EXE */ HEADR = 0x200; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; HEADR += (INITTEXT & 0xFFFF); if(debug['v']) Bprint(&bso, "HEADR = 0x%ld\n", HEADR); break; case 6: /* apple MACH */ /* * OS X system constant - offset from %gs to our TLS. * Explained in ../../libcgo/darwin_386.c. */ tlsoffset = 0x468; machoinit(); HEADR = MACHORESERVE; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 7: /* elf32 executable */ case 9: /* * Linux ELF uses TLS offsets negative from %gs. * Translate 0(GS) and 4(GS) into -8(GS) and -4(GS). * Also known to ../../pkg/runtime/linux/386/sys.s * and ../../libcgo/linux_386.c. */ tlsoffset = -8; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x08048000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 8: /* native client elf32 executable */ elfinit(); HEADR = 4096; if(INITTEXT == -1) INITTEXT = 0x20000; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 10: /* PE executable */ peinit(); HEADR = PERESERVE; if(INITTEXT == -1) INITTEXT = PEBASE+0x1000; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = PEALIGN; break; case 11: tlsoffset = 0; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x100000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%ld -T0x%lux -D0x%lux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); for(i=1; optab[i].as; i++) if(i != optab[i].as) { diag("phase error in optab: %d", i); errorexit(); } maxop = i; for(i=0; i<Ymax; i++) ycover[i*Ymax + i] = 1; ycover[Yi0*Ymax + Yi8] = 1; ycover[Yi1*Ymax + Yi8] = 1; ycover[Yi0*Ymax + Yi32] = 1; ycover[Yi1*Ymax + Yi32] = 1; ycover[Yi8*Ymax + Yi32] = 1; ycover[Yal*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrb] = 1; ycover[Ycx*Ymax + Yrb] = 1; ycover[Yrx*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrx] = 1; ycover[Ycx*Ymax + Yrx] = 1; ycover[Yax*Ymax + Yrl] = 1; ycover[Ycx*Ymax + Yrl] = 1; ycover[Yrx*Ymax + Yrl] = 1; ycover[Yf0*Ymax + Yrf] = 1; ycover[Yal*Ymax + Ymb] = 1; ycover[Ycl*Ymax + Ymb] = 1; ycover[Yax*Ymax + Ymb] = 1; ycover[Ycx*Ymax + Ymb] = 1; ycover[Yrx*Ymax + Ymb] = 1; ycover[Yrb*Ymax + Ymb] = 1; ycover[Ym*Ymax + Ymb] = 1; ycover[Yax*Ymax + Yml] = 1; ycover[Ycx*Ymax + Yml] = 1; ycover[Yrx*Ymax + Yml] = 1; ycover[Yrl*Ymax + Yml] = 1; ycover[Ym*Ymax + Yml] = 1; for(i=0; i<D_NONE; i++) { reg[i] = -1; if(i >= D_AL && i <= D_BH) reg[i] = (i-D_AL) & 7; if(i >= D_AX && i <= D_DI) reg[i] = (i-D_AX) & 7; if(i >= D_F0 && i <= D_F0+7) reg[i] = (i-D_F0) & 7; } zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; pcstr = "%.6lux "; nuxiinit(); histgen = 0; textp = P; datap = P; edatap = P; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; addlibpath("command line", "command line", argv[0], "main"); loadlib(); deadcode(); firstp = firstp->link; if(firstp == P) errorexit(); if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void main(int argc, char *argv[]) { int c; char *name, *val; Binit(&bso, 1, OWRITE); listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; nuxiinit(); ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); break; case 'I': debug['I'] = 1; // denote cmdline interpreter override interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); case 'X': name = EARGF(usage()); val = EARGF(usage()); addstrdata(name, val); break; case 'B': val = EARGF(usage()); addbuildinfo(val); break; } ARGEND if(argc != 1) usage(); mywhatsys(); // get goos if(HEADTYPE == -1) HEADTYPE = headtype(goos); if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = "6.out.exe"; else outfile = "6.out"; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hplan9x64: /* plan 9 */ HEADR = 32L + 8L; if(INITTEXT == -1) INITTEXT = 0x200000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x200000; break; case Helf: /* elf32 executable */ HEADR = rnd(52L+3*32L, 16); if(INITTEXT == -1) INITTEXT = 0x80110000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hdarwin: /* apple MACH */ /* * OS X system constant - offset from 0(GS) to our TLS. * Explained in ../../pkg/runtime/cgo/gcc_darwin_amd64.c. */ tlsoffset = 0x8a0; machoinit(); HEADR = INITIAL_MACHO_HEADR; if(INITRND == -1) INITRND = 4096; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; break; case Hlinux: /* elf64 executable */ case Hfreebsd: /* freebsd */ case Hnetbsd: /* netbsd */ case Hopenbsd: /* openbsd */ /* * ELF uses TLS offset negative from FS. * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS). * Also known to ../../pkg/runtime/sys_linux_amd64.s * and ../../pkg/runtime/cgo/gcc_linux_amd64.c. */ tlsoffset = -16; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = (1<<22)+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hwindows: /* PE executable */ peinit(); HEADR = PEFILEHEADR; if(INITTEXT == -1) INITTEXT = PEBASE+PESECTHEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = PESECTALIGN; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H%d -T0x%llux -D0x%llux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); instinit(); zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; zprg.mode = 64; pcstr = "%.6llux "; histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); deadcode(); patch(); follow(); doelf(); if(HEADTYPE == Hdarwin) domacho(); dostkoff(); dostkcheck(); paramspace = "SP"; /* (FP) now (SP) on output */ if(debug['p']) if(debug['1']) doprof1(); else doprof2(); span(); if(HEADTYPE == Hwindows) dope(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }