Skip to content

Commit fe14ee5

Browse files
Elias Naurrsc
authored andcommitted
cmd/6c, cmd/6g: add flag to support large-model code generation
Added the -pic flag to 6c and 6g to avoid assembler instructions that cannot use RIP-relative adressing. This is needed to support the -shared mode in 6l. See also: https://golang.org/cl/6926049 https://golang.org/cl/6822078 R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7064048
1 parent b0a29f3 commit fe14ee5

9 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/cmd/6c/sgen.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ xcom(Node *n)
126126
break;
127127

128128
case ONAME:
129-
n->addable = 10;
129+
if(flag_largemodel)
130+
n->addable = 9;
131+
else
132+
n->addable = 10;
130133
if(n->class == CPARAM || n->class == CAUTO)
131134
n->addable = 11;
132135
break;

src/cmd/6g/cgen.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,12 @@ agenr(Node *n, Node *a, Node *res)
737737
regalloc(&n3, types[tptr], res);
738738
p1 = gins(ALEAQ, N, &n3);
739739
datastring(nl->val.u.sval->s, nl->val.u.sval->len, &p1->from);
740-
p1->from.scale = 1;
741-
p1->from.index = n2.val.u.reg;
740+
if(flag_largemodel) {
741+
gins(AADDQ, &n2, &n3);
742+
} else {
743+
p1->from.scale = 1;
744+
p1->from.index = n2.val.u.reg;
745+
}
742746
goto indexdone;
743747
}
744748

src/cmd/6g/ggen.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ginscall(Node *f, int proc)
5959
{
6060
Prog *p;
6161
Node reg, con;
62+
Node r1;
6263

6364
switch(proc) {
6465
default:
@@ -76,7 +77,14 @@ ginscall(Node *f, int proc)
7677
case 1: // call in new proc (go)
7778
case 2: // deferred call (defer)
7879
nodreg(&reg, types[TINT64], D_CX);
79-
gins(APUSHQ, f, N);
80+
if(flag_largemodel) {
81+
regalloc(&r1, f->type, f);
82+
gmove(f, &r1);
83+
gins(APUSHQ, &r1, N);
84+
regfree(&r1);
85+
} else {
86+
gins(APUSHQ, f, N);
87+
}
8088
nodconst(&con, types[TINT32], argsize(f->type));
8189
gins(APUSHQ, &con, N);
8290
if(proc == 1)

src/cmd/6g/gsubr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ ismem(Node *n)
554554
case ONAME:
555555
case OPARAM:
556556
return 1;
557+
case OADDR:
558+
if(flag_largemodel)
559+
return 1;
560+
break;
557561
}
558562
return 0;
559563
}

src/cmd/cc/cc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ EXTERN int packflg;
528528
EXTERN int fproundflg;
529529
EXTERN int textflag;
530530
EXTERN int dataflag;
531+
EXTERN int flag_largemodel;
531532
EXTERN int ncontin;
532533
EXTERN int canreach;
533534
EXTERN int warnreach;

src/cmd/cc/lex.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ main(int argc, char *argv[])
174174
flagcount("t", "debug code generation", &debug['t']);
175175
flagcount("w", "enable warnings", &debug['w']);
176176
flagcount("v", "increase debug verbosity", &debug['v']);
177+
if(thechar == '6')
178+
flagcount("largemodel", "generate code that assumes a large memory model", &flag_largemodel);
177179

178180
flagparse(&argc, &argv, usage);
179181

src/cmd/gc/go.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ EXTERN int compiling_runtime;
941941
EXTERN int compiling_wrappers;
942942
EXTERN int pure_go;
943943
EXTERN int flag_race;
944+
EXTERN int flag_largemodel;
944945

945946
EXTERN int nointerface;
946947
EXTERN int fieldtrack_enabled;

src/cmd/gc/lex.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ main(int argc, char *argv[])
257257
flagcount("w", "debug type checking", &debug['w']);
258258
flagcount("x", "debug lexer", &debug['x']);
259259
flagcount("y", "debug declarations in canned imports (with -d)", &debug['y']);
260+
if(thechar == '6')
261+
flagcount("largemodel", "generate code that assumes a large memory model", &flag_largemodel);
260262

261263
flagparse(&argc, &argv, usage);
262264

src/make.bash

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
# GO_LDFLAGS: Additional 5l/6l/8l arguments to use when
2424
# building the commands.
2525
#
26+
# GO_CCFLAGS: Additional 5c/6c/8c arguments to use when
27+
# building.
28+
#
2629
# CGO_ENABLED: Controls cgo usage during the build. Set it to 1
2730
# to include all cgo related files, .c and .go file with "cgo"
2831
# build directive, in the build. Set it to 0 to ignore them.
@@ -129,12 +132,12 @@ echo
129132
if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
130133
echo "# Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH."
131134
GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \
132-
"$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
135+
"$GOTOOLDIR"/go_bootstrap install -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
133136
echo
134137
fi
135138

136139
echo "# Building packages and commands for $GOOS/$GOARCH."
137-
"$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
140+
"$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
138141
echo
139142

140143
rm -f "$GOTOOLDIR"/go_bootstrap

0 commit comments

Comments
 (0)