summaryrefslogtreecommitdiff
path: root/src/liblink
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-12 00:18:20 -0400
committerRuss Cox <rsc@golang.org>2014-09-12 00:18:20 -0400
commit01cc50951b57fd695075fa8a7e53025cf6115da0 (patch)
tree470703fc67a92851fd65b76afa1e16a390a2ee59 /src/liblink
parenta6669fa5e7d26c7e5f9d61a389450d2c1ef79f1c (diff)
downloadgo-01cc50951b57fd695075fa8a7e53025cf6115da0.tar.gz
cmd/gc: turn Go prototypes into ptr liveness maps for assembly functions
The goal here is to allow assembly functions to appear in the middle of a Go stack (having called other code) and still record enough information about their pointers so that stack copying and garbage collection can handle them precisely. Today, these frames are handled only conservatively. If you write func myfunc(x *float64) (y *int) (with no body, an 'extern' declaration), then the Go compiler now emits a liveness bitmap for use from the assembly definition of myfunc. The bitmap symbol is myfunc.args_stackmap and it contains two bitmaps. The first bitmap, in effect at function entry, marks all inputs as live. The second bitmap, not in effect at function entry, marks the outputs live as well. In funcdata.h, define new assembly macros: GO_ARGS opts in to using the Go compiler-generated liveness bitmap for the current function. GO_RESULTS_INITIALIZED indicates that the results have been initialized and need to be kept live for the remainder of the function; it causes a switch to the second generated bitmap for the assembly code that follows. NO_LOCAL_POINTERS indicates that there are no pointers in the local variables being stored in the function's stack frame. LGTM=khr R=khr CC=golang-codereviews https://codereview.appspot.com/137520043
Diffstat (limited to 'src/liblink')
-rw-r--r--src/liblink/objfile.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/liblink/objfile.c b/src/liblink/objfile.c
index dc463d474..02cfae495 100644
--- a/src/liblink/objfile.c
+++ b/src/liblink/objfile.c
@@ -103,6 +103,7 @@
#include <bio.h>
#include <link.h>
#include "../cmd/ld/textflag.h"
+#include "../runtime/funcdata.h"
static void writesym(Link*, Biobuf*, LSym*);
static void wrint(Biobuf*, int64);
@@ -232,6 +233,17 @@ writeobj(Link *ctxt, Biobuf *b)
continue;
}
+ if(p->as == ctxt->arch->AFUNCDATA) {
+ // Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
+ if(curtext == nil) // func _() {}
+ continue;
+ if(strcmp(p->to.sym->name, "go_args_stackmap") == 0) {
+ if(p->from.type != ctxt->arch->D_CONST || p->from.offset != FUNCDATA_ArgsPointerMaps)
+ ctxt->diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps");
+ p->to.sym = linklookup(ctxt, smprint("%s.args_stackmap", curtext->name), curtext->version);
+ }
+ }
+
if(curtext == nil)
continue;
s = curtext;