diff options
| author | Cherry Mui <cherryyz@google.com> | 2023-07-12 16:54:32 -0400 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-07-20 20:54:38 +0000 |
| commit | 57e2eb64ebdd441356eb3fb57bc06636cbfa58c0 (patch) | |
| tree | 84efab16029e2c081912a0a8b97c18f57a2cb916 /src/cmd/link/internal/ld/lib.go | |
| parent | e201ff2b98981807c4d57ed15d42d308817e138a (diff) | |
| download | go-57e2eb64ebdd441356eb3fb57bc06636cbfa58c0.tar.xz | |
cmd/link: pass flags to external linker in deterministic order
Currently we may pass C linker flags in nondeterministic order,
as on ELf systems we pass --export-dynamic-symbol for symbols from
a map. This is usally not a big problem because even if the flags
are passed in nondeterministic order the resulting binary is
probably still deterministic. This CL makes it pass them in a
deterministic order to be extra sure. This also helps build
systems where e.g. there is a build cache for the C linking action.
Change-Id: I930524dd2c3387f49d62be7ad2cef937cb2c2238
Reviewed-on: https://go-review.googlesource.com/c/go/+/509215
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/link/internal/ld/lib.go')
| -rw-r--r-- | src/cmd/link/internal/ld/lib.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 91e2d5149c..6c03072160 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -44,6 +44,7 @@ import ( "os/exec" "path/filepath" "runtime" + "sort" "strings" "sync" @@ -1670,9 +1671,12 @@ func (ctxt *Link) hostlink() { if ctxt.DynlinkingGo() || ctxt.BuildMode == BuildModeCShared || !linkerFlagSupported(ctxt.Arch, argv[0], altLinker, "-Wl,--export-dynamic-symbol=main") { argv = append(argv, "-rdynamic") } else { + var exports []string ctxt.loader.ForAllCgoExportDynamic(func(s loader.Sym) { - argv = append(argv, "-Wl,--export-dynamic-symbol="+ctxt.loader.SymExtname(s)) + exports = append(exports, "-Wl,--export-dynamic-symbol="+ctxt.loader.SymExtname(s)) }) + sort.Strings(exports) + argv = append(argv, exports...) } } if ctxt.HeadType == objabi.Haix { |
