aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/data.go
AgeCommit message (Collapse)Author
2026-03-31cmd/link, runtime: record size of itabsIan Lance Taylor
We were depending on runtime.etypes immediately following the itabs. However, on AIX, runtime.etypes, as a zero-sized symbol, can float when using external linking. It won't necessarily stay right at the end of the itabs. Rather than worry about this, just record the size of the itab data. In practice it almost always works on AIX, but it fails the runtime test TestSchedPauseMetrics/runtime/debug.WriteHeapDump, which fails when iterating over all the itabs. Tested on AIX. This should fix AIX on the build dashboard. Change-Id: Id3a113b75b93fa8440c047e92f764ab81423df48 Reviewed-on: https://go-review.googlesource.com/c/go/+/760203 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: Junyang Shao <shaojunyang@google.com>
2026-03-26cmd/link: group gcmask symbols, move them to noptrbssIan Lance Taylor
Also take them out of the symbol table. A new symbol runtime.gcmask.* marks where they start in BSS, and can be used to find them if anybody cares. Also stop checking for gcprog symbols that we no longer define. Change-Id: I4060d8e9350c20568f020172caacd0439337cd2d Reviewed-on: https://go-review.googlesource.com/c/go/+/729880 Reviewed-by: Dmitri Shuralyov <dmitshur@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>
2026-03-26runtime, cmd/link: remove itablinksIan Lance Taylor
Instead of keeping a separate list of pointers to itabs, just walk through the itabs themselves. For #6853 Change-Id: If030bd64fbd01d73b0bf8495f6c9826ed2e61568 Reviewed-on: https://go-review.googlesource.com/c/go/+/729201 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2026-03-25cmd/link: fix host object's .pdata entries orderqmuntal
Host objects are expected to have their .pdata entries in the correct order, but the Go internal linker might reorder some of the functions associated with the .pdata entries. This causes the .pdata section in the final binary to have entries in the wrong order, and therefore issues with unwinding on Windows. The fix is to treat the .pdata entries of host objects as individual symbols that will be retained only if the function they are associated with is retained. Also, those entries will be sorted together with the .pdata entries emitted by the Go compiler, ensuring the correct order in the final binary. Fixes #65116 Change-Id: I421471b2aef519b0c20707a40c4b7957db5d2ed5 Reviewed-on: https://go-review.googlesource.com/c/go/+/754080 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> 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-03-10cmd/link: put itabs in the .go.type sectionIan Lance Taylor
For #76038 Change-Id: I4c30d5854fcaacc7fd7f84b4679a5be30379122d Reviewed-on: https://go-review.googlesource.com/c/go/+/729200 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> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Pagol Mon <mpagol707@gmail.com>
2026-03-06cmd/link: sort .pdata by function start addressqmuntal
Loosely based on CL 678795. The PE/COFF spec requires RUNTIME_FUNCTION entries in the .pdata section to be ordered by their function start address. Previously the linker emitted them in symbol order. An unsorted table triggers the MSVC linker error: fatal error LNK1223: invalid or corrupt file: file contains invalid .pdata contributions Fixes #65116. Change-Id: I589cb4e6787a9edb34400b56e60fe23065b59162 Reviewed-on: https://go-review.googlesource.com/c/go/+/743820 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2026-02-12cmd/link: handle runtime.type based on size, not GOOSIan Lance Taylor
When handling type descriptors, we add some space at the start to ensure that offset 0 does not refer to a valid type descriptor. AIX has an initial runtime.types symbol with a non-zero size, so we used that instead of adding some space. In some cases Darwin also has a runtime.types symbol with a non-zero size. Before CL 727021, this was always fine, because the 8 byte size of runtime.types was swamped by the 32-byte alignment of type descriptors. That didn't work for AIX with the external linker, because on AIX the external linker lays out each symbol separately. Darwin doesn't have that problem, so the layout of the internal linker was preserved. However, CL 727021 changed the alignment of type descriptors to 8. That means that on Darwin the 8 byte size of runtime.types was no longer hidden by the alignment. In effect we were skipping twice: once for runtime.types, and then again explicitly. This only failed when runtime.types has a non-zero size, which is only in a few specific cases. This CL cleans this up by not skipping explicitly in any case where runtime.types has a non-zero size. That handles both AIX and Darwin consistently. To make this clearer, I changed the skip from a single byte to the size of a pointer in all cases. I considered always giving runtime.types a non-zero size, but that is a bigger change, and potentially confusing since there really isn't any data associated with runtime.types. The cases where we must give it a non-zero size are special, and I think it's simpler to keep it that way. For #6853 For #36313 Fixes #77569 Change-Id: I22ebbd0194527ecca96d48849aa00a4fc899e55c Reviewed-on: https://go-review.googlesource.com/c/go/+/744820 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2026-02-06cmd/link: use correct alignment for type descriptors on AIXIan Lance Taylor
CL 724261 changed the linker to put all type descriptors that are used for typelinks in a single list. This caused trouble on AIX when linking externally, because the AIX linker aligns symbols individually, rather than honoring the layout of the object file generated by the internal linker. I fixed internal linking problems with CL 740220, but that just made things worse for the external linker. This CL rolls back 740220, and adds commentary. With this CL we force a smaller alignment for type descriptors, use the same alignment for runtime.types and type:*, and use a consistent size for runtime.types in all cases. With this change all the type descriptor related code passes again on AIX, except for the new TestTypePlacement test which I will fix in a followup CL. Fixes #77400 Change-Id: I9f25847eb0588001cb4ce453f211a655400d6a59 Reviewed-on: https://go-review.googlesource.com/c/go/+/740820 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-02-06cmd/link: align covctrs symbolKeith Randall
If we start the covctrs blob at an odd alignment, then covctrs will not be correctly aligned. Each individual entry is aligned properly, but the start marker may be before any padding inserted to enforce that alignment. Fixes #58936 Change-Id: I802fbe40eacfa5a3c8c4864e078b0e078da956d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/733740 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>
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-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-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-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: 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-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-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-09-11cmd/link: allow one to specify the data section in the internal linkerKevaundray Wedderburn
Fixes #74945 Change-Id: Ia73a8dcdf707222e822522daaa7f31a38b1c31e6 GitHub-Last-Rev: da1526ad8cebd5cfa2f979d49d86f3424d192ce0 GitHub-Pull-Request: golang/go#75117 Reviewed-on: https://go-review.googlesource.com/c/go/+/698355 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-07-16cmd/link, runtime: on Wasm, put only function index in method table and func ↵Cherry Mui
table In the type descriptor's method table, it contains relative PCs of the methods (relative to the start of the text section) stored as 32-bit offsets. On Wasm, a PC is PC_F<<16 + PC_B, where PC_F is the function index, and PC_B is the block index. When there are more than 65536 functions, the PC will not fit into 32-bit (and relative to the section start doesn't help). Since there are no more bits for the function index, and the method table always targets the entry of a method, we put just the PC_F there, and rewrite back to a full PC at run time when we need the PC. This way we can have more than 65536 functions. The func table also contains 32-bit relative PCs, and it also always points to function entries. Do the same there, as well as other places where we use relative text offsets. Also add the relocation type in the relocation overflow error message. Also add check for function too big on Wasm. If a function has more than 65536 blocks, PC_B will overflow and PC = PC_F<<16 + PC_B will points to the wrong function. Fixes #64856. Change-Id: If9c307e9fb1641f367a5f19c39f88f455805d0bb Reviewed-on: https://go-review.googlesource.com/c/go/+/552835 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-15cmd/link: fix outdated output mmap checkZxilly
Outbuf.View used to perform a mmap check by default and return an error if the check failed, this behavior has been changed so that now the View never returns any error, so the usage needs to be modified accordingly. Change-Id: I76ffcda5476847f6fed59856a5a5161734f47562 GitHub-Last-Rev: 6449f2973d28c3b4a5c9e289c38dfcc38f83b3d9 GitHub-Pull-Request: golang/go#73730 Reviewed-on: https://go-review.googlesource.com/c/go/+/673095 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-12cmd/link: use >4GB base address for 64-bit PE binariesqmuntal
Windows prefers 64-bit binaries to be loaded at an address above 4GB. Having a preferred base address below this boundary triggers a compatibility mode in Address Space Layout Randomization (ASLR) on recent versions of Windows that reduces the number of locations to which ASLR may relocate the binary. The Go internal linker was using a smaller base address due to an issue with how dynamic cgo symbols were relocated, which has been fixed in this CL. Fixes #73561. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest Change-Id: Ia8cb35d57d921d9be706a8975fa085af7996f124 Reviewed-on: https://go-review.googlesource.com/c/go/+/671515 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-04-03cmd/link/internal/ld: introduce -funcalign=N optionAleksey Markin
This patch adds linker option -funcalign=N that allows to set alignment for function entries. This CL is based on vasiliy.leonenko@gmail.com's cl/615736. For #72130 Change-Id: I57e5c9c4c71a989533643fda63a9a79c5c897dea Reviewed-on: https://go-review.googlesource.com/c/go/+/660996 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>
2025-03-13cmd/go/internal/load,cmd/link/internal/ld: use ↵Jes Cok
objabi.LookupPkgSpecial(pkg).Runtime As suggested by Michael in CL 655515. Change-Id: Idf0b879287bd777d03443aebc7351fcb0d724885 GitHub-Last-Rev: 58eda020f5310f873674f56903facec4f212d6c0 GitHub-Pull-Request: golang/go#72806 Reviewed-on: https://go-review.googlesource.com/c/go/+/656856 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-11runtime/internal: clean up completelyJes Cok
We've been slowly moving packages from runtime/internal to internal/runtime. For now, runtime/internal only has test packages. It's a good chance to clean up the references to runtime/internal in the toolchain. For #65355. Change-Id: Ie6f9091a44511d0db9946ea6de7a78d3afe9f063 GitHub-Last-Rev: fad32e2e81d11508e734c3c3d3b0c1da583f89f5 GitHub-Pull-Request: golang/go#72137 Reviewed-on: https://go-review.googlesource.com/c/go/+/655515 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-02-25cmd/link: put .got section in __DATA_CONST segmentqmuntal
On Darwin, the .got section can be placed in a read-only segment. Only the dynamic linker should modify it at start-up time. Other read-only sections, like .typelink and .itablink, are already placed in the __DATA_CONST segment. Do the same for the .got section. Fixes #71416. Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64-longtest Change-Id: I9cd9c20da63b655fabb61d742feb086c3ef3bea7 Reviewed-on: https://go-review.googlesource.com/c/go/+/644055 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-02-22cmd: initial compiler+linker support for DWARF5 .debug_addrThan McIntosh
This patch rolls the main .debug_info DWARF section from version 4 to version 5, and also introduces machinery in the Go compiler and linker for taking advantage of the DWARF5 ".debug_addr" section for subprogram DIE "high" and "low" PC attributes. All functionality is gated by GOEXPERIMENT=dwarf5. For the compiler portion of this patch, we add a new DIE attribute form "DW_FORM_addrx", which accepts as an argument a function (text) symbol. The dwarf "putattr" function is enhanced to handle this format by invoking a new dwarf context method "AddIndirectTextRef". Under the hood, this method invokes the Lsym method WriteDwTxtAddrx, which emits a new objabi.R_DWTXTADDR_* relocation. The size of the relocation is dependent on the number of functions in the package; we pick a size that is just big enough for the largest func index. In the linker portion of this patch, we now switch over to writing out a version number of 5 (instead of 4) in the compile unit header (this is required if we want to use addrx attributes). In the parallel portion of DWARF gen, within each compilation unit we scan subprogram DIEs to look for R_DWTXTADDR_* relocations, and when we find such a reloc, we assign a slot in the .debug_addr section for the func targeted. After the parallel portion is complete, we then walk through all of the compilation units to assign a value to their DW_AT_addr_base attribute, which points to the portion of the single .debug_addr section containing the text addrs for that compilation unit. Note that once this patch is in, programs built with GOEXPERIMENT=dwarf5 will have broken/damaged DWARF info; in particular, since we've changed only the CU and subprogram DIEs and haven't incorported the other changes mandated by DWARF5 (ex: .debug_ranges => .debug_rnglists) a lot of the variable location info will be missing/incorrect. This will obviously change in subsequent patches. Note also that R_DWTXTADDR_* can't be used effectively for lexical scope DIE hi/lo PC attrs, since there isn't a viable way to encode "addrx + constant" in the attribute value (you would need a new entry for each attr endpoint in .debug_addr, which would defeat the point). Updates #26379. Change-Id: I2dfc45c9a8333e7b2a58f8e3b88fc8701fefd006 Reviewed-on: https://go-review.googlesource.com/c/go/+/635337 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-02-22cmd/link, cmd/internal/objabi: remove R_DWARFFILEREF relocation typeThan McIntosh
Get rid of the R_DWARFFILEREF relocation type -- we have not used this relocation for a while now, ever since jfaller's revamp of the DWARF line table file section in Go 1.15. No change in compiler or linker functionality; this is purely a dead code cleanup. Change-Id: I178760c87f3aa79694cfabe7364ca382605c6975 Reviewed-on: https://go-review.googlesource.com/c/go/+/633876 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>
2024-12-23cmd/link, runtime: apply a delta to RODATA->DATA relocationsCherry Mui
On AIX, an R_ADDR relocation from an RODATA symbol to a DATA symbol does not work, as the dynamic loader can change the address of the data section, and it is not possible to apply a dynamic relocation to RODATA. In order to get the correct address, we apply the delta between unrelocated and relocated data section addresses at run time. The linker saves both the unrelocated and the relocated addresses, so we can compute the delta. This is possible because RODATA symbols are generated by the compiler and so we have full control of. On AIX, the only case is the on-demand GC pointer masks from the type descriptors, for very large types. Perhaps there is a better way. Fixes #70483. Change-Id: I2664c0a813b38f7b146794cb1e73ccf5e238ca65 Reviewed-on: https://go-review.googlesource.com/c/go/+/638016 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>
2024-12-16cmd/link: update runtime dependency listCherry Mui
There have been a number of internal packages that the runtime package depends on. Update the list. We should stop using a hard- coded list. Change-Id: I6f9338d6690d955b8200f3301addd0e133a1bfe2 Reviewed-on: https://go-review.googlesource.com/c/go/+/636478 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2024-11-22cmd/compile, cmd/link: FIPS fixes for large programsRuss Cox
1. In cmd/internal/obj, only apply the exclusion list to data symbols. Text symbols are always fine since they can use PC-relative relocations. 2. In cmd/link, only skip trampolines for text symbols in the same package with the same type. Before, all text symbols had type STEXT, but now that there are different sections of STEXT, we can only rely on symbols in the same package in the same section being close enough not to need trampolines. Fixes #70379. Change-Id: Ifad2bdd6001ad3b5b23e641127554e9ec374715e Reviewed-on: https://go-review.googlesource.com/c/go/+/631036 Auto-Submit: 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>
2024-11-21cmd/link: remove debugging dregRuss Cox
I left this behind accidentally. Change-Id: I70f97b8214775e89c612890aead26431c9a443a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/630575 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-11-18runtime: get rid of gc programs for typesKeith Randall
Instead, have the runtime build the gc bitmaps on demand at runtime. Change-Id: If7a245bc62e4bce3ce80972410b0ed307d921abe Reviewed-on: https://go-review.googlesource.com/c/go/+/616255 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>
2024-11-18cmd/link: use types (and not GC programs) to build data/bss ptrmaskskhr@golang.org
The linker knows the types of the global variables. We can use those types to build the GC programs that describe the data and bss pointer masks. That way we don't use the GC programs of the constituent types. This is part of an effort to remove GC programs from the runtime. There's a major complication in that when we're linking against a shared library (typically, libstd.so), the relocations we need to break apart arrays and structs into constituent types are difficult to find. Load that additional data when linking against shared libraries. Change-Id: I8516b24a0604479895c7b8a8a358d3cd8d421530 Reviewed-on: https://go-review.googlesource.com/c/go/+/546216 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>
2024-11-13cmd/compile, cmd/link: add FIPS verification supportRuss Cox
For FIPS init-time code+data verification, we need to arrange to put the FIPS symbols into contiguous regions of the executable and then record those sections along with the expected checksum. The cmd/internal/obj changes identify the FIPS symbols and give them distinguished types, which the linker then places in contiguous regions. The linker also writes out information to use at run time to find the FIPS sections, along with the expected hash. See cmd/internal/obj/fips.go and cmd/link/internal/ld/fips.go for more details. The code is disabled in this commit. CL 625998 and 625999 adds tests. CL 626000 enables the code. For #69536. Change-Id: I48da6db94bc0bea7428c43d4abcf999527bccfcd Reviewed-on: https://go-review.googlesource.com/c/go/+/625997 Auto-Submit: 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>
2024-11-07cmd/link: remove dummy argument from ld.ErrorfRuss Cox
As the comment notes, all calls to Errorf now pass nil, so remove that argument entirely. There is a TODO to remove uses of Errorf entirely, but that seems wrong: sometimes there is no symbol on which to report the error, and in that situation, Errorf is appropriate. So clarify that in the docs. Change-Id: I92b3b6e8e3f61ba8356ace8cd09573d0b55d7869 Reviewed-on: https://go-review.googlesource.com/c/go/+/625617 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-11-06cmd/link/internal/ld: fix sort comparisonRuss Cox
Strictly speaking, the sort comparison was inconsistent (and therefore invalid) for the sort-by-name case, if you had a size 0 b size 1 c size 0 zerobase That would result in the inconsistent comparison ordering: a < b (by name) b < c (by name) c < zerobase (by zerobase rule) zerobase < b (by zerobase rule) This can't happen today because we only disable size-based sort in a segment that has no zerobase symbol, but it's confusing to reason through that, so clean up the code anyway. Passes golang.org/x/tools/cmd/toolstash/buildall. Change-Id: I21e4159cdedd2053952ba960530d1b0f28c6fb24 Reviewed-on: https://go-review.googlesource.com/c/go/+/625615 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-25cmd/link: for asan align coverage counter section to 8 bytesIan Lance Taylor
Fixes #66966 Change-Id: I92777a7d7d8afaa82ffcd605aa3e607289b645f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/622477 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-09cmd/link: add support for trampoline insertation on loong64limeidan
Change-Id: I58c861d8403a77c1f3b55207d46076ba76eb1d45 Reviewed-on: https://go-review.googlesource.com/c/go/+/540755 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn>
2024-07-29debug/buildinfo: improve format documentationMichael Pratt
Existing documentation is a bit sparse, and more importantly focuses almost entirely on the old pre-1.18 format, with the new format as an afterthought. Since the new format is the primary format, make it more prominent. Updates #68592. Change-Id: I108ecde1b33650b4812fa5d278b08cb9197f6329 Reviewed-on: https://go-review.googlesource.com/c/go/+/601456 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2024-07-27cmd/link: pass architecture to isPLTCalllimeidan
The relocation number of each architecture starts from 0. objabi.ElfRelocOffset + objabi.RelocType(xxx) cannot uniquely represent a relocation, so the new argument 'arch' was added to help identify relocation. Change-Id: Ic8121dbfd1a4f31f279d50ffdc9c932ce3066efd Reviewed-on: https://go-review.googlesource.com/c/go/+/580275 Commit-Queue: abner chenc <chenguoqi@loongson.cn> 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> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Auto-Submit: abner chenc <chenguoqi@loongson.cn>
2024-06-12cmd/link: put runtime.end in the last section of data segmentCherry Mui
Currently the runtime.end symbol is put into the noptrbss section, which is usually the last section, except that when fuzzing is enabled, the last section is actually .go.fuzzcntrs. The runtime.end symbol has the value pointing to the end of the data segment, so if it is not in the last section, the value will not actually be in the range of the section. This causes an assertion failure in the new Apple linker. This CL fixes this by putting it in the last section. Fixes #65169. Change-Id: I5c991c46a0483a96e5f6e0255a3b444953676026 Reviewed-on: https://go-review.googlesource.com/c/go/+/592095 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-10cmd/link/internal/ld: fix overlapping sections in ELF relro linksThan McIntosh
This patch fixes a problem with how the .dynamic and .got sections are handled during PIE linking on ELF targets. These sections were being given addresses that overlapped with the .data.rel.ro section, which resulted in binaries that worked correctly but confused the binutils "strip" tool (which, confusingly, produced non-working stripped output when used on Go PIE binaries without returning a non-zero exit status). The new RELRO PIE code path preserves .dynamic and .got as their own independent sections, while ensuring that they make it into the RELRO segment. A new test verifies that we can successfully strip and run Go PIE binaries, and also that we don't wind up with any sections whose address ranges overlap. Fixes #67261. Updates #45681. Change-Id: If874be05285252a9b074d4a1fc6a4023b9a28b5e Reviewed-on: https://go-review.googlesource.com/c/go/+/584595 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-22cmd/link: move .dynamic and .got sections to relro if applicableThan McIntosh
This is the second of two CLs to roll forward the changes in CL 473495, which was subsequently reverted. In this patch we move the .dynamic and .got sections from the writable data segment to the relro segment if the platform supports relro and we're producing a PIE binary, and also moves .got.plt into relro if eager binding is in effect (e.g. -bindnow or -Wl,-z,now). Updates #45681. Change-Id: I9f4fba6e825b96d1b5e27fb75844450dd0a650b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/571417 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-04-02internal/abi: clean up type of Kind and Type.Kind_Austin Clements
Currently, Type.Kind_ is a uint8, Kind is a uint, and some of the abi.Kind consts are not of type Kind. Clean this all up by making Kind a uint8, then making Type.Kind a Kind, and finally making all Kind consts actually have type Kind. This has some ripple effect, but I think all of the changes are improvements. Change-Id: If39be74699c2cdb52bf0ad7092d392bc8fb68d15 Reviewed-on: https://go-review.googlesource.com/c/go/+/575579 Auto-Submit: Austin Clements <austin@google.com> 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>
2024-02-16cmd/link: add -randlayout flag to randomize function orderingCherry Mui
Sometimes we found that benchmark results may strongly depend on the ordering of functions laid out in the binary. This CL adds a flag -randlayout=seed, which randomizes the function layout (in a deterministic way), so can verify the benchmark results against different function ordering. Change-Id: I85f33881bbfd4ca6812fbd4bec00bf475755a09e Reviewed-on: https://go-review.googlesource.com/c/go/+/562157 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>