FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
6g/6c: Add flag to support position independent code generation in the
6g/6c
compilers.

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://codereview.appspot.com/6926049
https://codereview.appspot.com/6822078

Please review this at https://codereview.appspot.com/7064048/

Affected files:
M src/cmd/6c/sgen.c
M src/cmd/6g/cgen.c
M src/cmd/6g/ggen.c
M src/cmd/6g/gsubr.c
M src/cmd/cc/cc.h
M src/cmd/cc/lex.c
M src/cmd/gc/go.h
M src/cmd/gc/lex.c
M src/make.bash


Index: src/cmd/6c/sgen.c
===================================================================
--- a/src/cmd/6c/sgen.c
+++ b/src/cmd/6c/sgen.c
@@ -126,7 +126,10 @@
break;

case ONAME:
- n->addable = 10;
+ if(flag_pic)
+ n->addable = 9;
+ else
+ n->addable = 10;
if(n->class == CPARAM || n->class == CAUTO)
n->addable = 11;
break;
Index: src/cmd/6g/cgen.c
===================================================================
--- a/src/cmd/6g/cgen.c
+++ b/src/cmd/6g/cgen.c
@@ -737,8 +737,12 @@
regalloc(&n3, types[tptr], res);
p1 = gins(ALEAQ, N, &n3);
datastring(nl->val.u.sval->s, nl->val.u.sval->len, &p1->from);
- p1->from.scale = 1;
- p1->from.index = n2.val.u.reg;
+ if(flag_pic) {
+ gins(AADDQ, &n2, &n3);
+ } else {
+ p1->from.scale = 1;
+ p1->from.index = n2.val.u.reg;
+ }
goto indexdone;
}

Index: src/cmd/6g/ggen.c
===================================================================
--- a/src/cmd/6g/ggen.c
+++ b/src/cmd/6g/ggen.c
@@ -59,6 +59,7 @@
{
Prog *p;
Node reg, con;
+ Node r1;

switch(proc) {
default:
@@ -76,7 +77,14 @@
case 1: // call in new proc (go)
case 2: // deferred call (defer)
nodreg(&reg, types[TINT64], D_CX);
- gins(APUSHQ, f, N);
+ if(flag_pic) {
+ regalloc(&r1, f->type, f);
+ gmove(f, &r1);
+ gins(APUSHQ, &r1, N);
+ regfree(&r1);
+ } else {
+ gins(APUSHQ, f, N);
+ }
nodconst(&con, types[TINT32], argsize(f->type));
gins(APUSHQ, &con, N);
if(proc == 1)
Index: src/cmd/6g/gsubr.c
===================================================================
--- a/src/cmd/6g/gsubr.c
+++ b/src/cmd/6g/gsubr.c
@@ -554,6 +554,10 @@
case ONAME:
case OPARAM:
return 1;
+ case OADDR:
+ if(flag_pic)
+ return 1;
+ break;
}
return 0;
}
Index: src/cmd/cc/cc.h
===================================================================
--- a/src/cmd/cc/cc.h
+++ b/src/cmd/cc/cc.h
@@ -527,6 +527,7 @@
EXTERN int fproundflg;
EXTERN int textflag;
EXTERN int dataflag;
+EXTERN int flag_pic;
EXTERN int ncontin;
EXTERN int canreach;
EXTERN int warnreach;
Index: src/cmd/cc/lex.c
===================================================================
--- a/src/cmd/cc/lex.c
+++ b/src/cmd/cc/lex.c
@@ -174,6 +174,8 @@
flagcount("t", "debug code generation", &debug['t']);
flagcount("w", "enable warnings", &debug['w']);
flagcount("v", "increase debug verbosity", &debug['v']);
+ if(thechar == '6')
+ flagcount("pic", "generate position independent code", &flag_pic);

flagparse(&argc, &argv, usage);

Index: src/cmd/gc/go.h
===================================================================
--- a/src/cmd/gc/go.h
+++ b/src/cmd/gc/go.h
@@ -940,6 +940,7 @@
EXTERN int compiling_wrappers;
EXTERN int pure_go;
EXTERN int flag_race;
+EXTERN int flag_pic;

EXTERN int nointerface;
EXTERN int fieldtrack_enabled;
Index: src/cmd/gc/lex.c
===================================================================
--- a/src/cmd/gc/lex.c
+++ b/src/cmd/gc/lex.c
@@ -258,6 +258,8 @@
flagcount("w", "debug type checking", &debug['w']);
flagcount("x", "debug lexer", &debug['x']);
flagcount("y", "debug declarations in canned imports (with -d)",
&debug['y']);
+ if(thechar == '6')
+ flagcount("pic", "generate position independent code", &flag_pic);

flagparse(&argc, &argv, usage);

Index: src/make.bash
===================================================================
--- a/src/make.bash
+++ b/src/make.bash
@@ -23,6 +23,9 @@
# GO_LDFLAGS: Additional 5l/6l/8l arguments to use when
# building the commands.
#
+# GO_CCFLAGS: Additional 5c/6c/8c arguments to use when
+# building.
+#
# CGO_ENABLED: Controls cgo usage during the build. Set it to 1
# to include all cgo related files, .c and .go file with "cgo"
# build directive, in the build. Set it to 0 to ignore them.
@@ -129,12 +132,12 @@
if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
echo "# Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH."
GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \
- "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS"
-ldflags "$GO_LDFLAGS" -v std
+ "$GOTOOLDIR"/go_bootstrap install -ccflags "$GO_CCFLAGS"
-gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
echo
fi

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

rm -f "$GOTOOLDIR"/go_bootstrap

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedJan 7, '13 at 9:39p
activeJan 7, '13 at 9:39p
posts1
users1
websitegolang.org

1 user in discussion

Elias Naur: 1 post

People

Translate

site design / logo © 2021 Grokbase