Commit 6a659ebf authored by Ken Thompson's avatar Ken Thompson

new elf header

SVN=121737
parent 3086910f
...@@ -175,6 +175,10 @@ cgen(Node *n, Node *res) ...@@ -175,6 +175,10 @@ cgen(Node *n, Node *res)
case OMOD: case OMOD:
case ODIV: case ODIV:
if(isfloat[n->type->etype]) {
a = optoas(n->op, nl->type);
goto abop;
}
cgen_div(n->op, nl, nr, res); cgen_div(n->op, nl, nr, res);
break; break;
......
...@@ -173,10 +173,6 @@ asmb(void) ...@@ -173,10 +173,6 @@ asmb(void)
case 5: case 5:
seek(cout, HEADR+textsize, 0); seek(cout, HEADR+textsize, 0);
break; break;
case 7:
v = rnd(HEADR+textsize, INITRND);
seek(cout, v, 0);
break;
case 6: case 6:
v = HEADR+textsize; v = HEADR+textsize;
myseek(cout, v); myseek(cout, v);
...@@ -187,6 +183,10 @@ asmb(void) ...@@ -187,6 +183,10 @@ asmb(void)
} }
cflush(); cflush();
break; break;
case 7:
v = rnd(HEADR+textsize, INITRND);
seek(cout, v, 0);
break;
} }
if(debug['v']) if(debug['v'])
...@@ -218,9 +218,13 @@ asmb(void) ...@@ -218,9 +218,13 @@ asmb(void)
default: default:
case 2: case 2:
case 5: case 5:
debug['s'] = 1;
seek(cout, HEADR+textsize+datsize, 0);
break;
case 7: case 7:
debug['s'] = 1; debug['s'] = 1;
seek(cout, HEADR+textsize+datsize, 0); seek(cout, HEADR+textsize+datsize, 0);
linuxstrtable();
break; break;
case 6: case 6:
debug['s'] = 1; debug['s'] = 1;
...@@ -239,12 +243,13 @@ debug['s'] = 1; ...@@ -239,12 +243,13 @@ debug['s'] = 1;
if(dlm) if(dlm)
asmdyn(); asmdyn();
cflush(); cflush();
} } else
else if(dlm){ if(dlm){
seek(cout, HEADR+textsize+datsize, 0); seek(cout, HEADR+textsize+datsize, 0);
asmdyn(); asmdyn();
cflush(); cflush();
} }
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f headr\n", cputime()); Bprint(&bso, "%5.2f headr\n", cputime());
Bflush(&bso); Bflush(&bso);
...@@ -383,47 +388,122 @@ debug['s'] = 1; ...@@ -383,47 +388,122 @@ debug['s'] = 1;
cput(1); /* version = CURRENT */ cput(1); /* version = CURRENT */
strnput("", 9); strnput("", 9);
/*10*/ wputl(2); /* type = EXEC */ wputl(2); /* type = EXEC */
wputl(62); /* machine = AMD64 */ wputl(62); /* machine = AMD64 */
lputl(1L); /* version = CURRENT */ lputl(1L); /* version = CURRENT */
/*18*/ llputl(entryvalue()); /* entry vaddr */ llputl(entryvalue()); /* entry vaddr */
llputl(64L); /* offset to first phdr */ llputl(64L); /* offset to first phdr */
llputl(0L); /* offset to first shdr */ llputl(64L+56*3); /* offset to first shdr */
/*30*/ lputl(0L); /* processor specific flags */ lputl(0L); /* processor specific flags */
wputl(64); /* Ehdr size */ wputl(64); /* Ehdr size */
wputl(56); /* Phdr size */ wputl(56); /* Phdr size */
wputl(2); /* # of Phdrs */ wputl(3); /* # of Phdrs */
wputl(64); /* Shdr size */ wputl(64); /* Shdr size */
wputl(0); /* # of Shdrs */ wputl(5); /* # of Shdrs */
wputl(0); /* Shdr string size */ wputl(4); /* Shdr with strings */
lputl(1L); /* text - type = PT_LOAD */ linuxphdr(1, /* text - type = PT_LOAD */
lputl(1L+4L); /* text - flags = PF_X+PF_R */ 1L+4L, /* text - flags = PF_X+PF_R */
llputl(HEADR); /* file offset */ HEADR, /* file offset */
llputl(INITTEXT); /* vaddr */ INITTEXT, /* vaddr */
llputl(INITTEXT); /* paddr */ INITTEXT, /* paddr */
llputl(textsize); /* file size */ textsize, /* file size */
llputl(textsize); /* memory size */ textsize, /* memory size */
llputl(INITRND); /* alignment */ INITRND); /* alignment */
lputl(1L); /* data - type = PT_LOAD */
lputl(1L+2L+4L); /* text - flags = PF_X+PF_W+PF_R */
v = rnd(HEADR+textsize, INITRND); v = rnd(HEADR+textsize, INITRND);
llputl(v); /* file offset */ linuxphdr(1, /* data - type = PT_LOAD */
llputl(INITDAT); /* vaddr */ 1L+2L+4L, /* data - flags = PF_X+PF_W+PF_R */
llputl(INITDAT); /* paddr */ v, /* file offset */
llputl(datsize); /* file size */ INITDAT, /* vaddr */
llputl(datsize+bsssize); /* memory size */ INITDAT, /* paddr */
llputl(INITRND); /* alignment */ datsize, /* file size */
datsize+bsssize, /* memory size */
// lputl(0L); /* data - type = PT_NULL */ INITRND); /* alignment */
// lputl(4L); /* ro - flags = PF_R */
// llputl(HEADR+textsize+datsize); /* file offset */ linuxphdr(0x6474e551, /* gok - type = gok */
// llputl(0L); 1L+2L+4L, /* gok - flags = PF_X+PF_R */
// llputl(0L); 0, /* file offset */
// llputl(symsize); /* symbol table size */ 0, /* vaddr */
// llputl(lcsize); /* line number size */ 0, /* paddr */
// llputl(0x04L); /* alignment */ 0, /* file size */
0, /* memory size */
8); /* alignment */
linuxshdr(nil, /* name */
0, /* type */
0, /* flags */
0, /* addr */
0, /* off */
0, /* size */
0, /* link */
0, /* info */
0, /* align */
0); /* entsize */
stroffset = 1;
v = HEADR;
linuxshdr(".text", /* name */
1, /* type */
6, /* flags */
INITTEXT, /* addr */
v, /* off */
textsize, /* size */
0, /* link */
0, /* info */
4, /* align */
0); /* entsize */
v += textsize;
linuxshdr(".data", /* name */
1, /* type */
3, /* flags */
INITDAT, /* addr */
v, /* off */
datsize, /* size */
0, /* link */
0, /* info */
4, /* align */
0); /* entsize */
v += datsize;
linuxshdr(".bss", /* name */
8, /* type */
3, /* flags */
INITDAT, /* addr */
v, /* off */
bsssize, /* size */
0, /* link */
0, /* info */
4, /* align */
0); /* entsize */
v += 0;
va = stroffset +
strlen(".shstrtab")+1 +
strlen(".gosymtab")+1;
linuxshdr(".shstrtab", /* name */
3, /* type */
0, /* flags */
0, /* addr */
v, /* off */
va, /* size */
0, /* link */
0, /* info */
4, /* align */
0); /* entsize */
v += va;
linuxshdr(".gosymtab", /* name */
2, /* type */
0, /* flags */
0, /* addr */
v, /* off */
0, /* size */
0, /* link */
0, /* info */
4, /* align */
0); /* entsize */
break; break;
} }
cflush(); cflush();
...@@ -678,3 +758,79 @@ machheadr(void) ...@@ -678,3 +758,79 @@ machheadr(void)
return a*4; return a*4;
} }
ulong
linuxheadr(void)
{
ulong a;
a = 64; /* a.out header */
a += 56; /* page zero seg */
a += 56; /* text seg */
a += 56; /* stack seg */
a += 64; /* nil sect */
a += 64; /* .text sect */
a += 64; /* .data seg */
a += 64; /* .bss sect */
a += 64; /* .shstrtab sect - strings for headers */
a += 64; /* .gosymtab sect */
return a;
}
void
linuxphdr(int type, int flags, vlong foff,
vlong vaddr, vlong paddr,
vlong filesize, vlong memsize, vlong align)
{
lputl(type); /* text - type = PT_LOAD */
lputl(flags); /* text - flags = PF_X+PF_R */
llputl(foff); /* file offset */
llputl(vaddr); /* vaddr */
llputl(paddr); /* paddr */
llputl(filesize); /* file size */
llputl(memsize); /* memory size */
llputl(align); /* alignment */
}
void
linuxshdr(char *name, ulong type, vlong flags, vlong addr, vlong off,
vlong size, ulong link, ulong info, vlong align, vlong entsize)
{
lputl(stroffset);
lputl(type);
llputl(flags);
llputl(addr);
llputl(off);
llputl(size);
lputl(link);
lputl(info);
llputl(align);
llputl(entsize);
if(name != nil)
stroffset += strlen(name)+1;
}
void
linuxstrtable(void)
{
char *name;
name = "";
strnput(name, strlen(name)+1);
name = ".text";
strnput(name, strlen(name)+1);
name = ".data";
strnput(name, strlen(name)+1);
name = ".bss";
strnput(name, strlen(name)+1);
name = ".shstrtab";
strnput(name, strlen(name)+1);
name = ".gosymtab";
strnput(name, strlen(name)+1);
}
...@@ -344,6 +344,7 @@ EXTERN int imports, nimports; ...@@ -344,6 +344,7 @@ EXTERN int imports, nimports;
EXTERN int exports, nexports; EXTERN int exports, nexports;
EXTERN char* EXPTAB; EXTERN char* EXPTAB;
EXTERN Prog undefp; EXTERN Prog undefp;
EXTERN ulong stroffset;
#define UP (&undefp) #define UP (&undefp)
...@@ -424,6 +425,15 @@ void machsect(char*, char*, vlong, vlong, ulong, ulong, ulong, ulong, ulong); ...@@ -424,6 +425,15 @@ void machsect(char*, char*, vlong, vlong, ulong, ulong, ulong, ulong, ulong);
void machstack(vlong); void machstack(vlong);
ulong machheadr(void); ulong machheadr(void);
ulong linuxheadr(void);
void linuxphdr(int type, int flags, vlong foff,
vlong vaddr, vlong paddr,
vlong filesize, vlong memsize, vlong align);
void linuxshdr(char *name, ulong type, vlong flags, vlong addr, vlong off,
vlong size, ulong link, ulong info, vlong align, vlong entsize);
void linuxstrtable(void);
#pragma varargck type "D" Adr* #pragma varargck type "D" Adr*
#pragma varargck type "P" Prog* #pragma varargck type "P" Prog*
#pragma varargck type "R" int #pragma varargck type "R" int
......
...@@ -195,9 +195,9 @@ main(int argc, char *argv[]) ...@@ -195,9 +195,9 @@ main(int argc, char *argv[])
INITRND = 4096; INITRND = 4096;
break; break;
case 7: /* elf64 executable */ case 7: /* elf64 executable */
HEADR = rnd(64L+2*56L, 16); HEADR = linuxheadr();
if(INITTEXT == -1) if(INITTEXT == -1)
INITTEXT = 0x400000L+HEADR; INITTEXT = 4096+HEADR;
if(INITDAT == -1) if(INITDAT == -1)
INITDAT = 0; INITDAT = 0;
if(INITRND == -1) if(INITRND == -1)
......
...@@ -227,7 +227,7 @@ l0: ...@@ -227,7 +227,7 @@ l0:
for(;;) { for(;;) {
if(escchar('"', &escflag, &v)) if(escchar('"', &escflag, &v))
break; break;
if(escflag || v < Runeself) { if(v < Runeself || escflag) {
cp = remal(cp, c1, 1); cp = remal(cp, c1, 1);
cp[c1++] = v; cp[c1++] = v;
} 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