diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2014-12-31 00:25:39 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2014-12-31 00:25:39 +0000 |
commit | d34d92fb9c316a9ccd82989cd89b67143cf3fb8d (patch) | |
tree | bec6cddb914b62d626e359eb2d79376eb58df754 /llgo/irgen/compiler.go | |
parent | a0a53085e1909c18af8e77c4eb02d8448c7314ca (diff) | |
download | bcm5719-llvm-d34d92fb9c316a9ccd82989cd89b67143cf3fb8d.tar.gz bcm5719-llvm-d34d92fb9c316a9ccd82989cd89b67143cf3fb8d.zip |
irgen: modify the ABI to use init guards instead of priority
The new ABI is simpler for use cases such as dynamically loaded packages.
The calling convention for import functions is similar to what go/ssa would
produce if BareInits were cleared. However, simply clearing this flag causes
two additional issues:
1) We would need to special case the 'init$guard' variable (see
discussion in https://codereview.appspot.com/78780043/).
2) The call to __go_register_gc_roots needs to appear in the right
place, i.e. after the guard check. Making this check appear
in the right place with non-bare inits seems unreliable at best.
So we keep BareInits set and generate the necessary code manually.
It is still possible to get the old ABI by specifying a path to a gccgo
installation.
Differential Revision: http://reviews.llvm.org/D6804
llvm-svn: 225030
Diffstat (limited to 'llgo/irgen/compiler.go')
-rw-r--r-- | llgo/irgen/compiler.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/llgo/irgen/compiler.go b/llgo/irgen/compiler.go index 60bd62f7196..16c3988ba7b 100644 --- a/llgo/irgen/compiler.go +++ b/llgo/irgen/compiler.go @@ -75,6 +75,9 @@ type CompilerOptions struct { // path in ImportPaths. GccgoPath string + // Whether to use the gccgo ABI. + GccgoABI bool + // ImportPaths is the list of additional import paths ImportPaths []string @@ -322,8 +325,6 @@ func (c *compiler) buildPackageInitData(mainPkg *ssa.Package) gccgoimporter.Init } func (c *compiler) createInitMainFunction(mainPkg *ssa.Package) { - initdata := c.buildPackageInitData(mainPkg) - ftyp := llvm.FunctionType(llvm.VoidType(), nil, false) initMain := llvm.AddFunction(c.module.Module, "__go_init_main", ftyp) c.addCommonFunctionAttrs(initMain) @@ -333,6 +334,17 @@ func (c *compiler) createInitMainFunction(mainPkg *ssa.Package) { defer builder.Dispose() builder.SetInsertPointAtEnd(entry) + if !c.GccgoABI { + initfn := c.module.Module.NamedFunction("main..import") + if !initfn.IsNil() { + builder.CreateCall(initfn, nil, "") + } + builder.CreateRetVoid() + return + } + + initdata := c.buildPackageInitData(mainPkg) + for _, init := range initdata.Inits { initfn := c.module.Module.NamedFunction(init.InitFunc) if initfn.IsNil() { @@ -348,8 +360,13 @@ func (c *compiler) buildExportData(mainPkg *ssa.Package) []byte { exportData := importer.ExportData(mainPkg.Object) b := bytes.NewBuffer(exportData) + b.WriteString("v1;\n") + if !c.GccgoABI { + return b.Bytes() + } + initdata := c.buildPackageInitData(mainPkg) - b.WriteString("v1;\npriority ") + b.WriteString("priority ") b.WriteString(strconv.Itoa(initdata.Priority)) b.WriteString(";\n") |