summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/8g/ggen.c12
-rw-r--r--src/cmd/8l/asm.c48
-rw-r--r--src/cmd/8l/l.h1
-rw-r--r--src/cmd/8l/obj.c7
-rw-r--r--src/cmd/8l/span.c2
-rwxr-xr-xsrc/cmd/gotest/gotest6
6 files changed, 57 insertions, 19 deletions
diff --git a/src/cmd/8g/ggen.c b/src/cmd/8g/ggen.c
index c1cad74be..110446a0d 100644
--- a/src/cmd/8g/ggen.c
+++ b/src/cmd/8g/ggen.c
@@ -8,6 +8,7 @@
#include "opt.h"
static Prog *pret;
+static Node *naclnop;
void
compile(Node *fn)
@@ -23,6 +24,7 @@ compile(Node *fn)
newproc = sysfunc("newproc");
deferproc = sysfunc("deferproc");
deferreturn = sysfunc("deferreturn");
+ naclnop = sysfunc("naclnop");
panicindex = sysfunc("panicindex");
panicslice = sysfunc("panicslice");
throwreturn = sysfunc("throwreturn");
@@ -95,8 +97,16 @@ compile(Node *fn)
gclean();
if(nerrors != 0)
goto ret;
- if(hasdefer)
+ if(hasdefer) {
+ // On Native client, insert call to no-op function
+ // to force alignment immediately before call to deferreturn,
+ // so that when jmpdefer subtracts 5 from the second CALL's
+ // return address and then the return masks off the low bits,
+ // we'll back up to the NOPs immediately after the dummy CALL.
+ if(strcmp(getgoos(), "nacl") == 0)
+ ginscall(naclnop, 0);
ginscall(deferreturn, 0);
+ }
pc->as = ARET; // overwrite AEND
pc->lineno = lineno;
diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c
index 4e8c0560d..0fca6fa0f 100644
--- a/src/cmd/8l/asm.c
+++ b/src/cmd/8l/asm.c
@@ -226,8 +226,11 @@ addsize(Sym *s, Sym *t)
vlong
datoff(vlong addr)
{
- if(addr >= INITDAT)
+ if(addr >= INITDAT) {
+ if(HEADTYPE == 8)
+ return addr - INITDAT + rnd(HEADR+textsize, 4096);
return addr - INITDAT + rnd(HEADR+textsize, INITRND);
+ }
diag("datoff %#llx", addr);
return 0;
}
@@ -548,6 +551,14 @@ asmb(void)
}
cflush();
break;
+ case 8:
+ // Native Client only needs to round
+ // text segment file address to 4096 bytes,
+ // but text segment memory address rounds
+ // to INITRND (65536).
+ v = rnd(HEADR+textsize, 4096);
+ seek(cout, v, 0);
+ break;
Elfseek:
case 10:
v = rnd(HEADR+textsize, INITRND);
@@ -829,15 +840,25 @@ asmb(void)
ph = newElfPhdr();
ph->type = PT_LOAD;
ph->flags = PF_X+PF_R;
- ph->vaddr = va - fo;
- ph->paddr = va - fo;
- ph->off = 0;
- ph->filesz = w + fo;
- ph->memsz = w + fo;
+ if(HEADTYPE != 8) { // Include header, but not on Native Client.
+ va -= fo;
+ w += fo;
+ fo = 0;
+ }
+ ph->vaddr = va;
+ ph->paddr = va;
+ ph->off = fo;
+ ph->filesz = w;
+ ph->memsz = INITDAT - va;
ph->align = INITRND;
- fo = rnd(fo+w, INITRND);
- va = rnd(va+w, INITRND);
+ // NaCl text segment file address rounds to 4096;
+ // only memory address rounds to INITRND.
+ if(HEADTYPE == 8)
+ fo = rnd(fo+w, 4096);
+ else
+ fo = rnd(fo+w, INITRND);
+ va = INITDAT;
w = datsize;
ph = newElfPhdr();
@@ -941,7 +962,7 @@ asmb(void)
ph->flags = PF_W+PF_R;
ph->align = 4;
- fo = ELFRESERVE;
+ fo = HEADR;
va = startva + fo;
w = textsize;
@@ -953,7 +974,12 @@ asmb(void)
sh->size = w;
sh->addralign = 4;
- fo = rnd(fo+w, INITRND);
+ // NaCl text segment file address rounds to 4096;
+ // only memory address rounds to INITRND.
+ if(HEADTYPE == 8)
+ fo = rnd(fo+w, 4096);
+ else
+ fo = rnd(fo+w, INITRND);
va = rnd(va+w, INITRND);
w = datsize;
@@ -1013,7 +1039,7 @@ asmb(void)
switch(HEADTYPE) {
case 8:
eh->ident[EI_OSABI] = ELFOSABI_NACL;
- eh->ident[EI_ABIVERSION] = 6;
+ eh->ident[EI_ABIVERSION] = 7;
eh->flags = 0x200000; // aligned mod 32
break;
case 9:
diff --git a/src/cmd/8l/l.h b/src/cmd/8l/l.h
index 8f02bdefd..5b0f30723 100644
--- a/src/cmd/8l/l.h
+++ b/src/cmd/8l/l.h
@@ -302,6 +302,7 @@ EXTERN Sym* symlist;
EXTERN int32 symsize;
EXTERN Prog* textp;
EXTERN int32 textsize;
+EXTERN int32 textpad;
EXTERN int version;
EXTERN Prog zprg;
EXTERN int dtype;
diff --git a/src/cmd/8l/obj.c b/src/cmd/8l/obj.c
index cd7984d71..82f4e47b7 100644
--- a/src/cmd/8l/obj.c
+++ b/src/cmd/8l/obj.c
@@ -280,7 +280,12 @@ main(int argc, char *argv[])
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
- INITRND = 4096;
+ INITRND = 65536;
+
+ // 512 kB of address space for closures.
+ // (Doesn't take any space in the binary file.)
+ // Closures are 64 bytes each, so this is 8,192 closures.
+ textpad = 512*1024;
break;
case 10: /* PE executable */
peinit();
diff --git a/src/cmd/8l/span.c b/src/cmd/8l/span.c
index f649777ec..0245d72b9 100644
--- a/src/cmd/8l/span.c
+++ b/src/cmd/8l/span.c
@@ -108,7 +108,7 @@ start:
}while(again);
if(INITRND) {
- INITDAT = rnd(c, INITRND);
+ INITDAT = rnd(c+textpad, INITRND);
if(INITDAT != idat) {
idat = INITDAT;
goto start;
diff --git a/src/cmd/gotest/gotest b/src/cmd/gotest/gotest
index 3fca81b6a..0a0aafc34 100755
--- a/src/cmd/gotest/gotest
+++ b/src/cmd/gotest/gotest
@@ -29,11 +29,7 @@ if [ -z "$O" ]; then
exit 2
fi
-E=""
-case "$GOOS" in
-nacl)
- E="nacl"
-esac
+E="$GORUN"
# TODO(kaib): proper emulator strategy
case x"$GOARCH" in