Skip to content

Commit db2a06a

Browse files
aykevldeadprogram
authored andcommitted
internal/abi: implement initial version of this package
This package can never be a full version as seen in upstream Go, because TinyGo is very different. But it is necessary to define so that no code can accidentally use this package (now or in the future). It currently defines: - NoEscape which is needed by strings.Builder since Go 1.23. - FuncPCABI* which is needed by internal/syscall/unix on MacOS.
1 parent 560fd0a commit db2a06a

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

compiler/symbol.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
139139
// On *nix systems, the "abort" functuion in libc is used to handle fatal panics.
140140
// Mark it as noreturn so LLVM can optimize away code.
141141
llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("noreturn"), 0))
142+
case "internal/abi.NoEscape":
143+
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
142144
case "runtime.alloc":
143145
// Tell the optimizer that runtime.alloc is an allocator, meaning that it
144146
// returns values that are never null and never alias to an existing value.

loader/goroot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
236236
"device/": false,
237237
"examples/": false,
238238
"internal/": true,
239+
"internal/abi/": false,
239240
"internal/binary/": false,
240241
"internal/bytealg/": false,
241242
"internal/cm/": false,

src/internal/abi/abi.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package abi exposes low-level details of the Go compiler/runtime
2+
package abi

src/internal/abi/escape.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package abi
2+
3+
import "unsafe"
4+
5+
// Tell the compiler the given pointer doesn't escape.
6+
// The compiler knows about this function and will give the nocapture parameter
7+
// attribute.
8+
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
9+
return p
10+
}

src/internal/abi/funcpc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package abi
2+
3+
// These two signatures are present to satisfy the expectation of some programs
4+
// (in particular internal/syscall/unix on MacOS). They do not currently have an
5+
// implementation, in part because TinyGo doesn't use ABI0 or ABIInternal (it
6+
// uses a C-like calling convention).
7+
8+
func FuncPCABI0(f interface{}) uintptr
9+
10+
func FuncPCABIInternal(f interface{}) uintptr

0 commit comments

Comments
 (0)