13 Sep 2025 |
emily | we now have like four PRs with toml11 4 in them so that's fun | 17:51:54 |
emily | I left a comment | 17:52:03 |
aloisw | IIRC several packages tamper with their ldflags in various phases (yuck) so that breaks. Refactoring those could work but I don't know for sure. | 17:52:26 |
aloisw | Yeah sorry for that, that was my fault. I underestimated the urgency of toml11 4 and overestimated the difficutly of fixing nix and lix. | 17:53:13 |
emily | it's understandable! | 17:54:11 |
emily | I was thinking we could append ldflags to GOFLAGS in preBuild or something. | 17:54:30 |
aloisw | Most usages indeed seem to be in preBuild . I don't remember if these packages already ran Go code in configurePhase but probably not. | 17:56:40 |
emily | not sure what the point of a separate ldflags even is tbh | 17:57:52 |
aloisw | probably so that packages can do exactly that shit | 17:59:13 |
emily | they could do it with GOFLAGS ! | 18:00:46 |
aloisw | Actually not quite: https://github.com/NixOS/nixpkgs/commit/155ae682a5122960aed61724b4ed8c9711b53e99 | 18:02:10 |
aloisw | That also explains why GOFLAGS doesn't work (short version: you can't specify -ldflags twice). | 18:02:37 |
emily | I see | 18:12:56 |
emily | I guess it's also "wrong" to use the ldflags for sub-builds in some cases | 18:13:57 |
emily | because people do, like, "-X main.Version=${version}" | 18:14:14 |
emily | and that could be any main | 18:14:17 |
emily | 🤔 | 18:15:04 |
emily | GO_EXTLINK_ENABLED
Whether the linker should use external linking mode
when using -linkmode=auto with code that uses cgo.
Set to 0 to disable external linking mode, 1 to enable it.
| 18:15:10 |
emily | does CGO_ENABLED count as "using cgo" even if the code itself doesn't "use cgo"? | 18:15:23 |
emily | 😮 | 18:15:58 |
emily | // The environment variable GO_EXTLINK_ENABLED controls the
// default value of -linkmode. If it is not set when the
// linker is called we take the value it was set to when
// cmd/link was compiled. (See make.bash.)
| 18:16:01 |
emily | we don't even need to inject a runtime environment variable | 18:16:05 |
emily | iscgo = ctxt.LibraryByPkg["runtime/cgo"] != nil
| 18:17:09 |
emily | I don't know Go well enough to determine whether this is going to be true always when CGO_ENABLED | 18:17:19 |
emily | oh wait the docs lie! | 18:17:40 |
emily | if ctxt.LinkMode == LinkExternal && !iscgo && !(buildcfg.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && ctxt.Arch.Family == sys.AMD64) {
// This indicates a user requested -linkmode=external.
// The startup code uses an import of runtime/cgo to decide
// whether to initialize the TLS. So give it one. This could
// be handled differently but it's an unusual case.
if lib := loadinternal(ctxt, "runtime/cgo"); lib != nil && lib.Shlib == "" {
if ctxt.BuildMode == BuildModeShared || ctxt.linkShared {
Exitf("cannot implicitly include runtime/cgo in a shared library")
}
for ; i < len(ctxt.Library); i++ {
lib := ctxt.Library[i]
if lib.Shlib == "" {
loadobjfile(ctxt, lib)
}
}
}
}
| 18:17:48 |
emily | it applies even when !iscgo | 18:17:52 |
aloisw | Cool, so just setting GO_EXTLINK_ENABLED is enough and we don't need any of the other shit? | 18:21:42 |
emily | Lun: proposal: set GO_EXTLINK_ENABLED = true; for the build of Go itself when !ppc64. patch https://github.com/golang/go/blob/ac803b5949f6dbc5bfa559afe506d35f9e1b3195/src/cmd/link/internal/ld/config.go#L35-L41 to replace the conditional with "ppc64/linux" no, everything else yes (because https://github.com/golang/go/blob/master/src/cmd/link/internal/ld/config.go#L223C8-L223C62) | 18:21:58 |
emily | we still need to ensure PIE is the default but they already have a conditional for that | 18:22:06 |