Skip to content

Commit

Permalink
Absolute path for LDFLAGS when building stdlib
Browse files Browse the repository at this point in the history
When using a custom cpp toolchain that adds libc++.a and libc++abi.a
in link_libs, linking the stdlib fails because it can't find the archives
by their relative paths. Same as issue bazelbuild#1357
  • Loading branch information
anrodrig committed Feb 12, 2021
1 parent 5c6e9f4 commit 9f1ed61
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion go/tools/builders/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,19 @@ You may need to use the flags --cpu=x64_windows --compiler=mingw-gcc.`)

// Strip path prefix from source files in debug information.
os.Setenv("CGO_CFLAGS", os.Getenv("CGO_CFLAGS")+" "+strings.Join(defaultCFlags(output), " "))
os.Setenv("CGO_LDFLAGS", os.Getenv("CGO_LDFLAGS")+" "+strings.Join(defaultLdFlags(), " "))
relativeLdflags, _ := splitQuoted(os.Getenv("CGO_LDFLAGS"))
var absLdflags strings.Builder
for _, f := range relativeLdflags {
if strings.HasPrefix(f, "-") {
absLdflags.WriteString(f)
} else if _, err := os.Stat(f); os.IsNotExist(err) {
absLdflags.WriteString(f)
} else {
absLdflags.WriteString(abs(f))
}
absLdflags.WriteString(" ")
}
os.Setenv("CGO_LDFLAGS", absLdflags.String()+" "+strings.Join(defaultLdFlags(), " "))

// Allow flags in CGO_LDFLAGS that wouldn't pass the security check.
// Workaround for golang.org/issue/42565.
Expand Down

0 comments on commit 9f1ed61

Please sign in to comment.