aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/goobj/objfile.go
AgeCommit message (Collapse)Author
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-01-20all: fix typos in go file commentsMarcel Meyer
This is the second round to look for spelling mistakes. This time the manual sifting of the result list was made easier by filtering out capitalized and camelcase words. grep -r --include '*.go' -E '^// .*$' . | aspell list | grep -E -x '[A-Za-z]{1}[a-z]*' | sort | uniq This PR will be imported into Gerrit with the title and first comment (this text) used to generate the subject and body of the Gerrit change. Change-Id: Ie8a2092aaa7e1f051aa90f03dbaf2b9aaf5664a9 GitHub-Last-Rev: fc2bd6e0c51652f13a7588980f1408af8e6080f5 GitHub-Pull-Request: golang/go#57737 Reviewed-on: https://go-review.googlesource.com/c/go/+/461595 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2022-11-10cmd/internal/obj: reduce allocations in object file writingCherry Mui
Some object file writer functions are structured like, having a local variable, setting fields, then passing it to a Write method which eventually calls io.Writer.Write. As the Write call is an interface call it escapes the parameter, which in turn causes the local variable to be heap allocated. To reduce allocation, use pre-allocated scratch space instead. Reduce number of allocations in the compiler: name old allocs/op new allocs/op delta Template 679k ± 0% 644k ± 0% -5.17% (p=0.000 n=20+20) Unicode 603k ± 0% 581k ± 0% -3.67% (p=0.000 n=20+20) GoTypes 3.83M ± 0% 3.63M ± 0% -5.30% (p=0.000 n=20+20) Compiler 353k ± 0% 342k ± 0% -3.09% (p=0.000 n=18+19) SSA 31.4M ± 0% 30.4M ± 0% -3.02% (p=0.000 n=20+20) Flate 397k ± 0% 373k ± 0% -5.92% (p=0.000 n=20+18) GoParser 777k ± 0% 735k ± 0% -5.37% (p=0.000 n=20+20) Reflect 2.07M ± 0% 1.90M ± 0% -7.89% (p=0.000 n=18+20) Tar 605k ± 0% 568k ± 0% -6.26% (p=0.000 n=19+16) XML 801k ± 0% 766k ± 0% -4.36% (p=0.000 n=20+20) [Geo mean] 1.18M 1.12M -5.02% Change-Id: I9d02a72e459e645527196ac54b6ee643a5ea6bd3 Reviewed-on: https://go-review.googlesource.com/c/go/+/449637 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-10-14cmd/compile,cmd/link,runtime: add start line numbers to func metadataMichael Pratt
This adds the function "start line number" to runtime._func and runtime.inlinedCall objects. The "start line number" is the line number of the func keyword or TEXT directive for assembly. Subtracting the start line number from PC line number provides the relative line offset of a PC from the the start of the function. This helps with source stability by allowing code above the function to move without invalidating samples within the function. Encoding start line rather than relative lines directly is convenient because the pprof format already contains a start line field. This CL uses a straightforward encoding of explictly including a start line field in every _func and inlinedCall. It is possible that we could compress this further in the future. e.g., functions with a prologue usually have <line of PC 0> == <start line>. In runtime.test, 95% of functions have <line of PC 0> == <start line>. According to bent, this is geomean +0.83% binary size vs master and -0.31% binary size vs 1.19. Note that //line directives can change the file and line numbers arbitrarily. The encoded start line is as adjusted by //line directives. Since this can change in the middle of a function, `line - start line` offset calculations may not be meaningful if //line directives are in use. For #55022. Change-Id: Iaabbc6dd4f85ffdda294266ef982ae838cc692f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/429638 Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-12cmd/link: remove name expansion logicCherry Mui
Now both the compiler and the assembler require the -p flag and emit full package path in symbol names, we no longer need to do the name expansion in the linker. Delete it. Change-Id: I771d4d97987a0a17414881b52806d600ef4cc351 Reviewed-on: https://go-review.googlesource.com/c/go/+/404300 Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-05-11cmd/asm: require -p flagCherry Mui
CL 391014 requires the compiler to be invoked with the -p flag, to specify the package path. Later, CL 394217 makes the compiler to produce an unlinkable object file, so "go tool compile x.go" can still be used on the command line. This CL does the same for the assembler, requiring -p, otherwise generating an unlinkable object. No special case for the main package, as the main package cannot be only assembly code, and there is no way to tell if it is the main package from an assembly file. Now we guarantee that we always have an expanded package path in the object file. A later CL will delete the name expansion code in the linker. Change-Id: I8c10661aaea2ff794614924ead958d80e7e2487d Reviewed-on: https://go-review.googlesource.com/c/go/+/404298 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-05-11cmd/internal/obj: add a flag to not write referenced symbol names in object fileCherry Mui
The Go object file references (some of) symbols from other packages by indices, not by names. The linker doesn't need the symbol names to do the linking. The names are included in the object file so it is self-contained and tools (objdump, nm) can read the referenced symbol names. Including the names increases object file size. Add a flag to disable it on demand (off by default). Change-Id: I143a0eb656997497c750b8eb1541341b2aee8f30 Reviewed-on: https://go-review.googlesource.com/c/go/+/404297 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-05-05cmd: use 128-bit SHA256 & encode in base64 for content hashesRuss Cox
We used to use SHA1 for content hashes, but CL 402595 changed all the “don't care” hashes to cmd/internal/notsha256 (negated SHA256). This made object files a little bit bigger: fmt.a on my Mac laptop grows from 910678 to 937612 bytes (+3%). To remove that growth, truncate the hash we use for these purposes to 128 bits (half a SHA256), and also use base64 instead of hex for encoding it when a string form is needed. This brings fmt.a down to 901706 bytes (-1% from original, -4% from current). Change-Id: Id81da1cf3ee85ed130b3cda73aa697d8c0053a62 Reviewed-on: https://go-review.googlesource.com/c/go/+/404294 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-04-29[dev.boringcrypto] cmd: use notsha256 instead of md5, sha1, sha256Russ Cox
When we add GOEXPERIMENT=boringcrypto, the bootstrap process will not converge if the compiler itself depends on the boringcrypto cgo-based implementations of sha1 and sha256. Using notsha256 avoids boringcrypto and makes bootstrap converge. Removing md5 is not strictly necessary but it seemed worthwhile to be consistent. For #51940. Change-Id: Iba649507e0964d1a49a1d16e463dd23c4e348f14 Reviewed-on: https://go-review.googlesource.com/c/go/+/402595 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: fix various doc comment formatting nitsRuss Cox
A run of lines that are indented with any number of spaces or tabs format as a <pre> block. This commit fixes various doc comments that format badly according to that (standard) rule. For example, consider: // - List item. // Second line. // - Another item. Because the - lines are unindented, this is actually two paragraphs separated by a one-line <pre> block. This CL rewrites it to: // - List item. // Second line. // - Another item. Today, that will format as a single <pre> block. In a future release, we hope to format it as a bulleted list. Various other minor fixes as well, all in preparation for reformatting. For #51082. Change-Id: I95cf06040d4186830e571cd50148be3bf8daf189 Reviewed-on: https://go-review.googlesource.com/c/go/+/384257 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-22cmd/compile, cmd/link: produce unlinkable object when compile without -pCherry Mui
CL 391014 requires the compiler to be invoked with the -p flag, to specify the package path. People are used to run "go tool compile" from the command line with the -p flag. This is mostly for simple testing, or debugging the compiler. The produced object file is almost never intended to be linked. This CL makes the compiler allow "go tool compile" without the -p flag again. It will produce an unlinkable object. If the linker sees such an object it will error out. Change-Id: I7bdb162c3cad61dadd5c456d903b92493a3df20f Reviewed-on: https://go-review.googlesource.com/c/go/+/394217 Trust: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-28cmd/internal/goobj: bump version numberCherry Mui
There have a few updates to the Go object file in this cycle (e.g. FuncInfo format change, some changes in constant values), and it is not compatible with the old tools. Bump up the version number. Change-Id: Id176979b139c76ded2c50f2678eb313934326d6f Reviewed-on: https://go-review.googlesource.com/c/go/+/359483 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-10-20cmd/internal/goobj: minor dead code cleanupThan McIntosh
Remove a bit of dead code from the Go object file reader (io.ReaderAt no longer needed in goobj.Reader). Change-Id: I04150d37fb90b59c9dbe930878d4dd21cdcd7ca7 Reviewed-on: https://go-review.googlesource.com/c/go/+/357309 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-09-28cmd/internal/objfile: use aux symbol for pcdata referencesCherry Mui
Pcdata are now separate aux symbols. Read them from aux, instead of using funcinfo. Change-Id: Ib3e4b5cff1e3329d0600504a8829a969a9c9f517 Reviewed-on: https://go-review.googlesource.com/c/go/+/352612 Trust: Cherry Mui <cherryyz@google.com> Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-09-28cmd/internal/goobj: remove Pcdata from object fileCherry Mui
As of CL 247399 we use separate symbols for PCDATA. There is no more need for writing PCDATA directly into the object file as a separate block. Change-Id: I942d1a372540415e0cc07fb2a01f79718a264142 Reviewed-on: https://go-review.googlesource.com/c/go/+/352610 Trust: Cherry Mui <cherryyz@google.com> Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-09-20cmd/link: generate DIE for types referenced only through dictionariesAlessandro Arzilli
Generate debug_info entries for types that are only referenced through dictionaries. Change-Id: Ic36c2e6d9588ec6746793bb213c2dc0e17a8a850 Reviewed-on: https://go-review.googlesource.com/c/go/+/350532 Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Trust: Dan Scales <danscales@google.com> Trust: David Chase <drchase@google.com>
2021-03-05cmd/internal/goobj: store relocation type as uint16Cherry Zhang
Currently, relocation type is stored as uint8 in object files, as Go relocations do not exceed 255. In the linker, however, it is used as a 16-bit type, because external relocations can exceed 255. The linker has to store the extra byte in a side table. This complicates many things. Just store it as uint16 in object files. This simplifies things, with a small cost of increasing the object file sizes. before after hello.o 1672 1678 runtime.a 7927784 8056194 Change-Id: I313cf44ad0b8b3b76e35055ae55d911ff35e3158 Reviewed-on: https://go-review.googlesource.com/c/go/+/268477 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-02-24docs: fix spellingJohn Bampton
Change-Id: Ib689e5793d9cb372e759c4f34af71f004010c822 GitHub-Last-Rev: d63798388e5dcccb984689b0ae39b87453b97393 GitHub-Pull-Request: golang/go#44259 Reviewed-on: https://go-review.googlesource.com/c/go/+/291949 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org>
2021-02-19cmd/asm, cmd/link, runtime: introduce FuncInfo flag bitsRuss Cox
The runtime traceback code has its own definition of which functions mark the top frame of a stack, separate from the TOPFRAME bits that exist in the assembly and are passed along in DWARF information. It's error-prone and redundant to have two different sources of truth. This CL provides the actual TOPFRAME bits to the runtime, so that the runtime can use those bits instead of reinventing its own category. This CL also adds a new bit, SPWRITE, which marks functions that write directly to SP (anything but adding and subtracting constants). Such functions must stop a traceback, because the traceback has no way to rederive the SP on entry. Again, the runtime has its own definition which is mostly correct, but also missing some functions. During ordinary goroutine context switches, such functions do not appear on the stack, so the incompleteness in the runtime usually doesn't matter. But profiling signals can arrive at any moment, and the runtime may crash during traceback if it attempts to unwind an SP-writing frame and gets out-of-sync with the actual stack. The runtime contains code to try to detect likely candidates but again it is incomplete. Deriving the SPWRITE bit automatically from the actual assembly code provides the complete truth, and passing it to the runtime lets the runtime use it. This CL is part of a stack adding windows/arm64 support (#36439), intended to land in the Go 1.17 cycle. This CL is, however, not windows/arm64-specific. It is cleanup meant to make the port (and future ports) easier. Change-Id: I227f53b23ac5b3dabfcc5e8ee3f00df4e113cf58 Reviewed-on: https://go-review.googlesource.com/c/go/+/288800 Trust: Russ Cox <rsc@golang.org> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-12-16cmd/internal/goobj: fix buglet in object file readerThan McIntosh
The code in the new (introduced in 1.15) Go object file reader was casting a pointer-mmaped-memory into a large array prior to performing a read of the relocations section: return (*[1<<20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n] For very large object files, this artificial array isn't large enough (that is, there are more than 1048576 relocs to read), so update the code to use a larger artifical array size. Fixes #41621. Change-Id: Ic047c8aef4f8a3839f2e7e3594bce652ebd6bd5b Reviewed-on: https://go-review.googlesource.com/c/go/+/278492 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org> Trust: Than McIntosh <thanm@google.com>
2020-09-11[dev.link] all: merge branch 'master' into dev.linkCherry Zhang
Clean merge. Change-Id: Ib773b0bc00fd99d494f9331c3613bcc8285e48e3
2020-08-26cmd/internal/objabi: delete doc.goCherry Zhang
cmd/internal/objabi/doc.go has comments decribing the (old) object file format. But cmd/internal/objabi has nothing to do with object files, and never did. Delete. Move some comment to cmd/internal/goobj, where the (new) object file format is actually defined, and update to reflect the current status. Change-Id: Ied96089df4be35e5d259a572ed60ee00f2cd0d1d Reviewed-on: https://go-review.googlesource.com/c/go/+/249958 Reviewed-by: Than McIntosh <thanm@google.com>
2020-08-13[dev.link] cmd/link, cmd/compile: create content addressable pcdata symsJeremy Faller
Switch pcdata over to content addressable symbols. This is the last step before removing these from pclntab_old. No meaningful benchmarks changes come from this work. Change-Id: I3f74f3d6026a278babe437c8010e22992c92bd89 Reviewed-on: https://go-review.googlesource.com/c/go/+/247399 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2020-08-11[dev.link] cmd: remove "2", another roundCherry Zhang
Rename the goobj2 package to goobj. Change-Id: Iff97b5575cbac45ac44de96b6bd9d555b9a4a12a Reviewed-on: https://go-review.googlesource.com/c/go/+/246444 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>