aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld/deadcode.go
AgeCommit message (Collapse)Author
2023-02-06cmd/link: linker portion of dead map removalThan McIntosh
This patch contains the linker changes needed to enable deadcoding of large unreferenced map variables, in combination with a previous compiler change. We add a new cleanup function that runs just after deadcode that looks for relocations in "init" funcs that are weak, of type R_CALL (and siblings), and are targeting an unreachable function. If we find such a relocation, after checking to make sure it targets a map.init.XXX helper, we redirect the relocation to a point to a no-op routine ("mapinitnoop") in the runtime. Compilebench results for this change: │ out.base.txt │ out.wrap.txt │ │ sec/op │ sec/op vs base │ Template 218.6m ± 2% 221.1m ± 1% ~ (p=0.129 n=39) Unicode 180.5m ± 1% 178.9m ± 1% -0.93% (p=0.006 n=39) GoTypes 1.162 ± 1% 1.156 ± 1% ~ (p=0.850 n=39) Compiler 143.6m ± 1% 142.6m ± 1% ~ (p=0.743 n=39) SSA 8.698 ± 1% 8.719 ± 1% ~ (p=0.145 n=39) Flate 142.6m ± 1% 143.9m ± 3% ~ (p=0.287 n=39) GoParser 247.7m ± 1% 248.8m ± 1% ~ (p=0.265 n=39) Reflect 588.0m ± 1% 590.4m ± 1% ~ (p=0.269 n=39) Tar 198.5m ± 1% 201.3m ± 1% +1.38% (p=0.005 n=39) XML 259.1m ± 1% 260.0m ± 1% ~ (p=0.376 n=39) LinkCompiler 746.8m ± 2% 747.8m ± 1% ~ (p=0.706 n=39) ExternalLinkCompiler 1.906 ± 0% 1.902 ± 1% ~ (p=0.207 n=40) LinkWithoutDebugCompiler 522.4m ± 21% 471.1m ± 1% -9.81% (p=0.000 n=40) StdCmd 21.32 ± 0% 21.39 ± 0% +0.32% (p=0.035 n=40) geomean 609.2m 606.0m -0.53% │ out.base.txt │ out.wrap.txt │ │ user-sec/op │ user-sec/op vs base │ Template 401.9m ± 3% 406.9m ± 2% ~ (p=0.291 n=39) Unicode 191.9m ± 6% 196.1m ± 3% ~ (p=0.052 n=39) GoTypes 3.967 ± 3% 4.056 ± 1% ~ (p=0.099 n=39) Compiler 171.1m ± 3% 173.4m ± 3% ~ (p=0.415 n=39) SSA 30.04 ± 4% 30.25 ± 4% ~ (p=0.106 n=39) Flate 246.3m ± 3% 248.9m ± 4% ~ (p=0.499 n=39) GoParser 518.7m ± 1% 520.6m ± 2% ~ (p=0.531 n=39) Reflect 1.670 ± 1% 1.656 ± 2% ~ (p=0.137 n=39) Tar 352.7m ± 2% 360.3m ± 2% ~ (p=0.117 n=39) XML 528.8m ± 2% 521.1m ± 2% ~ (p=0.296 n=39) LinkCompiler 1.128 ± 2% 1.140 ± 2% ~ (p=0.324 n=39) ExternalLinkCompiler 2.165 ± 2% 2.147 ± 2% ~ (p=0.537 n=40) LinkWithoutDebugCompiler 484.2m ± 4% 490.7m ± 3% ~ (p=0.897 n=40) geomean 818.5m 825.1m +0.80% │ out.base.txt │ out.wrap.txt │ │ text-bytes │ text-bytes vs base │ HelloSize 766.0Ki ± 0% 766.0Ki ± 0% ~ (p=1.000 n=40) ¹ CmdGoSize 10.02Mi ± 0% 10.02Mi ± 0% -0.03% (n=40) geomean 2.738Mi 2.738Mi -0.01% ¹ all samples are equal │ out.base.txt │ out.wrap.txt │ │ data-bytes │ data-bytes vs base │ HelloSize 14.17Ki ± 0% 14.17Ki ± 0% ~ (p=1.000 n=40) ¹ CmdGoSize 308.3Ki ± 0% 298.5Ki ± 0% -3.19% (n=40) geomean 66.10Ki 65.04Ki -1.61% ¹ all samples are equal │ out.base.txt │ out.wrap.txt │ │ bss-bytes │ bss-bytes vs base │ HelloSize 197.3Ki ± 0% 197.3Ki ± 0% ~ (p=1.000 n=40) ¹ CmdGoSize 228.2Ki ± 0% 228.1Ki ± 0% -0.01% (n=40) geomean 212.2Ki 212.1Ki -0.01% ¹ all samples are equal │ out.base.txt │ out.wrap.txt │ │ exe-bytes │ exe-bytes vs base │ HelloSize 1.192Mi ± 0% 1.192Mi ± 0% +0.00% (p=0.000 n=40) CmdGoSize 14.85Mi ± 0% 14.83Mi ± 0% -0.09% (n=40) geomean 4.207Mi 4.205Mi -0.05% Also tested for any linker changes by benchmarking relink of k8s "kubelet"; no changes to speak of there. Updates #2559. Updates #36021. Updates #14840. Change-Id: I4cc5370b3f20679a1065aaaf87bdf2881e257631 Reviewed-on: https://go-review.googlesource.com/c/go/+/463395 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-09all: use ":" for compiler generated symbolsCuong Manh Le
As it can't appear in user package paths. There is a hack for handling "go:buildid" and "type:*" on windows/386. Previously, windows/386 requires underscore prefix on external symbols, but that's only applied for SHOSTOBJ/SUNDEFEXT or cgo export symbols. "go.buildid" is STEXT, "type.*" is STYPE, thus they are not prefixed with underscore. In external linking mode, the external linker can't resolve them as external symbols. But we are lucky that they have "." in their name, so the external linker see them as Forwarder RVA exports. See: - https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#export-address-table - https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/pe-dll.c;h=e7b82ba6ffadf74dc1b9ee71dc13d48336941e51;hb=HEAD#l972) This CL changes "." to ":" in symbols name, so theses symbols can not be found by external linker anymore. So a hacky way is adding the underscore prefix for these 2 symbols. I don't have enough knowledge to verify whether adding the underscore for all STEXT/STYPE symbols are fine, even if it could be, that would be done in future CL. Fixes #37762 Change-Id: I92eaaf24c0820926a36e0530fdb07b07af1fcc35 Reviewed-on: https://go-review.googlesource.com/c/go/+/317917 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> 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-03-16cmd/link: mark unexported methods for pluginsCherry Mui
When plugin is used, we already mark all exported methods reachable. However, when the plugin and the host program share a common package, an unexported method could also be reachable from both the plugin and the host via interfaces. We need to mark them as well. Fixes #51621. Change-Id: I1a70d3f96b66b803f2d0ab14d00ed0df276ea500 Reviewed-on: https://go-review.googlesource.com/c/go/+/393365 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-12-07cmd/link, cmd/go: make version info easier to extractRuss Cox
Reading the version information to date has required evaluating two pointers to strings (which themselves contain pointers to data), which means applying relocations, which can be very system-dependent. To simplify the lookup, inline the string data into the build info blob. This makes go version work on binaries built with external linking on darwin/arm64. Also test that at least the very basics work on a trivial binary, even in short mode. Change-Id: I463088c19e837ae0ce57e1278c7b72e74a80b2c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/369977 Trust: 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>
2021-10-25cmd/compile,cmd/link: introduce generic interface call relocationsKeith Randall
To capture the fact that a method was called on a generic interface, so we can make sure the linker doesn't throw away any implementations that might be the method called. See the comment in reflect.go for details. Fixes #49049 Change-Id: I0be74b6e727c1ecefedae072b149f59d539dc1e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/357835 Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dan Scales <danscales@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-10-13cmd/link: disable weak reference in itab if build with "-linkshared"zhouguangyuan
When build with "-linkshared", we can't tell if the interface method will be used or not. It can be used in shared library. Fixes #47873 Change-Id: Iba12812f199b7679cf2fd41a304268d6d6dd03c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/350189 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Alexander Rakoczy <alex@golang.org>
2021-09-22cmd/compile, cmd/link: avoid ABI aliasesCherry Mui
In the past we introduced ABI aliases, in preparation for ABI wrappers. Now that we have ABI wrappers implemented, we don't need ABI aliases. If ABI wrappers are not enabled, ABI0 and ABIInternal are actually identical, so we can resolve symbol references without distinguish them. This CL does so by normalizing ABIInternal to ABI0 at link time. This way, we no longer need to generate ABI aliases. This CL doesn't clean up everything related to ABI aliases, which will be done in followup CLs. Change-Id: I5b5db43370d29b8ad153078c70a853e3263ae6f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/351271 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-08-09[dev.typeparams] cmd/compile: use types2.Constraint() rather than types2.Bound()Dan Scales
types2.Constraint() returns the top-level constraint type, including any unions or other interface elements. Because of that, we needed to add/fix some code in the type substituter and generic type instantiater in the importer to deal with unions and non-method members of an interface. Also, NewUnion was not correctly setting the HasTParam flag. I also added a better error message when a symbol is not found in (*deadcodePass).decodeIfaceMethod(). Change-Id: Id3668dc596dce63690fa05a9e5e42295b5e2bbb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/340670 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2021-05-13cmd/link: always mark runtime.unreachableMethod symbolCherry Mui
In the deadcode path we mark runtime.unreachableMethod symbol, which is a special symbol used for redirecting unreachable methods. Currently this code is conditioned on not -linkshared. This is wrong. It should be marked with -linkshared mode as well. In fact, -linkshared should only affect the entry symbol. Change the code accordingly. Change-Id: I252abf850212a930f275589ef0035a43e52cb9cc Reviewed-on: https://go-review.googlesource.com/c/go/+/319893 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2021-04-16internal/buildcfg: move build configuration out of cmd/internal/objabiRuss Cox
The go/build package needs access to this configuration, so move it into a new package available to the standard library. Change-Id: I868a94148b52350c76116451f4ad9191246adcff Reviewed-on: https://go-review.googlesource.com/c/go/+/310731 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-04-13cmd/link: build dynexp symbol list directlyAustin Clements
Currently, setCgoAttr populates the cgo_export_{static,dynamic} maps with symbol names of exported symbols, which are then re-looked-up by deadcode and setupdynexp, which in turn puts the re-looked-up symbols in ctxt.dynexp. setCgoAttr already looked up the Syms, so simplify all of this by making setCgoAttr populate ctxt.dynexp directly and eliminating the cgo_export_{static,dynamic} maps. Recording Syms directly also sets us up to use correct symbol versions for these exports, rather than just assuming version 0 for all lookups. Since setupdynexp doesn't really do any "setting up" of dynexp any more with this change, we fold the remaining logic from setupdynexp directly into addexport, where it has better context anyway. This also eliminates a sorting step, since we no longer do a non-deterministic map iteration to build the dynexp slice. For #40724. Change-Id: I3e1a65165268da8c2bf50d7485f2624133433260 Reviewed-on: https://go-review.googlesource.com/c/go/+/309340 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2021-03-24cmd/compile, cmd/link: use weak reference in itabCherry Zhang
When converting a type T to a non-empty interface I, we build the itab which contains the code pointers of the methods. Currently, this brings those methods live (if the itab is live), even if the interface method is never used. This CL changes the itab to use weak references, so the methods can be pruned if not otherwise live. Fixes #42421. Change-Id: Iee5de2ba11d603c5a102a2ba60440d839a7f9702 Reviewed-on: https://go-review.googlesource.com/c/go/+/268479 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-03-18cmd: move experiment flags into objabi.ExperimentAustin Clements
This moves all remaining GOEXPERIMENT flags into the objabi.Experiment struct, drops the "_enabled" from their name, and makes them all bool typed. We also drop DebugFlags.Fieldtrack because the previous CL shifted the one test that used it to use GOEXPERIMENT instead. Change-Id: I3406fe62b1c300bb4caeaffa6ca5ce56a70497fe Reviewed-on: https://go-review.googlesource.com/c/go/+/302389 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-03-15cmd/link/internal/ld: fix typo in a commentTao Qingyun
Change-Id: I9ae39aa2da2bfa6bb5d3f279bca764128d9cc401 GitHub-Last-Rev: 7a5945ae120b911793a1510f371945ac17611440 GitHub-Pull-Request: golang/go#44990 Reviewed-on: https://go-review.googlesource.com/c/go/+/301529 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Tobias Klauser <tobias.klauser@gmail.com>
2021-03-08cmd/link/internal/ld: fix typo in a commentBrad Fitzpatrick
Change-Id: I6d0fafd38f0ad9392f163a9d8cd94d103bf2a059 Reviewed-on: https://go-review.googlesource.com/c/go/+/299669 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-05cmd/internal/objabi: use a separate bit to mark weak relocationCherry Zhang
Instead of using two relocation types R_XXX and R_WEAKXXX, use a separate bit, R_WEAK, to mark weak relocations. This makes it easier to add more weak relocation types. Change-Id: Iec4195c2aefa65f59e464c83018246e17cd08173 Reviewed-on: https://go-review.googlesource.com/c/go/+/268478 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2021-02-26cmd/link: handle types as converted to interface when dynlinkCherry Zhang
When using plugins, a type (whose value) may be pass to a plugin and get converted to interface there, or vice versa. We need to treat the type as potentially converted to interface, and retain its methods. Should fix #44586. Change-Id: I80dd35e68baedaa852a317543ccd78d94628d13b Reviewed-on: https://go-review.googlesource.com/c/go/+/296709 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-19cmd/link: add debug print in deadcodeRuss Cox
This matches the prints that deadcode prints later as the algorithm progresses under -v=2. It helps to see the initial conditions with -v=2 as well. Change-Id: I06ae86fe9bd8314d003148f3d941832c9b10aef1 Reviewed-on: https://go-review.googlesource.com/c/go/+/288817 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-02-02cmd/link: don't decode type symbol in shared library in deadcodeCherry Zhang
In the linker's deadcode pass we decode type symbols for interface satisfaction analysis. When linking against Go shared libraries, the type symbol may come from a shared library, so it doesn't have data in the current module being linked, so we cannot decode it. We already have code to skip DYNIMPORT symbols. However, this doesn't actually work, because at that point the type symbols' names haven't been mangled, whereas they may be mangled in the shared library. So the symbol definition (in shared library) and reference (in current module) haven't been connected. Skip decoding type symbols of type Sxxx (along with DYNIMPORT) when linkShared. Note: we cannot skip all type symbols, as we still need to mark unexported methods defined in the current module. Fixes #44031. Change-Id: I833d19a060c94edbd6fc448172358f9a7d760657 Reviewed-on: https://go-review.googlesource.com/c/go/+/288496 Trust: Cherry Zhang <cherryyz@google.com> Trust: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-10-12cmd/link: always mark runtime.buildVersion and runtime.modinfo reachableCherry Zhang
runtime.buildVersion and runtime.modinfo are referenced in the .go.buildinfo section, therefore reachable. They should normally be reachable from the runtime. Just make it explicit, in case. Change-Id: I60ff3132e0bbb690f4a3cba8bb18735921fbe951 Reviewed-on: https://go-review.googlesource.com/c/go/+/261637 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-09-29cmd/link: retain only used interface methodsCherry Zhang
Currently, in the linker's deadcode pass, when an interface type is live, the linker thinks all its methods are live, and uses them to match methods on concrete types. The interface method may never be used, though. This CL changes it to only keep used interface methods, for matching concrete type methods. To do that, when an interface method is used, the compiler generates a mark relocation. The linker uses the marker relocations to mark used interface methods, and only the used ones. binary size before after cmd/compile 18887400 18812200 cmd/go 13470652 13470492 Change-Id: I3cfd9df4a53783330ba87735853f2a0ec3c42802 Reviewed-on: https://go-review.googlesource.com/c/go/+/256798 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-09-28cmd/link: consider interface conversions only in reachable codeCherry Zhang
The linker prunes methods that are not directly reachable if the receiver type is never converted to interface. Currently, this "never" is too strong: it is invalidated even if the interface conversion is in an unreachable function. This CL improves it by only considering interface conversions in reachable code. To do that, we introduce a marker relocation R_USEIFACE, which marks the target symbol as UsedInIface if the source symbol is reached. binary size before after cmd/compile 18897528 18887400 cmd/go 13607372 13470652 Change-Id: I66c6b69eeff9ae02d84d2e6f2bc7f1b29dd53910 Reviewed-on: https://go-review.googlesource.com/c/go/+/256797 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-09-18cmd/link: don't mark a symbol's GoType reachable when -linksharedCherry Zhang
In CL 231397, we stopped marking symbols' GoType reachable in general, but not when -linkshared. It was left as a TODO. This CL addresses it. The problem was that the type names are mangled in the shared library, so we need to mangle the name consistently in the executable as well (regardless of whether the symbol is reachable or not), so that the GCProg generation code can find the corresponding symbol from the shared library. Change-Id: I1040747402929a983ec581109f1681a77893682e Reviewed-on: https://go-review.googlesource.com/c/go/+/255964 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-09-18cmd/link: propagate UsedInIface through method descriptorCherry Zhang
The linker prunes methods that are not directly reachable if the receiver type is never converted to interface. A type can be converted to interface using reflection through other types. The linker already takes this into consideration but it missed the case that the intermediate is a method descriptor. Handle this case. Change-Id: I590efc5da163c326db8d43583908a2ef67f65d9d Reviewed-on: https://go-review.googlesource.com/c/go/+/255858 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> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-09-11cmd/link: record only the first occurance in Reachparent graphCherry Zhang
In the deadcode pass, a type symbol may be marked twice, one without UsedInIface, one with. For the second time, don't update the Reachparent graph, so it only records the path of the first time the symbol is reached. This ensures the Reachparent graph is acyclic. TODO: add a test. (This only affects GOEXPERIMENT=fieldtrack) Change-Id: I68e8a1a69c3830bc8aee5df946151dc22dcb2b29 Reviewed-on: https://go-review.googlesource.com/c/go/+/254297 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> 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>
2020-08-03[dev.link] cmd/compile, cmd/link: generate itablink at link timeCherry Zhang
Currently, at compile time, for each itab symbol, we create an "itablink" symbol which holds solely the address of the itab symbol. At link time, all the itablink symbols are grouped together to form the itablinks slice. This CL removes the itablink symbols, and directly generate the itablinks slice in the linker. This removes a number of symbols, which are dupOK and generally have long names. And also removes a special handling of itablink symbols in the deadcode pass which iterates through all symbols. Change-Id: I475c3c8899e9fbeec9abc7647b1e4a69aa5c3c5a Reviewed-on: https://go-review.googlesource.com/c/go/+/245901 Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-07-30[dev.link] cmd/link: remove "2", another roundCherry Zhang
Rename Reloc2 to Reloc, At2 to At, Aux2 to Aux. Change-Id: Ic98d83c080e8cd80fbe1837c8f0aa134033508ce Reviewed-on: https://go-review.googlesource.com/c/go/+/245578 Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-06-11[dev.link] cmd/compile, cmd/link: remove dead methods if type is not used in ↵Cherry Zhang
interface Currently, a method of a reachable type is live if it matches a method of a reachable interface. In fact, we only need to retain the method if the type is actually converted to an interface. If the type is never converted to an interface, there is no way to call the method through an interface method call (but the type descriptor could still be used, e.g. in calling runtime.newobject). A type can be used in an interface in two ways: - directly converted to interface. (Any interface counts, as it is possible to convert one interface to another.) - obtained by reflection from a related type (e.g. obtaining an interface of T from []T). For the former, we let the compiler emit a marker on the type descriptor symbol when it is converted to an interface. In the linker, we only need to check methods of marked types. For the latter, when the linker visits a marked type, it needs to visit all its "child" types as marked (i.e. potentially could be converted to interface). This reduces binary size: cmd/compile 18792016 18706096 (-0.5%) cmd/go 14120572 13398948 (-5.1%) Change-Id: I4465c7eeabf575f4dc84017214c610fa05ae31fd Reviewed-on: https://go-review.googlesource.com/c/go/+/237298 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-06-04[dev.link] cmd/link: reuse slice memory in deadcode passCherry Zhang
Reuse slice memory in the deadcode pass, reduce allocations. Linking cmd/compile, name old alloc/op new alloc/op delta Deadcode_GC 2.10MB ± 0% 1.41MB ± 0% -32.61% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Deadcode_GC 8.46k ± 0% 5.55k ± 0% -34.45% (p=0.008 n=5+5) Change-Id: Ib9ba0928d68a65879007218697712b53acd3c5c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/236566 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-06-04[dev.link] cmd/link: rewrite heap algorithmCherry Zhang
Instead of using container/heap package, implement a simple specialized heap algorithm for the work queue in the deadcode pass, to avoid allocations and function pointer calls. Linking cmd/compile, name old time/op new time/op delta Deadcode_GC 59.8ms ± 4% 42.2ms ± 4% -29.45% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Deadcode_GC 3.53MB ± 0% 2.10MB ± 0% -40.57% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Deadcode_GC 187k ± 0% 8k ± 0% -95.48% (p=0.008 n=5+5) Change-Id: Ibb21801d5b8e4a7eaf429856702e02720cd1772f Reviewed-on: https://go-review.googlesource.com/c/go/+/236565 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-06-04[dev.link] cmd/link: compare type descriptors for interface satisfaction ↵Cherry Zhang
analysis Currently, in the deadcode pass, when checking whether a defined method satisfies an interface, it compares the string representation of the defined method and the interface method. In fact, it can simply compare the method name and the type descriptor (as we do in runtime). Make it so. Change-Id: Ideb2b2410e5eedcd20ac31e3af41f5499fc90225 Reviewed-on: https://go-review.googlesource.com/c/go/+/236564 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-05-01cmd/link: expand a TODO commentCherry Zhang
CL 231397 is submitted too fast... Expand the comment to make it a little clearer. Change-Id: Ica9737aa7b51f97320bab74457388dcab8188370 Reviewed-on: https://go-review.googlesource.com/c/go/+/231597 Reviewed-by: Austin Clements <austin@google.com>
2020-05-01cmd/link: don't mark a symbol's Gotype reachableCherry Zhang
A symbol being reachable doesn't imply its type descriptor is needed. Don't mark it. If the type is converted to interface somewhere in the program, there will be an explicit use of the type descriptor, which will make it marked. A println("hello") program before and after -rwxr-xr-x 1 cherryyz primarygroup 1259824 Apr 30 23:00 hello -rwxr-xr-x 1 cherryyz primarygroup 1169680 Apr 30 23:10 hello Updates #38782. Updates #6853. Change-Id: I88884c126ce75ba073f1ba059c4b892c87d2ac96 Reviewed-on: https://go-review.googlesource.com/c/go/+/231397 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-04-30[dev.link] cmd/link: combine decodesym.go and decodesym2.goCherry Zhang
And remove "2" from some function names. Change-Id: Ibf1089970d849a42f53976064ceb9ade20bf6eba Reviewed-on: https://go-review.googlesource.com/c/go/+/231017 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-04-22[dev.link] cmd/link: delete ctxt.ReachparentCherry Zhang
It is no longer needed as we have converted the fieldtrack pass to using the loader. Also free loader.Reachparent after we are done with it. Change-Id: Ibc4b29f282e1e4aea363a1b549755e31f84b0295 Reviewed-on: https://go-review.googlesource.com/c/go/+/229322 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-04-20[dev.link] cmd/link: rename deadcode2 to deadcodeJeremy Faller
deadcode's been completely replaced. Make its death official. Change-Id: I85f1e3968463f216b8bce2fb7217c3b51641939f Reviewed-on: https://go-review.googlesource.com/c/go/+/229002 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-04-19cmd/link: check for reflect.Value.MethodByName explicitlyCherry Zhang
Currently we only check for reflect.Value.Method. And reflect.Value.MethodByName is covered since it calls reflect.Value.Method internally. But it is brittle to rely on implementation detail of the reflect package. Check for MethodByName explicitly. Change-Id: Ifa8920e997524003dade03abc4fb3c4e64723643 Reviewed-on: https://go-review.googlesource.com/c/go/+/228881 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-18cmd/link: update comment for deadcodeCherry Zhang
Update the comment to be in sync with the code. Change-Id: I19586767a37347c4da1b4d3f7c6dc6cc2292a90f Reviewed-on: https://go-review.googlesource.com/c/go/+/228877 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-13[dev.link] cmd/link: stop populating lib/unit.TextpCherry Zhang
lib.Textp was used for text address assignment and trampoline insertion. Now that it has been converted to using the loader, no need to populate lib.Textp. Port the logic of canonicalizing dupok symbol's package to the loader. unit.Textp was used for DWARF generation, which has also been converted to using the loader. Change-Id: I22d4dd30a52a29dd5b1b7b795d43a19f6215e4ac Reviewed-on: https://go-review.googlesource.com/c/go/+/228140 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2020-03-05[dev.link] cmd/link: fix up ctxt.Textp2 handling in AssignTextSymbolOrderThan McIntosh
Change the loader method AssignTextSymbolOrder to return a slice of all reachable textp symbols, since it will be needed in second-phase DWARF gen. Change-Id: Iaf16ee9cf0d5266aeb0d3df596e8117263b35d8e Reviewed-on: https://go-review.googlesource.com/c/go/+/220985 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-02-19[dev.link] cmd/link: convert DWARF type generation to use loaderThan McIntosh
Converts the portion of DWARF generation that deals with creation of type DIEs and constant DIEs to use the new loader interfaces. Creation of subprogram DIE and compilation unit DIE content still operates on sym.Symbols at the moment, and happens much later in the linker. The new code for type DIE generation is gated/guarded by the linker flag "-newdw", which currently defaults to true. At some point in the near future this flag should be removed, but it is handy for triage at the moment. This patch also includes shim code designed to run after loadlibfull() that walks through the DIE chains and to converts loader.Sym references back into sym.Symbol references for the remainder of the compilation, since the second phase of DWARF has not yet been converted. Change-Id: I681a00fb8a1f3c37884a79b373d86411332e07c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/208230 Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-01-06[dev.link] cmd/link: keep loader symbol info in sym.CompilationUnitThan McIntosh
In sym.Library and sym.CompilationUnit there are slices of *sym.Symbol pointer that hold text symbols contained in the unit lib. To support DWARF generation with new loader, add equivalent slices that hold loader.Sym values for functions in scope. This will be needed if at some point we push the sym.Symbol creation "wavefront" beyond dwarf gen. This patch also insures that live host object symbols are added to the context Textp2 slice, since they would not make it on otherwise. [NB: not sure if this is the best way to do this.] Change-Id: I4f440e12cebc525b1e37082ad39cf7338aeb6b99 Reviewed-on: https://go-review.googlesource.com/c/go/+/208231 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2019-11-12[dev.link] cmd/link: delete old object file format supportCherry Zhang
There are more cleanups to do, but I want to keep this CL mostly a pure deletion. Change-Id: I30f4891a2ea54545fd6b83041746ab65895537e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/206558 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2019-11-01[dev.link] all: merge branch 'master' into dev.linkThan McIntosh
Fixed a couple of minor conflicts in lib.go and deadcode.go relating to debug logging. Change-Id: I58335fc42ab1f1f3409fd8354da4f26419e8fb22
2019-10-26cmd/link/internal: eliminate all ld.Cputime() usagesnikita-vanyasin
Also a similar 'elapsed' function and its usages were deleted. Fixes #19865. Change-Id: Ib125365e69cf2eda60de64fa74290c8c7d1fd65a Reviewed-on: https://go-review.googlesource.com/c/go/+/171730 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2019-10-15[dev.link] cmd/link: create sym.Symbols after deadcode in newobj modeCherry Zhang
With the new object files, now we can run the deadcode pass on indices instead of Symbol structs, so we can delay creating Symbols after the deadcode pass. Then we only need to create reachable symbols. Not create Symbols in LoadNew and LoadRefs, and recombine LoadReloc into LoadFull. Split loadcgo into two parts: the first finds root symbols, the second create Symbols and sets attributes. The first runs before the deadcode pass, while the second runs after. TODO: currently there are still symbols that are not marked reachable but still used. This includes DWARF symbols, file symbols, and type symbols that are referenced by DWARF symbols. We still need to create them (conservatively). Change-Id: I695779c9312be9d49ab1683957ac3e72e1f65a1e Reviewed-on: https://go-review.googlesource.com/c/go/+/199643 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2019-10-10[dev.link] cmd/link: use index for deadcodeCherry Zhang
Switch the deadcode pass to use indices instead of Symbol structures when using new object file format. Delay loading symbol relocations and contents fully after the deadcode pass. The next step is not to create Symbol structures until deadcode is done. Method tracking logic hasn't been implemented. Currently, all methods of a reachable type are live. Change-Id: Iffcd06ff84e6e52bd9eb24d1220d94234d18ab6b Reviewed-on: https://go-review.googlesource.com/c/go/+/198199 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2019-10-09[dev.link] cmd/link: change some decodetype functions to operate on bytesCherry Zhang
Change some decodetype functions to operate on bytes nstead of Symbol. This is in preparation of implementing live method tracking in index-based deadcode pass, and reducing/eliminating sym.Symbol in general. Change-Id: Ia9809ad7b182884225e1bda577e8dbec0cd216c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/199077 Reviewed-by: Austin Clements <austin@google.com>