Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add -O2 flag to work around TLS mismatch issue #390

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,26 @@ func linkMainPkg(pkg *packages.Package, pkgs []*aPackage, llFiles []string, conf
if app == "" {
app = filepath.Join(conf.BinPath, name+conf.AppExt)
}
const N = 6
args := make([]string, N, len(pkg.Imports)+len(llFiles)+(N+1))
args[0] = "-o"
args[1] = app
args[2] = "-Wno-override-module"
args[3] = "-Xlinker"
args := make([]string, len(pkg.Imports)+len(llFiles)+10)
args = append(
args,
"-o", app,
// "-fuse-ld=lld", // TODO(xsw): to check lld exists or not
"-Wno-override-module",
"-O2", // Note that this also helps to solve the problem of TLS mismatch on Linux when using GNU ld.
)
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.
args = append(
args,
"-Xlinker", "-dead_strip",
)
} 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 = append(
args,
"-Xlinker", "--gc-sections",
"-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions.
)
}
//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) {
Expand Down
Loading