Commit 7d443bb6 authored by Russ Cox's avatar Russ Cox

make 8l generate Darwin Mach-O and Linux ELF binaries

R=ken
OCL=26584
CL=26589
parent 997b6f9d
This diff is collapsed.
...@@ -365,11 +365,19 @@ void span(void); ...@@ -365,11 +365,19 @@ void span(void);
void undef(void); void undef(void);
void undefsym(Sym*); void undefsym(Sym*);
int32 vaddr(Adr*); int32 vaddr(Adr*);
void wputb(ushort); void wput(ushort);
void xdefine(char*, int, int32); void xdefine(char*, int, int32);
void xfol(Prog*); void xfol(Prog*);
int zaddr(uchar*, Adr*, Sym*[]); int zaddr(uchar*, Adr*, Sym*[]);
void zerosig(char*); void zerosig(char*);
uint32 machheadr(void);
uint32 elfheadr(void);
void whatsys(void);
/* set by call to whatsys() */
extern char* goroot;
extern char* goarch;
extern char* goos;
#pragma varargck type "D" Adr* #pragma varargck type "D" Adr*
#pragma varargck type "P" Prog* #pragma varargck type "P" Prog*
......
...@@ -139,16 +139,22 @@ main(int argc, char *argv[]) ...@@ -139,16 +139,22 @@ main(int argc, char *argv[])
diag("usage: 8l [-options] objects"); diag("usage: 8l [-options] objects");
errorexit(); errorexit();
} }
if(!debug['9'] && !debug['U'] && !debug['B'])
debug[DEFAULT] = 1; whatsys(); // get goroot, goarch, goos
if(strcmp(goarch, thestring) != 0)
print("goarch is not known: %s\n", goarch);
if(HEADTYPE == -1) { if(HEADTYPE == -1) {
if(debug['U']) HEADTYPE = 2;
HEADTYPE = 1; if(strcmp(goos, "linux") == 0)
if(debug['B']) HEADTYPE = 7;
HEADTYPE = 2; else
if(debug['9']) if(strcmp(goos, "darwin") == 0)
HEADTYPE = 2; HEADTYPE = 6;
else
print("goos is not known: %sn", goos);
} }
switch(HEADTYPE) { switch(HEADTYPE) {
default: default:
diag("unknown -H option"); diag("unknown -H option");
...@@ -202,6 +208,24 @@ main(int argc, char *argv[]) ...@@ -202,6 +208,24 @@ main(int argc, char *argv[])
if(debug['v']) if(debug['v'])
Bprint(&bso, "HEADR = 0x%ld\n", HEADR); Bprint(&bso, "HEADR = 0x%ld\n", HEADR);
break; break;
case 6: /* apple MACH */
HEADR = machheadr();
if(INITTEXT == -1)
INITTEXT = 4096+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case 7: /* elf32 executable */
HEADR = elfheadr();
if(INITTEXT == -1)
INITTEXT = 0x08048000+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
} }
if(INITDAT != 0 && INITRND != 0) if(INITDAT != 0 && INITRND != 0)
print("warning: -D0x%lux is ignored because of -R0x%lux\n", print("warning: -D0x%lux is ignored because of -R0x%lux\n",
...@@ -294,19 +318,27 @@ main(int argc, char *argv[]) ...@@ -294,19 +318,27 @@ main(int argc, char *argv[])
firstp = prg(); firstp = prg();
lastp = firstp; lastp = firstp;
if(INITENTRY == 0) { if(INITENTRY == nil) {
INITENTRY = "_main"; INITENTRY = mal(strlen(goarch)+strlen(goos)+10);
if(debug['p']) sprint(INITENTRY, "_rt0_%s_%s", goarch, goos);
INITENTRY = "_mainp"; }
if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF;
lookup(INITENTRY, 0)->type = SXREF;
} else if(!debug['l']) {
lookup(INITENTRY, 0)->type = SXREF; a = mal(strlen(goroot)+strlen(goarch)+strlen(goos)+20);
sprint(a, "%s/lib/rt0_%s_%s.%c", goroot, goarch, goos, thechar);
objfile(a);
}
while(*argv) while(*argv)
objfile(*argv++); objfile(*argv++);
if(!debug['l'])
if(!debug['l']) {
loadlib(); loadlib();
a = mal(strlen(goroot)+strlen(goarch)+strlen(goos)+20);
sprint(a, "%s/lib/lib_%s_%s.a", goroot, goarch, goos);
objfile(a);
}
firstp = firstp->link; firstp = firstp->link;
if(firstp == P) if(firstp == P)
errorexit(); errorexit();
......
...@@ -1396,7 +1396,7 @@ asmdyn() ...@@ -1396,7 +1396,7 @@ asmdyn()
t++; t++;
} }
else if(c == 1){ else if(c == 1){
wputb(ra); wput(ra);
t += 2; t += 2;
} }
else{ else{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment