Skip to content

Commit d9c6ae6

Browse files
committed
all: final merge of NaCl tree
This CL replays the following one CL from the rsc-go13nacl repo. This is the last replay CL: after this CL the main repo will have everything the rsc-go13nacl repo did. Changes made to the main repo after the rsc-go13nacl repo branched off probably mean that NaCl doesn't actually work after this CL, but all the code is now moved over and just needs to be redebugged. --- cmd/6l, cmd/8l, cmd/ld: support for Native Client See golang.org/s/go13nacl for design overview. This CL is publicly visible but not CC'ed to golang-dev, to avoid distracting from the preparation of the Go 1.2 release. This CL and the others will be checked into my rsc-go13nacl clone repo for now, and I will send CLs against the main repo early in the Go 1.3 development. R≡khr https://golang.org/cl/15750044 --- LGTM=bradfitz, dave, iant R=dave, bradfitz, iant CC=golang-codereviews https://golang.org/cl/69040044
1 parent 8d2465a commit d9c6ae6

File tree

25 files changed

+633
-115
lines changed

25 files changed

+633
-115
lines changed

include/link.h

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct Prog
108108
char ft; /* 6l, 8l oclass cache */
109109
char tt; // 6l, 8l
110110
uchar optab; // 5l
111+
uchar isize; // 6l, 8l
111112

112113
char width; /* fake for DATA */
113114
char mode; /* 16, 32, or 64 in 6l, 8l; internal use in 5g, 6g, 8g */
@@ -363,6 +364,9 @@ struct Link
363364
Prog* blitrl;
364365
Prog* elitrl;
365366
int rexflag;
367+
int rep; // for nacl
368+
int repn; // for nacl
369+
int lock; // for nacl
366370
int asmode;
367371
uchar* andptr;
368372
uchar and[100];
@@ -412,6 +416,7 @@ struct LinkArch
412416

413417
int minlc;
414418
int ptrsize;
419+
int regsize;
415420

416421
// TODO: Give these the same values on all systems.
417422
int D_ADDR;
@@ -447,6 +452,7 @@ enum {
447452
Helf,
448453
Hfreebsd,
449454
Hlinux,
455+
Hnacl,
450456
Hnetbsd,
451457
Hopenbsd,
452458
Hplan9,
@@ -563,6 +569,7 @@ extern char* anames8[];
563569

564570
extern LinkArch link386;
565571
extern LinkArch linkamd64;
572+
extern LinkArch linkamd64p32;
566573
extern LinkArch linkarm;
567574

568575
#pragma varargck type "A" int

src/cmd/5l/l.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum
3939
thechar = '5',
4040
PtrSize = 4,
4141
IntSize = 4,
42+
RegSize = 4,
4243
MaxAlign = 8, // max data alignment
4344
FuncAlign = 4 // single-instruction alignment
4445
};

src/cmd/5l/obj.c

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
char *thestring = "arm";
4040
LinkArch *thelinkarch = &linkarm;
4141

42+
void
43+
linkarchinit(void)
44+
{
45+
}
46+
4247
void
4348
archinit(void)
4449
{
@@ -76,6 +81,7 @@ archinit(void)
7681
case Hlinux: /* arm elf */
7782
case Hfreebsd:
7883
case Hnetbsd:
84+
case Hnacl:
7985
debug['d'] = 0; // with dynamic linking
8086
elfinit();
8187
HEADR = ELFRESERVE;

src/cmd/6l/asm.c

+3
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ asmb(void)
661661
case Hsolaris:
662662
debug['8'] = 1; /* 64-bit addresses */
663663
break;
664+
case Hnacl:
664665
case Hwindows:
665666
break;
666667
}
@@ -689,6 +690,7 @@ asmb(void)
689690
case Hopenbsd:
690691
case Hdragonfly:
691692
case Hsolaris:
693+
case Hnacl:
692694
symo = rnd(HEADR+segtext.len, INITRND)+rnd(segrodata.len, INITRND)+segdata.filelen;
693695
symo = rnd(symo, INITRND);
694696
break;
@@ -770,6 +772,7 @@ asmb(void)
770772
case Hopenbsd:
771773
case Hdragonfly:
772774
case Hsolaris:
775+
case Hnacl:
773776
asmbelf(symo);
774777
break;
775778
case Hwindows:

src/cmd/6l/l.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
enum
4242
{
4343
thechar = '6',
44-
PtrSize = 8,
45-
IntSize = 8,
4644
MaxAlign = 32, // max data alignment
4745

4846
// Loop alignment constants:
@@ -64,6 +62,10 @@ enum
6462
FuncAlign = 16
6563
};
6664

65+
EXTERN int PtrSize;
66+
EXTERN int IntSize;
67+
EXTERN int RegSize;
68+
6769
#define P ((Prog*)0)
6870
#define S ((LSym*)0)
6971
#define TNAME (ctxt->cursym?ctxt->cursym->name:noname)

src/cmd/6l/obj.c

+24
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
char* thestring = "amd64";
4242
LinkArch* thelinkarch = &linkamd64;
4343

