aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link
AgeCommit message (Collapse)Author
2023-02-16cmd/link: don't switch to gold on ARM LinuxIan Lance Taylor
The bug in GNU ld appears to have been fixed in GNU binutils 2.28 by GNU binutils revision 5522f910cb539905d6adfdceab208ddfa5e84557. (This may have been accidental as the ChangeLog for the fix makes no reference to it; the fix is from https://sourceware.org/bugzilla/show_bug.cgi?id=19962). Continue using gold on arm64, at least for now, because as reported in issue #22040 GNU ld still fails there. For #15696 For #22040 Change-Id: I5534bb8b5680daf536a7941aba5c701e8a4138ab Reviewed-on: https://go-review.googlesource.com/c/go/+/468655 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2023-02-13cmd/link/internal/ld: fix text section splitting for ARMThan McIntosh
Fix a problem with trampoline generation for ARM that was causing link failures when building selected k8s targets. Representative error (this is coming from the external linker): go.go:(.text+...): relocation truncated to fit: R_ARM_CALL against `runtime.duffcopy' The Go linker is supposed to be limiting text section size for ARM to 0x1c00000 bytes, however due to a problem in the tramp generation phase this limit wasn't being enforced. Updates #58428. Fixes #58425. Change-Id: I4e778bdcbebeab607a6e626b354ca5109e52a1aa Reviewed-on: https://go-review.googlesource.com/c/go/+/467715 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-10cmd/link: try libssp_nonshared.a when looking for "__stack_chk_fail_local"Than McIntosh
Update the code that tries to satisfy unresolved references to "__stack_chk_fail_local" to look for "libssp_nonshared.a" in addition to "libc_nonshared.a" (the former archive is the correct place on Alpine). Updates #52919. Updates #54313. Updates #57261. Fixes #58385. Change-Id: Id6cd3ebb4d5388df50a838e6efa5e5b683545b01 Reviewed-on: https://go-review.googlesource.com/c/go/+/466936 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-10cmd/link: improve error for missing SDYNIMPORT support on mips/mips64Than McIntosh
Issue an error (instead of crashing) when encountering a symbol that requires dynamic relocations on mips/mips64. The dynimport support is in progress, but is not done yet, so rather than crashing, print a message indicating that the feature is not yet implemented and exit. Fixes #58240. Change-Id: I9ad64c89e4f7b4b180964b35ad1d72d375f2df7f Reviewed-on: https://go-review.googlesource.com/c/go/+/466895 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joel Sing <joel@sing.id.au> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2023-02-06cmd/link: linker portion of dead map removalThan McIntosh
This patch contains the linker changes needed to enable deadcoding of large unreferenced map variables, in combination with a previous compiler change. We add a new cleanup function that runs just after deadcode that looks for relocations in "init" funcs that are weak, of type R_CALL (and siblings), and are targeting an unreachable function. If we find such a relocation, after checking to make sure it targets a map.init.XXX helper, we redirect the relocation to a point to a no-op routine ("mapinitnoop") in the runtime. Compilebench results for this change: │ out.base.txt │ out.wrap.txt │ │ sec/op │ sec/op vs base │ Template 218.6m ± 2% 221.1m ± 1% ~ (p=0.129 n=39) Unicode 180.5m ± 1% 178.9m ± 1% -0.93% (p=0.006 n=39) GoTypes 1.162 ± 1% 1.156 ± 1% ~ (p=0.850 n=39) Compiler 143.6m ± 1% 142.6m ± 1% ~ (p=0.743 n=39) SSA 8.698 ± 1% 8.719 ± 1% ~ (p=0.145 n=39) Flate 142.6m ± 1% 143.9m ± 3% ~ (p=0.287 n=39) GoParser 247.7m ± 1% 248.8m ± 1% ~ (p=0.265 n=39) Reflect 588.0m ± 1% 590.4m ± 1% ~ (p=0.269 n=39) Tar 198.5m ± 1% 201.3m ± 1% +1.38% (p=0.005 n=39) XML 259.1m ± 1% 260.0m ± 1% ~ (p=0.376 n=39) LinkCompiler 746.8m ± 2% 747.8m ± 1% ~ (p=0.706 n=39) ExternalLinkCompiler 1.906 ± 0% 1.902 ± 1% ~ (p=0.207 n=40) LinkWithoutDebugCompiler 522.4m ± 21% 471.1m ± 1% -9.81% (p=0.000 n=40) StdCmd 21.32 ± 0% 21.39 ± 0% +0.32% (p=0.035 n=40) geomean 609.2m 606.0m -0.53% │ out.base.txt │ out.wrap.txt │ │ user-sec/op │ user-sec/op vs base │ Template 401.9m ± 3% 406.9m ± 2% ~ (p=0.291 n=39) Unicode 191.9m ± 6% 196.1m ± 3% ~ (p=0.052 n=39) GoTypes 3.967 ± 3% 4.056 ± 1% ~ (p=0.099 n=39) Compiler 171.1m ± 3% 173.4m ± 3% ~ (p=0.415 n=39) SSA 30.04 ± 4% 30.25 ± 4% ~ (p=0.106 n=39) Flate 246.3m ± 3% 248.9m ± 4% ~ (p=0.499 n=39) GoParser 518.7m ± 1% 520.6m ± 2% ~ (p=0.531 n=39) Reflect 1.670 ± 1% 1.656 ± 2% ~ (p=0.137 n=39) Tar 352.7m ± 2% 360.3m ± 2% ~ (p=0.117 n=39) XML 528.8m ± 2% 521.1m ± 2% ~ (p=0.296 n=39) LinkCompiler 1.128 ± 2% 1.140 ± 2% ~ (p=0.324 n=39) ExternalLinkCompiler 2.165 ± 2% 2.147 ± 2% ~ (p=0.537 n=40) LinkWithoutDebugCompiler 484.2m ± 4% 490.7m ± 3% ~ (p=0.897 n=40) geomean 818.5m 825.1m +0.80% │ out.base.txt │ out.wrap.txt │ │ text-bytes │ text-bytes vs base │ HelloSize 766.0Ki ± 0% 766.0Ki ± 0% ~ (p=1.000 n=40) ¹ CmdGoSize 10.02Mi ± 0% 10.02Mi ± 0% -0.03% (n=40) geomean 2.738Mi 2.738Mi -0.01% ¹ all samples are equal │ out.base.txt │ out.wrap.txt │ │ data-bytes │ data-bytes vs base │ HelloSize 14.17Ki ± 0% 14.17Ki ± 0% ~ (p=1.000 n=40) ¹ CmdGoSize 308.3Ki ± 0% 298.5Ki ± 0% -3.19% (n=40) geomean 66.10Ki 65.04Ki -1.61% ¹ all samples are equal │ out.base.txt │ out.wrap.txt │ │ bss-bytes │ bss-bytes vs base │ HelloSize 197.3Ki ± 0% 197.3Ki ± 0% ~ (p=1.000 n=40) ¹ CmdGoSize 228.2Ki ± 0% 228.1Ki ± 0% -0.01% (n=40) geomean 212.2Ki 212.1Ki -0.01% ¹ all samples are equal │ out.base.txt │ out.wrap.txt │ │ exe-bytes │ exe-bytes vs base │ HelloSize 1.192Mi ± 0% 1.192Mi ± 0% +0.00% (p=0.000 n=40) CmdGoSize 14.85Mi ± 0% 14.83Mi ± 0% -0.09% (n=40) geomean 4.207Mi 4.205Mi -0.05% Also tested for any linker changes by benchmarking relink of k8s "kubelet"; no changes to speak of there. Updates #2559. Updates #36021. Updates #14840. Change-Id: I4cc5370b3f20679a1065aaaf87bdf2881e257631 Reviewed-on: https://go-review.googlesource.com/c/go/+/463395 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-06cmd/internal/obj: flag init functions in object fileThan McIntosh
Introduce a flag in the object file indicating whether a given function corresponds to a compiler-generated (not user-written) init function, such as "os.init" or "syscall.init". Add code to the compiler to fill in the correct value for the flag, and add support to the loader package in the linker for testing the flag. The new loader API is currently unused, but will be needed in the next CL in this stack. Updates #2559. Updates #36021. Updates #14840. Change-Id: Iea7ad2adda487e4af7a44f062f9817977c53b394 Reviewed-on: https://go-review.googlesource.com/c/go/+/463855 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-02internal/testenv: avoid rebuilding all of std in WriteImportcfgBryan C. Mills
Instead, have the caller pass in an explicit list of the packages (if any) they need. After #47257, a builder running a test does not necessarily have the entire standard library already cached, especially when running tests in sharded mode. testenv.WriteImportcfg used to write an importcfg for the entire standard library — which required rebuilding the entire standard library — even though most tests need only a tiny subset. This reduces the time to test internal/abi with a cold build cache on my workstation from ~16s to ~0.05s. It somewhat increases the time for 'go test go/internal/gcimporter' with a cold cache, from ~43s to ~54s, presumably due to decreased parallelism in rebuilding the standard library and increased overhead in re-resolving the import map. However, 'go test -short' running time remains stable (~5.5s before and after). Fixes #58248. Change-Id: I9be6b61ae6e28b75b53af85207c281bb93b9346f Reviewed-on: https://go-review.googlesource.com/c/go/+/464736 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-02-02cmd/link: remove special cases for relocations in .go.buildinfoRuss Cox
.go.buildinfo has no relocations anymore, as of Go 1.18. Change-Id: I98369c6a0ef07ada770eaa12f6f56c210e812abc Reviewed-on: https://go-review.googlesource.com/c/go/+/464436 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-02-02cmd/link: keep go.buildinfo even with --gc-sectionsRuss Cox
If you use an external linker with --gc-sections, nothing refers to .go.buildinfo, so the section is deleted, which in turns makes 'go version' fail on the binary. It is important for vulnerability scanning and the like to be able to run 'go version' on any binary. Fix this by inserting a reference to .go.buildinfo from the rodata section, which will not be GC'ed. Fixes #58222. Change-Id: I1e13e9464acaf2f5cc5e0b70476fa52b43651123 Reviewed-on: https://go-review.googlesource.com/c/go/+/464435 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31cmd/link: add debug print in hostobjCopyCherry Mui
In external linking mode, when the external linker fails to handle something in a host object file, it usually reports the name of the host object which is a copied file named 000NNN.o. This is often not helpful to determine what file it is. Add some debug print so at least in -v mode it is more helpful. Change-Id: Ibe762bff6a25640d16ee0dc082736ba5161b7522 Reviewed-on: https://go-review.googlesource.com/c/go/+/458735 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31cmd/link: rewrite (*BuildMode).Set to use platform.BuildModeSupportedIan Lance Taylor
Change-Id: I7aa2bb4560198a7d9d9e4321f60dec38f6834bdc Reviewed-on: https://go-review.googlesource.com/c/go/+/463745 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-01-31cmd/link: rename ELF struct fields to remove "elf" prefixIan Lance Taylor
While we're here rename setupplt to setupPLT. This is a pure naming change with no semantic change. Change-Id: Ib0312fb6568475b620dab7632438b4d25e4d9cc0 Reviewed-on: https://go-review.googlesource.com/c/go/+/463744 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2023-01-31cmd/link, cmd/dist, internal/platform: consolidate c-archive supportIan Lance Taylor
Make all the tests for whether -buildmode=c-archive is supported consistent. Base this on the historical code, on whether cmd/compile supports -shared, and whether cmd/link permits the mode. Change-Id: Ib996546906f698ade4c32b8e6c705838e4ad4b90 Reviewed-on: https://go-review.googlesource.com/c/go/+/463984 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31cmd/link: skip c-archive tests if c-archive mode is not supportedIan Lance Taylor
Change-Id: If0e034d9ebf2baeb89cb52b22aedbe923cc703ff Reviewed-on: https://go-review.googlesource.com/c/go/+/463983 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31cmd/link: make .dynamic section read-only for MIPS ELFIan Lance Taylor
For #36435 Change-Id: Ie733b641f20ca5bcee3784c088eb27699890a151 Reviewed-on: https://go-review.googlesource.com/c/go/+/463982 Reviewed-by: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2023-01-31cmd/link: load host archive libc_nonshared.a for -fstack-protectorThan McIntosh
For internal linking, at the point where we finish reading libgcc.a, if the symbol "__stack_chk_local" is still undefined, then read in the host archive libc_nonshared.a as well. Updates #57261. Change-Id: I0b1e485aa50aa7940db8cabcb3b9a7959bf99ce7 Reviewed-on: https://go-review.googlesource.com/c/go/+/456856 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-30cmd/link: refactor ELF hooks into ELFArch structIan Lance Taylor
This is a pure cleanup to bring the ELF hooks together. Change-Id: I01d5227c70f30e4a659dcd7904e7c247266e95b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/463981 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joel Sing <joel@sing.id.au>
2023-01-30all: fix problematic commentscui fliter
Change-Id: If092ae7c72b66f172ae32fa6c7294a7ac250362e Reviewed-on: https://go-review.googlesource.com/c/go/+/463995 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2023-01-30cmd/link/internal/ld: split varDeclCoords testsMichael Pratt
This test set is a bit hard to follow due to trying to test both variable and function declaration location information. Now that we have additional helpers to avoid duplication, it isn't too much work to split them up into individually more understandable tests. Change-Id: I619ac82ac3b5d00683e22a4a2064e2a5b15e8ce9 Reviewed-on: https://go-review.googlesource.com/c/go/+/458197 Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2023-01-30cmd/link/internal/ld: add dwarf testing helpersMichael Pratt
Many tests build a program just to analyze it with dwtest.Examiner. Add gobuildAndExamine, a helper that returns Examiner directly to reduce duplication in these tests. Many tests also lookup the DIE for a specific subprogram, which includes several verification steps. Package those up in findSubprogramDIE. Change-Id: I72202ba289ae8389b682be525ff7e6cfbfc00ff3 Reviewed-on: https://go-review.googlesource.com/c/go/+/458196 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-30cmd/compile,cmd/link: set DW_AT_decl_line for function declarationsMichael Pratt
DW_AT_decl_line provides the line number of function declarations (the line containing the func keyword). This is the equivalent to CL 429638, but provided via DWARF. Note that the file of declarations (DW_AT_decl_file) is already provided for non-inlined functions. It is omitted for inlined functions because those DWARF subprograms may be generated outside of their source compilation unit, where referencing the file table is difficult. Fixes #57308. Change-Id: I3ad12e1f366c4465c2a588297988a5825ef7efec Reviewed-on: https://go-review.googlesource.com/c/go/+/458195 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-01-25cmd: remove GOEXPERIMENT=nounified knobMatthew Dempsky
This CL removes the GOEXPERIMENT=nounified knob, and any conditional statements that depend on that knob. Further CLs to remove unreachable code follow this one. Updates #57410. Change-Id: I39c147e1a83601c73f8316a001705778fee64a91 Reviewed-on: https://go-review.googlesource.com/c/go/+/458615 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-01-25cmd/link: don't export all symbols for ELF external linkingIan Lance Taylor
Since this may add a large number of --export-dynamic-symbol options, use a response file if the command line gets large. Fixes #53579 Change-Id: Ic226bf372bf1e177a3dae886d1c48f4ce3569c0e Reviewed-on: https://go-review.googlesource.com/c/go/+/414654 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-24cmd/link: support R_ADDRPOWER_GOT_PCREL34 on ppc64lePaul E. Murphy
This will be generated by go code built for dynamic linking when built with GOPPC64=power10 in a future change. Change-Id: I9bd7ca6b2a65c360465e35ef12b10d3fa6d75745 Reviewed-on: https://go-review.googlesource.com/c/go/+/463015 Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Archana Ravindar <aravind5@in.ibm.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-01-24cmd/link: remove importcycles functionJeremy Quirke
The importcycles method has not been useful since April 2016 when a large code deletion was performed. The compiler itself provides some protection against import cycles, and the linker does import cycle detection in linksetup -> postorder. For #57400 Change-Id: I3095bdb3f16a82ba25681bf4a20ceaa3c9613921 GitHub-Last-Rev: 87a46153b136db67675874ffe46e5881b9c756ce GitHub-Pull-Request: golang/go#57462 Reviewed-on: https://go-review.googlesource.com/c/go/+/459475 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com>
2023-01-23internal/abi,runtime: refactor map constants into one placeDavid Chase
Previously TryBot-tested with bucket bits = 4. Also tested locally with bucket bits = 5. This makes it much easier to change the size of map buckets, and hopefully provides pointers to all the code that in some way depends on details of map layout. Change-Id: I9f6669d1eadd02f182d0bc3f959dc5f385fa1683 Reviewed-on: https://go-review.googlesource.com/c/go/+/462115 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Austin Clements <austin@google.com>
2023-01-20cmd/link: fix incorrect DOS header on Windows binariesKevin Parsons
The previous DOS header placed on Windows binaries was incorrect, as it had e_crlc (number of relocations) set to 4, instead of e_cparhdr (size of header in 16-bit words) set to 4. This resulted in execution starting at the beginning of the file, instead of where the DOS stub code actually exists. Fixes #57834 Change-Id: I8c5966b65c72b2474b771b85aaadb61cad9f5be6 GitHub-Last-Rev: c715ad290a01218a1320834e519125e7a5f94384 GitHub-Pull-Request: golang/go#57835 Reviewed-on: https://go-review.googlesource.com/c/go/+/462054 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
2023-01-20cmd/link: use strings.LastIndexByte to fix a TODODaniel Martí
Go 1.20 will require Go 1.17 to bootstrap, so we can stop worrying about older Go bootstrap versions. https://go.dev/issues/44505 fixed most of those TODOs, but this one was presumably forgotten about. Change-Id: I0c19ec4eec65cd807e7db9a57c5969845d915c07 Reviewed-on: https://go-review.googlesource.com/c/go/+/461155 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-01-10cmd/link, runtime: Apple libc atfork workaround take 3Russ Cox
CL 451735 worked around bugs in Apple's atfork handlers by calling notify_is_valid_token and xpc_atfork_child at startup, so that init code that wouldn't be safe in the child process would be warmed up in the parent process instead, but xpc_atfork_child broke use of the xpc library in Go programs, and xpc is internally used by various macOS frameworks (#57263). CL 459175 reverted that change, and then CL 459176 tried a new approach: use __fork, which doesn't call any of the atfork handlers at all. That worked, but an Apple engineer reviewing the change in private email suggests that since __fork is not public API, it should be avoided. The same engineer (with access to the source code for the xpc library) suggests that the breakage in #57263 is caused by xpc_atfork_child marking the library as unusable, expecting an imminent call to exec, and that calling xpc_date_create_from_current instead would do the necessary initialization without marking xpc as unusable. CL 460475 reverted that change, to prepare for this one. This CL goes back to the original “call functions to warm things up” approach, replacing xpc_atfork_child with xpc_date_create_from_current. The CL also updates cmd/link to use OS and SDK version 10.13.0 for x86 macOS binaries, up from 10.9.0, also suggested by the Apple engineer. Combined with the two warmup calls, this makes the fork hangs go away. The minimum macOS version has been 10.13 High Sierra since Go 1.17, so there should be no problem with writing that in the binaries too. Fixes #33565. Fixes #56784. Fixes #57263. Fixes #57577. Change-Id: I20769d9daa1fe9ea930f8009481335f8a14dc21b Reviewed-on: https://go-review.googlesource.com/c/go/+/460476 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-12-23cmd/link, runtime: use a different section for Go libfuzzer countersCherry Mui
Currently in libfuzzer mode, we put our counters in section __sancov_cntrs. When linking with C/C++ code that also has fuzzer counters, apparently the C linker combines our counters and their counters and registers them together. But in the Go runtime we also have code to register our counters. So the Go counters ended up registered twice, causing problems. Since we already have code to register our counters, put them in a Go-specific section so it won't be combined with the C counters. Fixes #57449. Change-Id: If3d41735124e7e301572d4b7aecf7d057ac134c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/459055 Reviewed-by: Nicolas Hillegeer <aktau@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-12-08cmd/link: fix dynamic interpreter path for musl-based linux amd64cia-rana
Change-Id: Ia07e237647b419b73d6faa11baa32e6176c8b7ce Reviewed-on: https://go-review.googlesource.com/c/go/+/456215 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-12-06cmd/link: pass -Wl,--no-insert-timestamp to external linker on windowsThan McIntosh
Pass -Wl,--no-insert-timestamp to the external linker on windows, so as to suppress generation of the PE file header data/time stamp. This is in order to make it possible to get reproducible CGO builds on windows (note that we already zero the timestamp field in question for internal linkage). Updates #35006. Change-Id: I3d69cf1fd32e099bd9bb4b0431a4c5f43e4b08f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/455535 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-19cmd/link: revise DLL import symbol handlingThan McIntosh
This patch reworks the handling of DLL import symbols in the PE host object loader to ensure that the Go linker can deal with them properly during internal linking. Prior to this point the strategy was to immediately treat an import symbol reference of the form "__imp__XXX" as if it were a reference to the corresponding DYNIMPORT symbol XXX, except for certain special cases. This worked for the most part, but ran into problems in situations where the target ("XXX") wasn't a previously created DYNIMPORT symbol (and when these problems happened, the root cause was not always easy to see). The new strategy is to not do any renaming or forwarding immediately, but to delay handling until host object loading is complete. At that point we make a scan through the newly introduced text+data sections looking at the relocations that target import symbols, forwarding the references to the corresponding DYNIMPORT sym where appropriate and where there are direct refs to the DYNIMPORT syms, tagging them for stub generation later on. Updates #35006. Updates #53540. Change-Id: I2d42b39141ae150a9f82ecc334001749ae8a3b4a Reviewed-on: https://go-review.googlesource.com/c/go/+/451738 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2022-11-19cmd/link: add capturehostobjs debugging flagThan McIntosh
Add a new debugging flag "-capturehostobjs" that instructs the linker to capture copies of all object files loaded in during the host object loading portion of CGO internal linking. The intent is to make it easier to analyze the objects after the fact (as opposed to having to dig around inside archives, which can be a "find needle in haystack" exercise). Change-Id: I7023a5b72b1b899ea9b3bd6501f069d1f21bbaf0 Reviewed-on: https://go-review.googlesource.com/c/go/+/451737 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-11-19cmd/link: improved host archive debug trace outputThan McIntosh
When ctxt.Debugvlog > 1, produce additional trace output to describe which object files are being pulled out of host archive libraries and why they were pulled (e.g. which symbol had a reference to something in a library). Intended to make it easier to debug problems with cgo internal linking. Change-Id: Icd64aff244b9145162a00cb51642ef32f26adfba Reviewed-on: https://go-review.googlesource.com/c/go/+/451736 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-18all: add missing periods in commentscui fliter
Change-Id: I69065f8adf101fdb28682c55997f503013a50e29 Reviewed-on: https://go-review.googlesource.com/c/go/+/449757 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-18runtime,cmd/link: increase stack guard space when building with -raceKeith Randall
More stuff to do = more stack needed. Bump up the guard space when building with the race detector. Fixes #54291 Change-Id: I701bc8800507921bed568047d35b8f49c26e7df7 Reviewed-on: https://go-review.googlesource.com/c/go/+/451217 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-11-18cmd/link/internal/ppc64: fix trampoline reuse distance calculationPaul E. Murphy
If a compatible trampoline has been inserted by a previously laid function in the same section, and is known to be sufficiently close, it can be reused. When testing if the trampoline can be reused, the addend of the direct call should be ignored. It is already encoded in the trampoline. If the addend is non-zero, and the target sufficiently far away, and just beyond direct call reach, this may cause the trampoline to be incorrectly reused. This was observed on go1.17.13 and openshift-installer commit f3c53b382 building in release mode with the following error: github.com/aliyun/alibaba-cloud-sdk-go/services/cms.(*Client).DescribeMonitoringAgentAccessKeyWithChan.func1: direct call too far: runtime.duffzero+1f0-tramp0-1 -2000078 Fixes #56775 Change-Id: I54af957302506d4e3cd5d3121542c83fe980e912 Reviewed-on: https://go-review.googlesource.com/c/go/+/451415 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Than McIntosh <thanm@google.com>
2022-11-16cmd/compile: do not emit a few more basic types from every compilationRuss Cox
We already emit types for any and func(error) string in runtime.a but unlike the other pre-emitted types, we don't then exclude them from being emitted in other packages. Fix that. Also add slices of non-func types that we already emit. Saves 0.3% of .a files in std cmd deps, computed by adding sizes from: ls -l $(go list -export -f '{{.Export}}' -deps std cmd The effect is small and not worth doing on its own. The real improvement is making “what to write always in runtime” and “what not to write in other packages” more obviously aligned. Change-Id: Ie5cb5fd7e5a3025d2776d9b4cece775fdf92d3b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/450135 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
2022-11-15cmd/link: use testenv.Command instead of exec.Command in testsBryan C. Mills
testenv.Command sets a default timeout based on the test's deadline and sends SIGQUIT (where supported) in case of a hang. Change-Id: I25a67aa5793c6fa977ff6d4dc59ca1533bf58d41 Reviewed-on: https://go-review.googlesource.com/c/go/+/450702 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-11-11cmd/link: exit if runtime.a is missingCherry Mui
Many stages in the linker assume some runtime symbols exist. Error out if the runtime package cannot be found. Fixes #56685. Change-Id: I39b2663f6d7419688e30e6d8650e5eb8fc43a2b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/449638 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-03cmd/link: support PPC64 prefixed relocations for power10Paul E. Murphy
Handle emitting (to ld) or resolving commonly used ELFv2 1.5 relocations. The new ISA provides PC relative addressing with 34 bit signed addresses, and many other relocations which can replace addis + d-form type relocations with a single prefixed instruction. Updates #44549 Change-Id: I7d4f4314d1082daa3938f4353826739be35b0e81 Reviewed-on: https://go-review.googlesource.com/c/go/+/355149 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Paul Murphy <murp@ibm.com>
2022-11-02cmd/link: remove unnecessary use of sync.Once alongside sync.MutexRuss Cox
There does not seem to be any point to this sync.Once. I noticed because I was surveying uses of sync.Once to understand usage patterns. This seems to be a dreg left over from some earlier instance of the code. Change-Id: I99dd258d865a41d0e8f6cfa55887855e477fb9c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/445755 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-10-28cmd/go: don't install most GOROOT .a files in pkgMichael Matloob
Packages in GOROOT that don't use cgo will not be installed in GOROOT/pkg, and will instead be cached as usual like other Go packages. - add a internal/buildinternal package to hold the identities of the five packages that use cgo - update dist's test code to do a go build std cmd before checking staleness on builders. Because most of those packages no longer have install locations, and have dependencies that don't either, the packages need to be cached to not be stale. - fix index_test to import packages with the path "." when preparing the "want" values to compare the indexed data to. (the module index matches the behavior of build.ImportDir, which always passes in "." as the path. - In both the index and go/build Importers, don't set PkgObj for GOROOT packages which will no longer have install targets. PkgTargetRoot will still be set to compute target paths, which will still be needed in buildmode=shared. - "downgrade" all install actions that don't have a target to build actions. (The target should already not be set for packages that shouldn't be installed). For #47257 Change-Id: Ia5aee6b3b20b58e028119cf0352a4c4a2f10f6b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/432535 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-10-28cmd/compile: emit DIEs for zero sized variablesAlessandro Arzilli
Fixes the compiler to emit DIEs for zero sized variables. Fixes #54615 Change-Id: I1e0c86a97f1abcc7edae516b6a7fe35bcb65ed0f Reviewed-on: https://go-review.googlesource.com/c/go/+/433479 Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
2022-10-28cmd/internal/obj/arm64: optimize ADRP+ADD+LD/ST to ADRP+LD/ST(offset)eric fang
This CL optimizes the sequence of instructions ADRP+ADD+LD/ST to the sequence of ADRP+LD/ST(offset). This saves an ADD instruction. The test result of compilecmp: name old text-bytes new text-bytes delta HelloSize 763kB ± 0% 755kB ± 0% -1.06% (p=0.000 n=20+20) name old data-bytes new data-bytes delta HelloSize 13.5kB ± 0% 13.5kB ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 227kB ± 0% 227kB ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 1.33MB ± 0% 1.33MB ± 0% -0.02% (p=0.000 n=20+20) file before after Δ % addr2line 3760392 3759504 -888 -0.024% api 5361511 5295351 -66160 -1.234% asm 5014157 4948674 -65483 -1.306% buildid 2579949 2579485 -464 -0.018% cgo 4492817 4491737 -1080 -0.024% compile 23359229 23156074 -203155 -0.870% cover 4823337 4756937 -66400 -1.377% dist 3332850 3331794 -1056 -0.032% doc 3902649 3836745 -65904 -1.689% fix 3269708 3268828 -880 -0.027% link 6510760 6443496 -67264 -1.033% nm 3670740 3604348 -66392 -1.809% objdump 4069599 4068967 -632 -0.016% pack 2374824 2374208 -616 -0.026% pprof 13874860 13805700 -69160 -0.498% test2json 2599210 2598530 -680 -0.026% trace 13231640 13162872 -68768 -0.520% vet 7360899 7292267 -68632 -0.932% total 113589131 112775517 -813614 -0.716% Change-Id: Ie1cf277e149ddd3f352d05fa0753d0ced7e0b894 Reviewed-on: https://go-review.googlesource.com/c/go/+/444715 Run-TryBot: Eric Fang <eric.fang@arm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2022-10-27runtime: add wasm bulk memory operationsGaret Halliday
The existing implementation uses loops to implement bulk memory operations such as memcpy and memclr. Now that bulk memory operations have been standardized and are implemented in all major browsers and engines (see https://webassembly.org/roadmap/), we should use them to improve performance. Updates #28360 Change-Id: I28df0e0350287d5e7e1d1c09a4064ea1054e7575 Reviewed-on: https://go-review.googlesource.com/c/go/+/444935 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Richard Musiol <neelance@gmail.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Richard Musiol <neelance@gmail.com> Reviewed-by: Richard Musiol <neelance@gmail.com>
2022-10-26cmd: remove redundant _cui fliter
Change-Id: Ia7e1e3679e03d125feb9708cb05bbd32c4954edb GitHub-Last-Rev: a62b72ea3edcf2b4f9f378cd03b1ac073ab80c74 GitHub-Pull-Request: golang/go#55957 Reviewed-on: https://go-review.googlesource.com/c/go/+/436879 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-18go,cmd,internal: update to anticipate missing targets and .a filesMichael Matloob
go/build and cmd/go will stop returing Targets for stdlib .a files, and stop producing the .a files is pkg/GOOS_GOARCH. update tests to anticipate that and to pass in importcfgs instead of expecting the compiler can find .a files in their old locations. Adds code to determine locations of .a files to internal/goroot. Also adds internal/goroot to dist's bootstrap directories and changes internal/goroot to build with a bootstrap version of Go. Change-Id: Ie81e51105bddb3f0e374cbf47e81c23edfb67fa5 Reviewed-on: https://go-review.googlesource.com/c/go/+/442303 Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-10-17cmd/link/internal/s390: return comparison directlycuiweixie
Change-Id: I171905d5cd7a121de549827ef4d5968510aa3efc Reviewed-on: https://go-review.googlesource.com/c/go/+/436705 Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: hopehook <hopehook@golangcn.org> Run-TryBot: Cherry Mui <cherryyz@google.com> Run-TryBot: xie cui <523516579@qq.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>