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[]) { 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 *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[]) { 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, 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(); }
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 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(); }