fix: symbol not found when building in baremental environment

This commit is contained in:
Haolan
2025-09-05 16:27:38 +08:00
parent 6588f36123
commit 2d1120bf69
15 changed files with 143 additions and 34 deletions

View File

@@ -21,7 +21,7 @@ import (
)
const (
LLGoPackage = "decl"
LLGoPackage = "link"
)
type (

View File

@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !wasm && !baremental
package debug

View File

@@ -0,0 +1,40 @@
//go:build baremental
package debug
import (
"unsafe"
c "github.com/goplus/llgo/runtime/internal/clite"
)
type Info struct {
Fname *c.Char
Fbase c.Pointer
Sname *c.Char
Saddr c.Pointer
}
func Address() unsafe.Pointer {
panic("not implemented")
}
func Addrinfo(addr unsafe.Pointer, info *Info) c.Int {
panic("not implemented")
}
type Frame struct {
PC uintptr
Offset uintptr
SP unsafe.Pointer
Name string
}
func StackTrace(skip int, fn func(fr *Frame) bool) {
panic("not implemented")
}
func PrintStack(skip int) {
panic("not implemented")
}

View File

@@ -1,3 +1,5 @@
//go:build wasm
package debug
import (

View File

@@ -1,4 +1,4 @@
//go:build linux
//go:build linux && !baremental
package debug

View File

@@ -0,0 +1,29 @@
//go:build baremental
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package c
import _ "unsafe"
//go:linkname Stdin stdin
var Stdin FilePtr
//go:linkname Stdout stdout
var Stdout FilePtr
var Stderr FilePtr = Fopen(Str("/dev/stderr"), Str("w"))

View File

@@ -1,5 +1,4 @@
//go:build !darwin
// +build !darwin
//go:build !darwin && !baremental
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.

View File

@@ -0,0 +1,15 @@
//go:build baremental
package unix
import (
_ "unsafe"
)
func Fcntl(fd int, cmd int, arg int) (int, error) {
return 0, nil
}
func fcntl(fd int, cmd int, arg int) (int, error) {
return 0, nil
}

View File

@@ -1,3 +1,5 @@
//go:build !baremental
package unix
import (

View File

@@ -0,0 +1,5 @@
//go:build baremental
package runtime
func c_maxprocs() int32 { return 1 }

View File

@@ -0,0 +1,11 @@
//go:build !baremental
package runtime
const (
LLGoPackage = "link"
LLGoFiles = "_wrap/runtime.c"
)
//go:linkname c_maxprocs C.llgo_maxprocs
func c_maxprocs() int32

View File

@@ -26,11 +26,6 @@ import (
// llgo:skipall
type _runtime struct{}
const (
LLGoPackage = "link"
LLGoFiles = "_wrap/runtime.c"
)
var defaultGOROOT string // set by cmd/link
func GOROOT() string {
@@ -43,9 +38,6 @@ func Version() string {
return buildVersion
}
//go:linkname c_maxprocs C.llgo_maxprocs
func c_maxprocs() int32
func GOMAXPROCS(n int) int {
return int(c_maxprocs())
}

View File

@@ -0,0 +1,6 @@
//go:build baremental
package runtime
// Rethrow rethrows a panic.
func Rethrow(link *Defer) {}

View File

@@ -0,0 +1,29 @@
//go:build !baremental
package runtime
import (
c "github.com/goplus/llgo/runtime/internal/clite"
"github.com/goplus/llgo/runtime/internal/clite/debug"
"github.com/goplus/llgo/runtime/internal/clite/pthread"
)
// Rethrow rethrows a panic.
func Rethrow(link *Defer) {
if ptr := excepKey.Get(); ptr != nil {
if link == nil {
TracePanic(*(*any)(ptr))
debug.PrintStack(2)
c.Free(ptr)
c.Exit(2)
} else {
c.Siglongjmp(link.Addr, 1)
}
} else if link == nil && goexitKey.Get() != nil {
if pthread.Equal(mainThread, pthread.Self()) != 0 {
fatal("no goroutines (main called runtime.Goexit) - deadlock!")
c.Exit(2)
}
pthread.Exit(nil)
}
}

View File

@@ -20,7 +20,6 @@ import (
"unsafe"
c "github.com/goplus/llgo/runtime/internal/clite"
"github.com/goplus/llgo/runtime/internal/clite/debug"
"github.com/goplus/llgo/runtime/internal/clite/pthread"
"github.com/goplus/llgo/runtime/internal/clite/setjmp"
)
@@ -57,26 +56,6 @@ func Panic(v any) {
Rethrow((*Defer)(c.GoDeferData()))
}
// Rethrow rethrows a panic.
func Rethrow(link *Defer) {
if ptr := excepKey.Get(); ptr != nil {
if link == nil {
TracePanic(*(*any)(ptr))
debug.PrintStack(2)
c.Free(ptr)
c.Exit(2)
} else {
c.Siglongjmp(link.Addr, 1)
}
} else if link == nil && goexitKey.Get() != nil {
if pthread.Equal(mainThread, pthread.Self()) != 0 {
fatal("no goroutines (main called runtime.Goexit) - deadlock!")
c.Exit(2)
}
pthread.Exit(nil)
}
}
var (
excepKey pthread.Key
goexitKey pthread.Key