From 7db50921bcf7590d807a44cdee518e27a9c4f55f Mon Sep 17 00:00:00 2001 From: Aofei Sheng Date: Mon, 17 Jun 2024 08:01:07 +0800 Subject: [PATCH] build: explicitly link libpthread for compatibility with glibc versions before 2.34 Fixes #329 --- internal/build/build.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/build/build.go b/internal/build/build.go index e1ed2f73..f72ca5d4 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -292,7 +292,7 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string, if app == "" { app = filepath.Join(conf.BinPath, name+conf.AppExt) } - const N = 5 + const N = 6 args := make([]string, N, len(pkg.Imports)+len(runtimeFiles)+(N+1)) args[0] = "-o" args[1] = app @@ -300,11 +300,13 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, runtimeFiles []string, args[3] = "-Xlinker" if runtime.GOOS == "darwin" { // ld64.lld (macOS) args[4] = "-dead_strip" + args[5] = "" // It's ok to leave it empty, as we can assume libpthread is built-in on macOS. } else { // ld.lld (Unix), lld-link (Windows), wasm-ld (WebAssembly) args[4] = "--gc-sections" + args[5] = "-lpthread" // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions. } - //args[5] = "-fuse-ld=lld" // TODO(xsw): to check lld exists or not - //args[6] = "-O2" + //args[6] = "-fuse-ld=lld" // TODO(xsw): to check lld exists or not + //args[7] = "-O2" needRuntime := false needPyInit := false packages.Visit([]*packages.Package{pkg}, nil, func(p *packages.Package) {