build: fix sigsetjmp issues and ensure required libs on Linux

1. Handle `sigsetjmp` platform differences:
   - Separate `sigsetjmp` linkage to platform-specific files.
   - Use `__sigsetjmp` on Linux to handle `sigsetjmp` being a macro.
   - Maintain original implementation for Darwin.

2. Ensure linking of required libs:
   - Explicitly link against fundamental libs (e.g., libm, libatomic).
   - Address the fact that typical Linux linkers don't link these by
     default.
This commit is contained in:
Aofei Sheng
2024-07-29 08:58:13 +08:00
parent 9dca62ff8b
commit e7d72b6f53
4 changed files with 26 additions and 3 deletions

View File

@@ -44,9 +44,6 @@ func Longjmp(env *JmpBuf, val c.Int)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//go:linkname Sigsetjmp C.sigsetjmp
func Sigsetjmp(env *SigjmpBuf, savemask c.Int) c.Int
//go:linkname Siglongjmp C.siglongjmp //go:linkname Siglongjmp C.siglongjmp
func Siglongjmp(env *SigjmpBuf, val c.Int) func Siglongjmp(env *SigjmpBuf, val c.Int)

12
c/setjmp/setjmp_linux.go Normal file
View File

@@ -0,0 +1,12 @@
//go:build linux
package setjmp
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
//go:linkname Sigsetjmp C.__sigsetjmp
func Sigsetjmp(env *SigjmpBuf, savemask c.Int) c.Int

12
c/setjmp/setjmp_other.go Normal file
View File

@@ -0,0 +1,12 @@
//go:build !linux
package setjmp
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
//go:linkname Sigsetjmp C.sigsetjmp
func Sigsetjmp(env *SigjmpBuf, savemask c.Int) c.Int

View File

@@ -356,6 +356,8 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, llFiles
"-rpath", "$ORIGIN", "-rpath", "$ORIGIN",
"-rpath", "$ORIGIN/../lib", "-rpath", "$ORIGIN/../lib",
"-Xlinker", "--gc-sections", "-Xlinker", "--gc-sections",
"-lm",
"-latomic",
"-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions. "-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
) )
} }