Merge pull request #334 from aofei/build

build: explicitly link libpthread for compatibility with glibc versions before 2.34
This commit is contained in:
xushiwei
2024-06-17 18:15:41 +08:00
committed by GitHub

View File

@@ -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) {