From f24a93c51d8b565aedfa6edebd3c638c9125f468 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 9 Jul 2021 14:01:37 +0200 Subject: [PATCH] compiler, runtime: add layout parameter to runtime.alloc This layout parameter is currently always nil and ignored, but will eventually contain a pointer to a memory layout. This commit also adds module verification to the transform tests, as I found out that it didn't (and therefore didn't initially catch all bugs). --- compiler/compiler.go | 6 ++++-- compiler/defer.go | 3 ++- compiler/llvmutil/wordpack.go | 1 + compiler/testdata/basic.ll | 2 +- compiler/testdata/channel.ll | 2 +- compiler/testdata/float.ll | 2 +- compiler/testdata/func.ll | 2 +- compiler/testdata/go1.17.ll | 4 ++-- compiler/testdata/goroutine-cortex-m-qemu.ll | 10 +++++----- compiler/testdata/goroutine-wasm.ll | 10 +++++----- compiler/testdata/interface.ll | 2 +- compiler/testdata/intrinsics-cortex-m-qemu.ll | 2 +- compiler/testdata/intrinsics-wasm.ll | 2 +- compiler/testdata/pointer.ll | 2 +- compiler/testdata/pragma.ll | 2 +- compiler/testdata/slice.ll | 12 ++++++------ compiler/testdata/string.ll | 2 +- interp/testdata/slice-copy.ll | 6 +++--- src/reflect/value.go | 4 ++-- src/runtime/arch_tinygowasm.go | 4 ++-- src/runtime/baremetal.go | 2 +- src/runtime/chan.go | 2 +- src/runtime/gc_conservative.go | 2 +- src/runtime/gc_extalloc.go | 2 +- src/runtime/gc_leaking.go | 2 +- src/runtime/gc_none.go | 2 +- src/runtime/hashmap.go | 4 ++-- src/runtime/slice.go | 2 +- src/runtime/string.go | 8 ++++---- transform/allocs.go | 2 +- transform/coroutines.go | 4 ++-- transform/testdata/allocs.ll | 18 +++++++++--------- transform/testdata/allocs.out.ll | 8 ++++---- transform/testdata/coroutines.ll | 2 +- transform/testdata/coroutines.out.ll | 14 +++++++------- transform/testdata/gc-stackslots.ll | 14 +++++++------- transform/testdata/gc-stackslots.out.ll | 14 +++++++------- transform/transform_test.go | 6 ++++++ 38 files changed, 99 insertions(+), 89 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index afc8eb9d..c42e40c4 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -1524,7 +1524,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { return llvm.Value{}, b.makeError(expr.Pos(), fmt.Sprintf("value is too big (%v bytes)", size)) } sizeValue := llvm.ConstInt(b.uintptrType, size, false) - buf := b.createRuntimeCall("alloc", []llvm.Value{sizeValue}, expr.Comment) + nilPtr := llvm.ConstNull(b.i8ptrType) + buf := b.createRuntimeCall("alloc", []llvm.Value{sizeValue, nilPtr}, expr.Comment) buf = b.CreateBitCast(buf, llvm.PointerType(typ, 0), "") return buf, nil } else { @@ -1736,7 +1737,8 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) { return llvm.Value{}, err } sliceSize := b.CreateBinOp(llvm.Mul, elemSizeValue, sliceCapCast, "makeslice.cap") - slicePtr := b.createRuntimeCall("alloc", []llvm.Value{sliceSize}, "makeslice.buf") + nilPtr := llvm.ConstNull(b.i8ptrType) + slicePtr := b.createRuntimeCall("alloc", []llvm.Value{sliceSize, nilPtr}, "makeslice.buf") slicePtr = b.CreateBitCast(slicePtr, llvm.PointerType(llvmElemType, 0), "makeslice.array") // Extend or truncate if necessary. This is safe as we've already done diff --git a/compiler/defer.go b/compiler/defer.go index 0687f4d1..6edcc142 100644 --- a/compiler/defer.go +++ b/compiler/defer.go @@ -217,7 +217,8 @@ func (b *builder) createDefer(instr *ssa.Defer) { // This may be hit a variable number of times, so use a heap allocation. size := b.targetData.TypeAllocSize(deferFrameType) sizeValue := llvm.ConstInt(b.uintptrType, size, false) - allocCall := b.createRuntimeCall("alloc", []llvm.Value{sizeValue}, "defer.alloc.call") + nilPtr := llvm.ConstNull(b.i8ptrType) + allocCall := b.createRuntimeCall("alloc", []llvm.Value{sizeValue, nilPtr}, "defer.alloc.call") alloca = b.CreateBitCast(allocCall, llvm.PointerType(deferFrameType, 0), "defer.alloc") } if b.NeedsStackObjects { diff --git a/compiler/llvmutil/wordpack.go b/compiler/llvmutil/wordpack.go index 05fc4ee8..e2b6c7d9 100644 --- a/compiler/llvmutil/wordpack.go +++ b/compiler/llvmutil/wordpack.go @@ -97,6 +97,7 @@ func EmitPointerPack(builder llvm.Builder, mod llvm.Module, needsStackObjects bo alloc := mod.NamedFunction("runtime.alloc") packedHeapAlloc := builder.CreateCall(alloc, []llvm.Value{ sizeValue, + llvm.ConstNull(i8ptrType), llvm.Undef(i8ptrType), // unused context parameter llvm.ConstPointerNull(i8ptrType), // coroutine handle }, "") diff --git a/compiler/testdata/basic.ll b/compiler/testdata/basic.ll index 2ac982c9..56baf3a7 100644 --- a/compiler/testdata/basic.ll +++ b/compiler/testdata/basic.ll @@ -6,7 +6,7 @@ target triple = "wasm32-unknown-wasi" %main.kv = type { float } %main.kv.0 = type { i8 } -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll index ffe6bf2d..2d4f1475 100644 --- a/compiler/testdata/channel.ll +++ b/compiler/testdata/channel.ll @@ -9,7 +9,7 @@ target triple = "wasm32-unknown-wasi" %"internal/task.state" = type { i8* } %runtime.chanSelectState = type { %runtime.channel*, i8* } -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/float.ll b/compiler/testdata/float.ll index a83def94..c6964058 100644 --- a/compiler/testdata/float.ll +++ b/compiler/testdata/float.ll @@ -3,7 +3,7 @@ source_filename = "float.go" target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-wasi" -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/func.ll b/compiler/testdata/func.ll index 86345b8d..eeefa43c 100644 --- a/compiler/testdata/func.ll +++ b/compiler/testdata/func.ll @@ -8,7 +8,7 @@ target triple = "wasm32-unknown-wasi" @"reflect/types.funcid:func:{basic:int}{}" = external constant i8 @"main.someFunc$withSignature" = linkonce_odr constant %runtime.funcValueWithSignature { i32 ptrtoint (void (i32, i8*, i8*)* @main.someFunc to i32), i8* @"reflect/types.funcid:func:{basic:int}{}" } -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/go1.17.ll b/compiler/testdata/go1.17.ll index ea758a9d..3e131236 100644 --- a/compiler/testdata/go1.17.ll +++ b/compiler/testdata/go1.17.ll @@ -3,7 +3,7 @@ source_filename = "go1.17.go" target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-wasi" -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { @@ -46,7 +46,7 @@ declare void @runtime.sliceToArrayPointerPanic(i8*, i8*) ; Function Attrs: nounwind define hidden [4 x i32]* @main.SliceToArrayConst(i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %makeslice = call i8* @runtime.alloc(i32 24, i8* undef, i8* null) #0 + %makeslice = call i8* @runtime.alloc(i32 24, i8* null, i8* undef, i8* null) #0 br i1 false, label %slicetoarray.throw, label %slicetoarray.next slicetoarray.throw: ; preds = %entry diff --git a/compiler/testdata/goroutine-cortex-m-qemu.ll b/compiler/testdata/goroutine-cortex-m-qemu.ll index 064a5fd8..efc51861 100644 --- a/compiler/testdata/goroutine-cortex-m-qemu.ll +++ b/compiler/testdata/goroutine-cortex-m-qemu.ll @@ -11,7 +11,7 @@ target triple = "armv7m-unknown-unknown-eabi" @"main.startInterfaceMethod$string" = internal unnamed_addr constant [4 x i8] c"test", align 1 -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { @@ -66,10 +66,10 @@ entry: ; Function Attrs: nounwind define hidden void @main.closureFunctionGoroutine(i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %n = call i8* @runtime.alloc(i32 4, i8* undef, i8* null) #0 + %n = call i8* @runtime.alloc(i32 4, i8* null, i8* undef, i8* null) #0 %0 = bitcast i8* %n to i32* store i32 3, i32* %0, align 4 - %1 = call i8* @runtime.alloc(i32 8, i8* undef, i8* null) #0 + %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef, i8* null) #0 %2 = bitcast i8* %1 to i32* store i32 5, i32* %2, align 4 %3 = getelementptr inbounds i8, i8* %1, i32 4 @@ -107,7 +107,7 @@ declare void @runtime.printint32(i32, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.funcGoroutine(i8* %fn.context, void ()* %fn.funcptr, i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %0 = call i8* @runtime.alloc(i32 12, i8* undef, i8* null) #0 + %0 = call i8* @runtime.alloc(i32 12, i8* null, i8* undef, i8* null) #0 %1 = bitcast i8* %0 to i32* store i32 5, i32* %1, align 4 %2 = getelementptr inbounds i8, i8* %0, i32 4 @@ -163,7 +163,7 @@ declare void @runtime.chanClose(%runtime.channel* dereferenceable_or_null(32), i ; Function Attrs: nounwind define hidden void @main.startInterfaceMethod(i32 %itf.typecode, i8* %itf.value, i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %0 = call i8* @runtime.alloc(i32 16, i8* undef, i8* null) #0 + %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef, i8* null) #0 %1 = bitcast i8* %0 to i8** store i8* %itf.value, i8** %1, align 4 %2 = getelementptr inbounds i8, i8* %0, i32 4 diff --git a/compiler/testdata/goroutine-wasm.ll b/compiler/testdata/goroutine-wasm.ll index ab628148..4a346c11 100644 --- a/compiler/testdata/goroutine-wasm.ll +++ b/compiler/testdata/goroutine-wasm.ll @@ -16,7 +16,7 @@ target triple = "wasm32-unknown-wasi" @"main.closureFunctionGoroutine$1$withSignature" = linkonce_odr constant %runtime.funcValueWithSignature { i32 ptrtoint (void (i32, i8*, i8*)* @"main.closureFunctionGoroutine$1" to i32), i8* @"reflect/types.funcid:func:{basic:int}{}" } @"main.startInterfaceMethod$string" = internal unnamed_addr constant [4 x i8] c"test", align 1 -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { @@ -51,10 +51,10 @@ entry: ; Function Attrs: nounwind define hidden void @main.closureFunctionGoroutine(i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %n = call i8* @runtime.alloc(i32 4, i8* undef, i8* null) #0 + %n = call i8* @runtime.alloc(i32 4, i8* null, i8* undef, i8* null) #0 %0 = bitcast i8* %n to i32* store i32 3, i32* %0, align 4 - %1 = call i8* @runtime.alloc(i32 8, i8* undef, i8* null) #0 + %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef, i8* null) #0 %2 = bitcast i8* %1 to i32* store i32 5, i32* %2, align 4 %3 = getelementptr inbounds i8, i8* %1, i32 4 @@ -80,7 +80,7 @@ declare void @runtime.printint32(i32, i8*, i8*) define hidden void @main.funcGoroutine(i8* %fn.context, i32 %fn.funcptr, i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: %0 = call i32 @runtime.getFuncPtr(i8* %fn.context, i32 %fn.funcptr, i8* nonnull @"reflect/types.funcid:func:{basic:int}{}", i8* undef, i8* null) #0 - %1 = call i8* @runtime.alloc(i32 8, i8* undef, i8* null) #0 + %1 = call i8* @runtime.alloc(i32 8, i8* null, i8* undef, i8* null) #0 %2 = bitcast i8* %1 to i32* store i32 5, i32* %2, align 4 %3 = getelementptr inbounds i8, i8* %1, i32 4 @@ -119,7 +119,7 @@ declare void @runtime.chanClose(%runtime.channel* dereferenceable_or_null(32), i ; Function Attrs: nounwind define hidden void @main.startInterfaceMethod(i32 %itf.typecode, i8* %itf.value, i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %0 = call i8* @runtime.alloc(i32 16, i8* undef, i8* null) #0 + %0 = call i8* @runtime.alloc(i32 16, i8* null, i8* undef, i8* null) #0 %1 = bitcast i8* %0 to i8** store i8* %itf.value, i8** %1, align 4 %2 = getelementptr inbounds i8, i8* %0, i32 4 diff --git a/compiler/testdata/interface.ll b/compiler/testdata/interface.ll index 21d00fdb..f5afb0f3 100644 --- a/compiler/testdata/interface.ll +++ b/compiler/testdata/interface.ll @@ -22,7 +22,7 @@ target triple = "wasm32-unknown-wasi" @"reflect/types.interface:interface{String() string}$interface" = linkonce_odr constant [1 x i8*] [i8* @"reflect/methods.String() string"] @"reflect/types.typeid:basic:int" = external constant i8 -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/intrinsics-cortex-m-qemu.ll b/compiler/testdata/intrinsics-cortex-m-qemu.ll index f5f00e9e..bf767bf9 100644 --- a/compiler/testdata/intrinsics-cortex-m-qemu.ll +++ b/compiler/testdata/intrinsics-cortex-m-qemu.ll @@ -3,7 +3,7 @@ source_filename = "intrinsics.go" target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" target triple = "armv7m-unknown-unknown-eabi" -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/intrinsics-wasm.ll b/compiler/testdata/intrinsics-wasm.ll index 96e1bcb8..bebadb08 100644 --- a/compiler/testdata/intrinsics-wasm.ll +++ b/compiler/testdata/intrinsics-wasm.ll @@ -3,7 +3,7 @@ source_filename = "intrinsics.go" target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-wasi" -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/pointer.ll b/compiler/testdata/pointer.ll index 20dfadf3..4072816b 100644 --- a/compiler/testdata/pointer.ll +++ b/compiler/testdata/pointer.ll @@ -3,7 +3,7 @@ source_filename = "pointer.go" target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-wasi" -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/pragma.ll b/compiler/testdata/pragma.ll index 4d51748e..31fe6236 100644 --- a/compiler/testdata/pragma.ll +++ b/compiler/testdata/pragma.ll @@ -10,7 +10,7 @@ target triple = "wasm32-unknown-wasi" @undefinedGlobalNotInSection = external global i32, align 4 @main.multipleGlobalPragmas = hidden global i32 0, section ".global_section", align 1024 -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll index 234aea33..da257c4c 100644 --- a/compiler/testdata/slice.ll +++ b/compiler/testdata/slice.ll @@ -3,7 +3,7 @@ source_filename = "slice.go" target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-wasi" -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { @@ -44,7 +44,7 @@ declare void @runtime.lookupPanic(i8*, i8*) ; Function Attrs: nounwind define hidden { i32*, i32, i32 } @main.sliceAppendValues(i32* %ints.data, i32 %ints.len, i32 %ints.cap, i8* %context, i8* %parentHandle) unnamed_addr #0 { entry: - %varargs = call i8* @runtime.alloc(i32 12, i8* undef, i8* null) #0 + %varargs = call i8* @runtime.alloc(i32 12, i8* null, i8* undef, i8* null) #0 %0 = bitcast i8* %varargs to i32* store i32 1, i32* %0, align 4 %1 = getelementptr inbounds i8, i8* %varargs, i32 4 @@ -105,7 +105,7 @@ slice.throw: ; preds = %entry unreachable slice.next: ; preds = %entry - %makeslice.buf = call i8* @runtime.alloc(i32 %len, i8* undef, i8* null) #0 + %makeslice.buf = call i8* @runtime.alloc(i32 %len, i8* null, i8* undef, i8* null) #0 %0 = insertvalue { i8*, i32, i32 } undef, i8* %makeslice.buf, 0 %1 = insertvalue { i8*, i32, i32 } %0, i32 %len, 1 %2 = insertvalue { i8*, i32, i32 } %1, i32 %len, 2 @@ -126,7 +126,7 @@ slice.throw: ; preds = %entry slice.next: ; preds = %entry %makeslice.cap = shl i32 %len, 1 - %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* undef, i8* null) #0 + %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* null, i8* undef, i8* null) #0 %makeslice.array = bitcast i8* %makeslice.buf to i16* %0 = insertvalue { i16*, i32, i32 } undef, i16* %makeslice.array, 0 %1 = insertvalue { i16*, i32, i32 } %0, i32 %len, 1 @@ -146,7 +146,7 @@ slice.throw: ; preds = %entry slice.next: ; preds = %entry %makeslice.cap = mul i32 %len, 3 - %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* undef, i8* null) #0 + %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* null, i8* undef, i8* null) #0 %makeslice.array = bitcast i8* %makeslice.buf to [3 x i8]* %0 = insertvalue { [3 x i8]*, i32, i32 } undef, [3 x i8]* %makeslice.array, 0 %1 = insertvalue { [3 x i8]*, i32, i32 } %0, i32 %len, 1 @@ -166,7 +166,7 @@ slice.throw: ; preds = %entry slice.next: ; preds = %entry %makeslice.cap = shl i32 %len, 2 - %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* undef, i8* null) #0 + %makeslice.buf = call i8* @runtime.alloc(i32 %makeslice.cap, i8* null, i8* undef, i8* null) #0 %makeslice.array = bitcast i8* %makeslice.buf to i32* %0 = insertvalue { i32*, i32, i32 } undef, i32* %makeslice.array, 0 %1 = insertvalue { i32*, i32, i32 } %0, i32 %len, 1 diff --git a/compiler/testdata/string.ll b/compiler/testdata/string.ll index a4a819ca..cdc8619a 100644 --- a/compiler/testdata/string.ll +++ b/compiler/testdata/string.ll @@ -7,7 +7,7 @@ target triple = "wasm32-unknown-wasi" @"main.someString$string" = internal unnamed_addr constant [3 x i8] c"foo", align 1 -declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*) +declare noalias nonnull i8* @runtime.alloc(i32, i8*, i8*, i8*) ; Function Attrs: nounwind define hidden void @main.init(i8* %context, i8* %parentHandle) unnamed_addr #0 { diff --git a/interp/testdata/slice-copy.ll b/interp/testdata/slice-copy.ll index ae5cda6c..52cbb372 100644 --- a/interp/testdata/slice-copy.ll +++ b/interp/testdata/slice-copy.ll @@ -10,7 +10,7 @@ target triple = "x86_64--linux" declare i64 @runtime.sliceCopy(i8* %dst, i8* %src, i64 %dstLen, i64 %srcLen, i64 %elemSize) unnamed_addr -declare i8* @runtime.alloc(i64) unnamed_addr +declare i8* @runtime.alloc(i64, i8*) unnamed_addr declare void @runtime.printuint8(i8) @@ -52,7 +52,7 @@ entry: ; uint8SliceDst = make([]uint8, len(uint8SliceSrc)) %uint8SliceSrc = load { i8*, i64, i64 }, { i8*, i64, i64 }* @main.uint8SliceSrc %uint8SliceSrc.len = extractvalue { i8*, i64, i64 } %uint8SliceSrc, 1 - %uint8SliceDst.buf = call i8* @runtime.alloc(i64 %uint8SliceSrc.len) + %uint8SliceDst.buf = call i8* @runtime.alloc(i64 %uint8SliceSrc.len, i8* null) %0 = insertvalue { i8*, i64, i64 } undef, i8* %uint8SliceDst.buf, 0 %1 = insertvalue { i8*, i64, i64 } %0, i64 %uint8SliceSrc.len, 1 %2 = insertvalue { i8*, i64, i64 } %1, i64 %uint8SliceSrc.len, 2 @@ -68,7 +68,7 @@ entry: %int16SliceSrc = load { i16*, i64, i64 }, { i16*, i64, i64 }* @main.int16SliceSrc %int16SliceSrc.len = extractvalue { i16*, i64, i64 } %int16SliceSrc, 1 %int16SliceSrc.len.bytes = mul i64 %int16SliceSrc.len, 2 - %int16SliceDst.buf.raw = call i8* @runtime.alloc(i64 %int16SliceSrc.len.bytes) + %int16SliceDst.buf.raw = call i8* @runtime.alloc(i64 %int16SliceSrc.len.bytes, i8* null) %int16SliceDst.buf = bitcast i8* %int16SliceDst.buf.raw to i16* %3 = insertvalue { i16*, i64, i64 } undef, i16* %int16SliceDst.buf, 0 %4 = insertvalue { i16*, i64, i64 } %3, i64 %int16SliceSrc.len, 1 diff --git a/src/reflect/value.go b/src/reflect/value.go index 88f8137a..f5f0132d 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -729,7 +729,7 @@ func Zero(typ Type) Value { func New(typ Type) Value { return Value{ typecode: PtrTo(typ).(rawType), - value: alloc(typ.Size()), + value: alloc(typ.Size(), nil), flags: valueFlagExported, } } @@ -778,7 +778,7 @@ func (e *ValueError) Error() string { func memcpy(dst, src unsafe.Pointer, size uintptr) //go:linkname alloc runtime.alloc -func alloc(size uintptr) unsafe.Pointer +func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer //go:linkname sliceAppend runtime.sliceAppend func sliceAppend(srcBuf, elemsBuf unsafe.Pointer, srcLen, srcCap, elemsLen uintptr, elemSize uintptr) (unsafe.Pointer, uintptr, uintptr) diff --git a/src/runtime/arch_tinygowasm.go b/src/runtime/arch_tinygowasm.go index a19a1448..7dc04f07 100644 --- a/src/runtime/arch_tinygowasm.go +++ b/src/runtime/arch_tinygowasm.go @@ -66,7 +66,7 @@ func growHeap() bool { //export malloc func libc_malloc(size uintptr) unsafe.Pointer { - return alloc(size) + return alloc(size, nil) } //export free @@ -79,7 +79,7 @@ func libc_calloc(nmemb, size uintptr) unsafe.Pointer { // Note: we could be even more correct here and check that nmemb * size // doesn't overflow. However the current implementation should normally work // fine. - return alloc(nmemb * size) + return alloc(nmemb*size, nil) } //export realloc diff --git a/src/runtime/baremetal.go b/src/runtime/baremetal.go index 6b9fbcc3..e17edcbf 100644 --- a/src/runtime/baremetal.go +++ b/src/runtime/baremetal.go @@ -38,7 +38,7 @@ func growHeap() bool { //export malloc func libc_malloc(size uintptr) unsafe.Pointer { - return alloc(size) + return alloc(size, nil) } //export free diff --git a/src/runtime/chan.go b/src/runtime/chan.go index c2da4f05..a5229f0e 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -133,7 +133,7 @@ func chanMake(elementSize uintptr, bufSize uintptr) *channel { return &channel{ elementSize: elementSize, bufSize: bufSize, - buf: alloc(elementSize * bufSize), + buf: alloc(elementSize*bufSize, nil), } } diff --git a/src/runtime/gc_conservative.go b/src/runtime/gc_conservative.go index 67fbfdb2..ea142be9 100644 --- a/src/runtime/gc_conservative.go +++ b/src/runtime/gc_conservative.go @@ -263,7 +263,7 @@ func calculateHeapAddresses() { // alloc tries to find some free space on the heap, possibly doing a garbage // collection cycle if needed. If no space is free, it panics. //go:noinline -func alloc(size uintptr) unsafe.Pointer { +func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer { if size == 0 { return unsafe.Pointer(&zeroSizedAlloc) } diff --git a/src/runtime/gc_extalloc.go b/src/runtime/gc_extalloc.go index 7272d34c..7fbeec11 100644 --- a/src/runtime/gc_extalloc.go +++ b/src/runtime/gc_extalloc.go @@ -527,7 +527,7 @@ var zeroSizedAlloc uint8 // alloc tries to find some free space on the heap, possibly doing a garbage // collection cycle if needed. If no space is free, it panics. //go:noinline -func alloc(size uintptr) unsafe.Pointer { +func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer { if size == 0 { return unsafe.Pointer(&zeroSizedAlloc) } diff --git a/src/runtime/gc_leaking.go b/src/runtime/gc_leaking.go index 60340c64..345539d6 100644 --- a/src/runtime/gc_leaking.go +++ b/src/runtime/gc_leaking.go @@ -13,7 +13,7 @@ import ( // Ever-incrementing pointer: no memory is freed. var heapptr = heapStart -func alloc(size uintptr) unsafe.Pointer { +func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer { // TODO: this can be optimized by not casting between pointers and ints so // much. And by using platform-native data types (e.g. *uint8 for 8-bit // systems). diff --git a/src/runtime/gc_none.go b/src/runtime/gc_none.go index 6528261b..403675f8 100644 --- a/src/runtime/gc_none.go +++ b/src/runtime/gc_none.go @@ -10,7 +10,7 @@ import ( "unsafe" ) -func alloc(size uintptr) unsafe.Pointer +func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer func free(ptr unsafe.Pointer) { // Nothing to free when nothing gets allocated. diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index fdfbcfde..17299c49 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -69,7 +69,7 @@ func hashmapMake(keySize, valueSize uint8, sizeHint uintptr) *hashmap { bucketBits++ } bucketBufSize := unsafe.Sizeof(hashmapBucket{}) + uintptr(keySize)*8 + uintptr(valueSize)*8 - buckets := alloc(bucketBufSize * (1 << bucketBits)) + buckets := alloc(bucketBufSize*(1<