aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld
AgeCommit message (Collapse)Author
2026-02-03all: prealloc slice with possible minimum capabilitiesShulhan
2026-01-30all: switch linux-ppc64 target to ELFv2 ABIPaul Murphy
Go is only capable of producing internally linked, static binaries on linux-ppc64. As such, binaries should run in either ELFv1 or ELFv2 ppc64 userspaces today. This opens the door to enabling cgo and external linking which will require ELFv2 support and userspace, eventually. Fixes #76244 Change-Id: I5ca15037cbe546f352e8693dcf14da51a308b8ca Reviewed-on: https://go-review.googlesource.com/c/go/+/734540 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-01-29cmd/link: put type:* at the start of the type descriptorsIan Lance Taylor
That used to happen naturally because the symbol had zero size. After CL 724261 we need to force it. Fixes #77372 Change-Id: Ia8eef989bc9cbad5459b60ff6535136e7e0c6cab Reviewed-on: https://go-review.googlesource.com/c/go/+/740400 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-01-29cmd/link: remove AIX special case for first type descriptorIan Lance Taylor
It doesn't seem to be necessary, and removing it seems cleaner than adding an AIX case to the code in runtime.moduleTypelinks. Fixes #77365 Change-Id: I59fa56abf42e18017bd112481ea09d0cca47d105 Reviewed-on: https://go-review.googlesource.com/c/go/+/740220 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2026-01-29cmd/link: adjust symkind comparisons in XCOFF codeIan Lance Taylor
This XCOFF symkind comparison broke when STYPE moved in CL 723580. These comparisons are unmaintainable, but at least the new code is no worse than the old code. Change-Id: I1be9de6afdf1814aaadcd2105e6247a4b66b46fe Reviewed-on: https://go-review.googlesource.com/c/go/+/740200 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2026-01-29runtime, cmd/link: store type descriptor length, not endIan Lance Taylor
Storing the type descriptor length lets us save a relocation. It also avoids a problem for Darwin dynamic linking. For #6853 Fixes #77350 Change-Id: If5c94330fe10d75690325f3d0b0658060ef3eb2d Reviewed-on: https://go-review.googlesource.com/c/go/+/739681 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-01-27cmd/link, runtime: remove typelinksIan Lance Taylor
Instead of adding a typelinks section to a Go binary, mark the start and end of the typelinked type descriptors. The runtime can then step through the descriptors to find them all, rather than relying on the extra linker-generated offset list. The runtime steps through the type descriptors lazily, as many Go programs don't need the typelinks list at all. This reduces the size of cmd/go by 15K bytes, which isn't much but it's not nothing. A future CL will change the reflect package to use the type pointers directly rather than converting to offsets and then back to type pointers. For #6853 Change-Id: Id0af4ce81c5b1cea899fc92b6ff9d2db8ce4c267 Reviewed-on: https://go-review.googlesource.com/c/go/+/724261 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2026-01-27cmd/link: remove unused symbol kind SFUNCTABIan Lance Taylor
Change-Id: Ica7201dabe7f72b9470d8acbad043a34a20345a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/724121 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-01-27cmd/link: handle SRODATALRELRO in xcoffUpdateOuterSizeIan Lance Taylor
This is a followup to CL 723580. This fixes cgo builds on AIX. For #76038 Change-Id: Idea959615891f3f6e33932fae7a9043778db3366 Reviewed-on: https://go-review.googlesource.com/c/go/+/738920 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2026-01-23cmd/compile: redo how equality functions are generatedkhr@golang.org
Instead of generating an equality function for each type that needs it, generate one per "signature". A "signature" is a summary of the comparisons needed to check a type for equality. For instance, the type type S struct { i int32 j uint32 s string e error } Will have the signature "M8SI". M8 = 8 bytes of regular memory S = string I = nonempty interface This way, potentially many types that have the same signature can share the same equality function. The number of generated equality functions in the go binary is reduced from 634 to 286. The go binary is ~1% smaller. The generation of equality functions gets simpler (particularly, how we do inlining of sub-types, unrolling, etc.) and the generated code is probably a bit more efficient. The new function names are kind of weird, but will seldom show up for users. They will appear in cpu profiles, and in tracebacks in the situation where comparisons panic because an interface somewhere in the type being compared contains an uncomparable type (e.g. a slice). Note that this CL only affects generated comparison functions. It does not generally affect generated code for == (except when that code decides to call a comparison function as a subtask). Maybe a TODO for the future. Update #6853 Change-Id: I202bd6424cb6bf7c745a62c9603d4f01dc1a1fc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/725380 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
2026-01-22cmd/link: put type descriptors in .go.type sectionIan Lance Taylor
This change rewrites and simplifies the relro handling. We eliminate the separate relro SymKind values and the complex shifting of symbol kinds. Instead, we put the possible relro data into their own sections, and make those sections relro when appropriate. We put type descriptors and their associated data into a new .go.type section. As part of this we change the runtime.etypes symbol to be the end of the new section, rather than the end of rodata as it was before. We put function descriptors into a new .go.func section. Ordinary rodata relro stays in the .data.rel.ro section. We stop making the typelink section relro, as it only contains offsets and never has dynamic relocations. We drop the typerel:* and go:funcdescrel symbols. For #76038 Change-Id: I7aab7cfad3f2623ff06c09a70b756fe1e43f4169 Reviewed-on: https://go-review.googlesource.com/c/go/+/723580 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2025-12-15cmd/link: set canUsePlugins only on platforms that support pluginCherry Mui
If a program imports the plugin package, but the plugin build mode is not supported on the platform, it still cannot use plugin. Don't treat it like so. Updates #76815. Change-Id: I0fd719427d7c3cc96a94ce1f92d6e4457da92a90 Reviewed-on: https://go-review.googlesource.com/c/go/+/730164 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-12runtime, cmd/link: tighten search for stackObjectRecordIan Lance Taylor
A stackObjectRecord should always be in funcdata, between gofunc and the end of pclntab, except for the special case of methodValueCallFrameObjs, which should always be in noptrbss. Adjust the two loops that look for the moduledata corresponding to a stackObjectRecord to search more precisely, rather than relying on datap.end. Closely based on a patch by Michael Stapelberg. For #76038 Change-Id: I751801d8fd030af751825a67905b2a343280e7d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/728840 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-12-09cmd: fix some issues in the commentscuishuang
Change-Id: Id2c4152b43c7ee1a687e49da7dda5a690e554231 Reviewed-on: https://go-review.googlesource.com/c/go/+/727900 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org>
2025-12-08cmd/link: fix AIX builds after recent linker changesIan Lance Taylor
This updates XCOFF-specific code for the recent addition of funcdata to pclntab. Because XCOFF puts separate symbols into separate csects, each with their own alignment, it's important to tell the external linker the expected alignment of each part of pclntab. Otherwise the offsets within pclntab may change as the external linker aligns symbols. This CL sets the correct alignment for each pclntab child symbol, and sets pclntab's alignment to the max of that of its children. Tested on the GCC compile farm. Fixes #76486 Change-Id: I77d8a90c4b4b79d80ca11ede8d9a2aa9cc89f53f Reviewed-on: https://go-review.googlesource.com/c/go/+/725603 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-12-08cmd/link: generate DWARF for moduledataIan Lance Taylor
Fixes #76731 Change-Id: I5c686c91af8543b57880a89d30393912ef1958ad Reviewed-on: https://go-review.googlesource.com/c/go/+/727760 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-03cmd/link: don't update offset of existing ELF section nameIan Lance Taylor
Fixes #76656 Change-Id: If2e823ba1577700af00f5883e4ea5c139e4749c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/726100 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26cmd/link: put moduledata in its own .go.module sectionIan Lance Taylor
There is a test for this in CL 721480 later in this series. For #76038 Change-Id: Ib7ed1f0b0aed2d929ca0f135b54d6b62112cae30 Reviewed-on: https://go-review.googlesource.com/c/go/+/720660 TryBot-Bypass: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-11-26cmd/link, runtime, debug/gosym: move pclntab magic to internal/abiIan Lance Taylor
Change-Id: I2d3c41b0e61b994d7b04bd16a791fd226dc45269 Reviewed-on: https://go-review.googlesource.com/c/go/+/720302 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26cmd/link: put runtime.findfunctab in the .gopclntab sectionIan Lance Taylor
There is a test for this in CL 721461 later in this series. For #76038 Change-Id: I15f9a8d0d5bd9424702a9ca7febb2fa76035aaf8 Reviewed-on: https://go-review.googlesource.com/c/go/+/719743 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26cmd/link: put funcdata symbols in .gopclntab sectionIan Lance Taylor
There is a test for this in CL 721460 later in this series. For #76038 Change-Id: Icd7a52cbabde5162139dbc4b2c61306c0c748545 Reviewed-on: https://go-review.googlesource.com/c/go/+/719440 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-26cmd/link: build shstrtab from ELF sectionsIan Lance Taylor
Since before Go 1 the Go linker has handled ELF by first building the ELF section string table, and then pointing ELF section headers to it. This duplicates code as sections are effectively created twice, once with the name and then again with the full section header. The code duplication also means that it's easy to create unnecessary section names; for example, every internally linked Go program currently contains the string ".go.fuzzcntrs" although most do not have a section by that name. This CL changes the linker to simply build the section string table after all the sections are known. Change-Id: I27ba15b2af3dc1b8d7436b6c409f818aa8e6bfb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/718840 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26cmd/link: use shdr as a slice rather than counting in elfhdr.ShnumIan Lance Taylor
Change-Id: I293e50e3a6ab19fb927099e106095d6aa1241b9f Reviewed-on: https://go-review.googlesource.com/c/go/+/718820 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-26cmd/link: sort allocated ELF section headers by addressIan Lance Taylor
For an executable, emit the allocated section headers in address order, so that section headers are easier for humans to read. Change-Id: Ib5efb4734101e4a1f6b09d0e045ed643c79c7c0a Reviewed-on: https://go-review.googlesource.com/c/go/+/718620 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Bypass: David Chase <drchase@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-11-18cmd/link: align sections, not symbols after DWARF compressCherry Mui
After DWARF compression, we recompute the symbol and section addresses. On Windows, we need to align the sections to PEFILEALIGN. But the code actually apply the alignment to every symbol. This works mostly fine as after compression a section usually contains a single symbol (the compressed data). But if the compression is not beneficial, it leaves with the original set of symbols, which could be more than one. Applying alignment to every symbol causing the section size too big, no longer matching the size we computed before compression. Fixes #76022. Change-Id: I2246045955405997c77e54001bbb83f9ccd1ee7c Reviewed-on: https://go-review.googlesource.com/c/go/+/721340 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-11-18cmd/asm,cmd/compile,cmd/internal/obj/riscv: use compressed instructions on ↵Joel Sing
riscv64 Make use of compressed instructions on riscv64 - add a compress pass to the end of the assembler, which replaces non-compressed instructions with compressed alternatives if possible. Provide a `compressinstructions` compiler and assembler debug flag, such that the compression pass can be disabled via `-asmflags=all=-d=compressinstructions=0` and `-gcflags=all=-d=compressinstructions=0`. Note that this does not prevent the explicit use of compressed instructions via assembly. Note that this does not make use of compressed control transfer instructions - this will be implemented in later changes. Reduces the text size of a hello world binary by ~121KB and reduces the text size of the go binary on riscv64 by ~1.21MB (between 8-10% in both cases). Updates #71105 Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64 Change-Id: I24258353688554042c2a836deed4830cc673e985 Reviewed-on: https://go-review.googlesource.com/c/go/+/523478 Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-14cmd/link/internal/ld: make runtime.buildVersion with experiments validmatloob@golang.org
Specifically if there are experiments but no nonstandard toolchain suffix such as "-devel", the go version will not be valid according to go/version.IsValid. To fix that, always put the X: part into the suffix, resulting in, for example, go1.25.0-X:foo. Fixes #75953 Change-Id: I6a6a696468f3ba9b82b6a410fb88831428e93b58 Reviewed-on: https://go-review.googlesource.com/c/go/+/719701 Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-11-12cmd/link: change shdr and phdr from arrays to slicesIan Lance Taylor
Removes an arbitrary and unnecessary limit. Change-Id: Iba04568ed5e6b1a8f8f23369f51f068e830f1059 Reviewed-on: https://go-review.googlesource.com/c/go/+/718600 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-11-11std,cmd: go fix -any std cmdAlan Donovan
This change mechanically replaces all occurrences of interface{} by 'any' (where deemed safe by the 'any' modernizer) throughout std and cmd, minus their vendor trees. Since this fix is relatively numerous, it gets its own CL. Also, 'go generate go/types'. Change-Id: I14a6b52856c3291c1d27935409bca8d5fd4242a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/719702 Commit-Queue: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Alan Donovan <adonovan@google.com>
2025-11-07cmd/link: clean up some comments to Go standardsIan Lance Taylor
Also drop a couple of unused names. Change-Id: I0f09775a276c34ece7809cf5d3f7c6b8cd1fa487 Reviewed-on: https://go-review.googlesource.com/c/go/+/718580 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-06cmd/link: move pclntab out of relro sectionIan Lance Taylor
The .gopclntab section should not have any relocations. Move it out of relro to regular rodata. Note that this is tested by tests like TestNoTextrel in cmd/cgo/internal/testshared. The existing test TestMachoSectionsReadOnly looks for sections in a Mach-O file that are read-only after relocations are applied (this is marked by a segment with a flags field set to 0x10). We remove the __gopclntab section, as that section is now read-only at all times, not only after relocating. For #76038 Change-Id: I7f837e423bf1e802509277f5dc7fdd1ed0228e32 Reviewed-on: https://go-review.googlesource.com/c/go/+/718065 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2025-11-05cmd/link: support weak binding on darwinqmuntal
Symbols loaded from host files can have the N_WEAK_REF bit set, which is used to instruct the loader to not fail if that symbol can't be resolved. The Go internal linker should honor this information by setting the BIND_SYMBOL_FLAGS_WEAK_IMPORT flag in the corresponding bind table entry. Fixes #76023 Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64-longtest,gotip-darwin-amd64_12,gotip-darwin-arm64_12,gotip-darwin-arm64_15,gotip-darwin-arm64-longtest,gotip-darwin-amd64_14 Change-Id: Id2cef247ec7a9cb08455844f3c30ff874772bb7b Reviewed-on: https://go-review.googlesource.com/c/go/+/713760 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-04cmd/link, runtime: don't store text start in pcHeaderIan Lance Taylor
The textStart field requires a relocation, the only relocation in pclntab. And nothing uses it. So remove it. Replace it with a zero, which can itself be removed at some point in coordination with Delve. For #76038 Change-Id: I35675c0868c5d957bb375e40b804c516ae0300ca Reviewed-on: https://go-review.googlesource.com/c/go/+/717240 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2025-11-04cmd/link: don't generate .gosymtab sectionIan Lance Taylor
Since Go 1.2 the section is always empty. Also remove the code looking for .gosymtab in cmd/internal/objfile. For #76038 Change-Id: Icd34c870ed0c6da8001e8d32305f79905ee2b066 Reviewed-on: https://go-review.googlesource.com/c/go/+/717200 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Commit-Queue: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-11-04cmd/link: add and use new SymKind SFirstUnallocatedIan Lance Taylor
The linker sources in several places used SXREF to mark the first SymKind which is not allocated in memory. This is cryptic. Instead use SFirstUnallocated, following the example of the existing SFirstWritable. Change-Id: If326ad63027402699094bcc49ef860db3772f82a Reviewed-on: https://go-review.googlesource.com/c/go/+/715623 Reviewed-by: Than McIntosh <thanm@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-04cmd/link: remove misleading commentIan Lance Taylor
The comment suggests that the text section is briefly writable. That is not the case. As the earlier part of the comment explains, part of the text section is mapped twice, once r-x and once rw-. It is never the case that there is writable executable memory. Change-Id: I56841e19a8a08f2515f29752536a5c8f180ac8c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/715622 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27cmd/link: internal linking support for windows/arm64qmuntal
The internal linker was missing some pieces to support windows/arm64. Closes #75485 Cq-Include-Trybots: luci.golang.try:gotip-windows-arm64 Change-Id: I5c18a47e63e09b8ae22c9b24832249b54f544b7e Reviewed-on: https://go-review.googlesource.com/c/go/+/704295 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-21all: eliminate unnecessary type conversionsJes Cok
Found by github.com/mdempsky/unconvert Change-Id: I88ce10390a49ba768a4deaa0df9057c93c1164de GitHub-Last-Rev: 3b0f7e8f74f58340637f33287c238765856b2483 GitHub-Pull-Request: golang/go#75974 Reviewed-on: https://go-review.googlesource.com/c/go/+/712940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-10-11cmd/link: in TestFallocate, only check number of blocks on DarwinCherry Mui
The number-of-blocks check was introduced when fixing a Darwin- specific bug. On Darwin, the file allocation syscall is a bit tricky. On Linux and BSDs, it is more straightforward and unlikely to go wrong. The test itself, on the other hand, is less reliable on Linux (and perhaps BSDs), as it is considered less portable and is an implementation detail of the file system. Given these two reasons, only check it on Darwin. Fixes #75795. Change-Id: I3da891fd60a141c3eca5d0f5ec20c2cad65b8862 Reviewed-on: https://go-review.googlesource.com/c/go/+/711095 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2025-10-07Revert "cmd/compile: redo arm64 LR/FP save and restore"Keith Randall
This reverts commit 719dfcf8a8478d70360bf3c34c0e920be7b32994. Reason for revert: Causing crashes. Change-Id: I0b8526dd03d82fa074ce4f97f1789eeac702b3eb Reviewed-on: https://go-review.googlesource.com/c/go/+/709755 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-10-06cmd/compile: redo arm64 LR/FP save and restoreKeith Randall
Instead of storing LR (the return address) at 0(SP) and the FP (parent's frame pointer) at -8(SP), store them at framesize-8(SP) and framesize-16(SP), respectively. We push and pop data onto the stack such that we're never accessing anything below SP. The prolog/epilog lengths are unchanged (3 insns for a typical prolog, 2 for a typical epilog). We use 8 bytes more per frame. Typical prologue: STP.W (FP, LR), -16(SP) MOVD SP, FP SUB $C, SP Typical epilogue: ADD $C, SP LDP.P 16(SP), (FP, LR) RET The previous word where we stored LR, at 0(SP), is now unused. We could repurpose that slot for storing a local variable. The new prolog and epilog instructions are recognized by libunwind, so pc-sampling tools like perf should now be accurate. (TODO: except maybe after the first RET instruction? Have to look into that.) Update #73753 (fixes, for arm64) Update #57302 (Quim thinks this will help on that issue) Change-Id: I4800036a9a9a08aaaf35d9f99de79a36cf37ebb8 Reviewed-on: https://go-review.googlesource.com/c/go/+/674615 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-03cmd/link: add LIBRARY statement only with -buildmode=csharedqmuntal
When creating a .def file for Windows linking, add a LIBRARY statement only when building a DLL with -buildmode=cshared. That statement is documented to instruct the linker to create a DLL, overriding any other flag that might indicate building an executable. Fixes #75734 Change-Id: I0231435df70b71a493a39deb639f6328a8e354f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/708815 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Dominic Della Valle <ddvpublic@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-03cmd/link: support .def file with MSVC clang toolchainCherry Mui
lld-link supports .def file, but requires a "-def:" (or "/def:") flag. (MinGW linker, on the other hand, requires no flag.) Pass the flag when using MSVC-based toolchain. CL originally authored by Chressie Himpel. Change-Id: I8c327ab48d36b0bcbb1d127cff544ffdb06be38e Reviewed-on: https://go-review.googlesource.com/c/go/+/708716 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Chressie Himpel <chressie@google.com>
2025-09-30cmd/link/internal/arm64: support Mach-O ARM64_RELOC_SUBTRACTOR in internal ↵qmuntal
linking ARM64_RELOC_SUBTRACTOR is the arm64 version of X86_64_RELOC_SUBTRACTOR, which has been recently implemented in CL 660715. The standard library still doesn't need it, but I've found it necessary when statically linking against a library I own. Change-Id: I138281b12f2304e3673f7dc92f7137e48bf68fdd Reviewed-on: https://go-review.googlesource.com/c/go/+/703316 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-09-30cmd/link/internal/arm64: support Mach-O ARM64_RELOC_POINTER_TO_GOT in ↵qmuntal
internal linking ARM64_RELOC_POINTER_TO_GOT is the arm64 version of X86_64_RELOC_GOT, which has been support for many years now. The standard library still doesn't need it, but I've found it necessary when statically linking against a library I own. Change-Id: I8eb7bf3c74aed663a1fc00b5dd986057130f7f7a Reviewed-on: https://go-review.googlesource.com/c/go/+/703315 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-09-29cmd/link: use a .def file to mark exported symbols on Windowsqmuntal
Binutils defaults to exporting all symbols when building a Windows DLL. To avoid that we were marking symbols with __declspec(dllexport) in the cgo-generated headers, which instructs ld to export only those symbols. However, that approach makes the headers hard to reuse when importing the resulting DLL into other projects, as imported symbols should be marked with __declspec(dllimport). A better approach is to generate a .def file listing the symbols to export, which gets the same effect without having to modify the headers. Updates #30674 Fixes #56994 Change-Id: I22bd0aa079e2be4ae43b13d893f6b804eaeddabf Reviewed-on: https://go-review.googlesource.com/c/go/+/705776 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-29cmd/link: don't pass -Wl,-S on SolarisCherry Mui
Solaris linker's -S has a different meaning. Fixes #75637. Change-Id: I51e641d5bc6d7f64ab5aa280090c70ec787a1fbf Reviewed-on: https://go-review.googlesource.com/c/go/+/707096 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-09-29cmd/link: use correct length for pcln.cutabIan Lance Taylor
The pcln.cutab slice holds uint32 elements, as can be seen in the runtime.moduledata type. The slice was being created with the len (and cap) set to the size of the slice, which means that the count was four times too large. This patch sets the correct len/cap. This doesn't matter for the runtime because nothing looks at the len of cutab. Since the incorrect len is larger, all valid indexes remain valid. Using the correct length means that more invalid indexes will be caught at run time, but such cases are unlikely. Still, using the correct len is less confusing. While we're here use the simpler sliceSym for pcln.pclntab. Change-Id: I09f680b3287467120d994b171c86c784085e3d27 Reviewed-on: https://go-review.googlesource.com/c/go/+/707595 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2025-09-26cmd/link: don't pass -Wl,-S on AIXCherry Mui
The AIX linker's -S flag has a different meaning. Don't pass it. Updates #75618. Change-Id: I98faabea3435cde255f4c2d25f34dde9f69b7ec9 Reviewed-on: https://go-review.googlesource.com/c/go/+/707097 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-09-25cmd/link: handle -w flag in external linking modeCherry Mui
Currently, when the -w flag is set, it doesn't actually disable the debug info generation with in external linking mode. (It does make the Go object have no debug info, but C objects may still have.) Pass "-Wl,-S" to let the external linker disable debug info generation. Change-Id: I0fce56b9f23a45546b69b9e6dd027c5527b1bc87 Reviewed-on: https://go-review.googlesource.com/c/go/+/705857 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>