44+
void
45+
linkarchinit(void)
46+
{
47+
if(strcmp(getgoarch(), "amd64p32") == 0)
48+
thelinkarch = &linkamd64p32;
49+
PtrSize = thelinkarch->ptrsize;
50+
IntSize = PtrSize;
51+
RegSize = thelinkarch->regsize;
52+
}
53+
4454
void
4555
archinit(void)
4656
{
@@ -63,6 +73,7 @@ archinit(void)
6373
case Hdragonfly:
6474
case Hfreebsd:
6575
case Hlinux:
76+
case Hnacl:
6677
case Hnetbsd:
6778
case Hopenbsd:
6879
case Hsolaris:
@@ -117,6 +128,18 @@ archinit(void)
117128
if(INITRND == -1)
118129
INITRND = 4096;
119130
break;
131+
case Hnacl:
132+
elfinit();
133+
debug['w']++; // disable dwarf, which gets confused and is useless anyway
134+
HEADR = 0x10000;
135+
funcalign = 32;
136+
if(INITTEXT == -1)
137+
INITTEXT = 0x20000;
138+
if(INITDAT == -1)
139+
INITDAT = 0;
140+
if(INITRND == -1)
141+
INITRND = 0x10000;
142+
break;
120143
case Hwindows: /* PE executable */
121144
peinit();
122145
HEADR = PEFILEHEADR;
@@ -128,6 +151,7 @@ archinit(void)
128151
INITRND = PESECTALIGN;
129152
break;
130153
}
154+
131155
if(INITDAT != 0 && INITRND != 0)
132156
print("warning: -D0x%llux is ignored because of -R0x%ux\n",
133157
INITDAT, INITRND);

src/cmd/8l/asm.c

+1
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ asmb(void)
696696
case Hnetbsd:
697697
case Hopenbsd:
698698
case Hdragonfly:
699+
case Hnacl:
699700
asmbelf(symo);
700701
break;
701702
case Hwindows:

src/cmd/8l/l.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum
4343
thechar = '8',
4444
PtrSize = 4,
4545
IntSize = 4,
46+
RegSize = 4,
4647
MaxAlign = 32, // max data alignment
4748
FuncAlign = 16
4849
};

src/cmd/8l/obj.c

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
char* thestring = "386";
4242
LinkArch* thelinkarch = &link386;
4343

44+
void
45+
linkarchinit(void)
46+
{
47+
}
48+
4449
void
4550
archinit(void)
4651
{
@@ -104,6 +109,19 @@ archinit(void)
104109
if(INITRND == -1)
105110
INITRND = 4096;
106111
break;
112+
113+
case Hnacl:
114+
elfinit();
115+
HEADR = 0x10000;
116+
funcalign = 32;
117+
if(INITTEXT == -1)
118+
INITTEXT = 0x20000;
119+
if(INITDAT == -1)
120+
INITDAT = 0;
121+
if(INITRND == -1)
122+
INITRND = 0x10000;
123+
break;
124+
107125
case Hwindows: /* PE executable */
108126
peinit();
109127
HEADR = PEFILEHEADR;

src/cmd/gc/doc.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ Flags:
5252
add dir1 and dir2 to the list of paths to check for imported packages
5353
-N
5454
disable optimizations
55+
-nolocalimports
56+
disallow local (relative) imports
5557
-S
5658
write assembly language text to standard output (code only)
5759
-S -S
5860
write assembly language text to standard output (code and data)
5961
-u
60-
disallow importing packages not marked as safe
62+
disallow importing packages not marked as safe; implies -nolocalimports
6163
-V
6264
print the compiler version
6365
-race

src/cmd/ld/data.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ textaddress(void)
10471047
// Could parallelize, by assigning to text
10481048
// and then letting threads copy down, but probably not worth it.
10491049
sect = segtext.sect;
1050-
sect->align = FuncAlign;
1050+
sect->align = funcalign;
10511051
linklookup(ctxt, "text", 0)->sect = sect;
10521052
linklookup(ctxt, "etext", 0)->sect = sect;
10531053
va = INITTEXT;
@@ -1058,6 +1058,8 @@ textaddress(void)
10581058
continue;
10591059
if(sym->align != 0)
10601060
va = rnd(va, sym->align);
1061+
else
1062+
va = rnd(va, funcalign);
10611063
sym->value = 0;
10621064
for(sub = sym; sub != S; sub = sub->sub)
10631065
sub->value += va;
@@ -1083,13 +1085,14 @@ address(void)
10831085
segtext.vaddr = va;
10841086
segtext.fileoff = HEADR;
10851087
for(s=segtext.sect; s != nil; s=s->next) {
1086-
//print("%s at %#llux + %#llux\n", s->name, va, (vlong)s->len);
10871088
va = rnd(va, s->align);
10881089
s->vaddr = va;
10891090
va += s->len;
10901091
}
10911092
segtext.len = va - INITTEXT;
10921093
segtext.filelen = segtext.len;
1094+
if(HEADTYPE == Hnacl)
1095+
va += 32; // room for the "halt sled"
10931096

10941097
if(segrodata.sect != nil) {
10951098
// align to page boundary so as not to mix

0 commit comments

Comments
 (0)