Remove the "ElfSym" and "LocalElfSym" fields from sym.Symbol,
replacing uses with loader method calls as needed.
Change-Id: I3828f13203ece2bdc03eeb09ab37a5c94e21a726
Reviewed-on: https://go-review.googlesource.com/c/go/+/230462
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Remove sym.Symbol 'Unit' field, replacing accesses to the field with
calls into the loader instead.
Change-Id: Ia1abd4c3d93036705dd624a49cb3d9cbe6a5188b
Reviewed-on: https://go-review.googlesource.com/c/go/+/230307
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Add new get/set methods to the loader for recording the ELF symbol
index for a given loader symbol. These are map-based, since it is
expected that many/most symbols will not need an ELF symbol table
entry.
Change-Id: I1102c3637775515ccc6650118e8b059468a2c3ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/230461
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Remove the 'Gotype' field from sym.Symbol, as it is now no longer
used. Store the loader.Sym for a symbol as a field in sym.Symbol
("SymIdx"). Then remove sym.Symbol 'File' field, and replace the field
accesses in question with calls into the loader instead.
Change-Id: I01c5504425006b8d3fe77fac2b69a86e198c7a5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/230304
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>
None of the users of genasmsym are doing anything with the Gotype
field of sym.Symbol, so remove that param from the callback function.
Change-Id: Ie902c4cdbcc6b68d353daf5ce21a99012161a946
Reviewed-on: https://go-review.googlesource.com/c/go/+/230545
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Make Wasm more like other architectures, writing data sections to
heap in Asmb instead of Asmb2. Then we can remove the
copy-on-write logic in applying relocations.
Change-Id: I26d5315ea9fba032fe4bdb9b5c7fe483611c4373
Reviewed-on: https://go-review.googlesource.com/c/go/+/230465
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>
This change is just the mechanical work of moving the wavefront past
address.
Change-Id: I519ec49fa8ba50760c7d23fc084fcd3bb0544546
Reviewed-on: https://go-review.googlesource.com/c/go/+/229700
Run-TryBot: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This reverts CL 229994.
Reason for revert: break AIX build.
This is nice to have but isn't critical. We can revisit later.
Change-Id: Ifc56a0a4c0fb36859cf7666ab149e25e0e5d4cc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/230459
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
ctxt.Tlsg2 is supposed to be the embedded ArchSyms.Tlsg2.
Change-Id: I4f9711f83999d4a98bcf6d99c24fab756c580905
Reviewed-on: https://go-review.googlesource.com/c/go/+/230379
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
symGroupType was needed for dodata. Now that we have converted
dodata to using the loader, stop overwriting it.
Change-Id: Ie94109c0b35dd2f71a19ebb38f8cf20b6a37c624
Reviewed-on: https://go-review.googlesource.com/c/go/+/229994
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
In dodata we overwrite symbol types to SDATA. Now we'll stop
doing that, so accept more symbol types here. This is basically
a list of all writeable types handled in dodata that could appear
in XCOFF.
Change-Id: Iee35369162f5acd59806a3f0e6c8d3682620067e
Reviewed-on: https://go-review.googlesource.com/c/go/+/230310
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Add linux/{ppc64,ppc64le} and aix/ppc64 arch support for the new
dodata() phase.
This completes the picture in terms of architecture support for the
new dodata(), but to be safe this patch leaves the command line flag
in place there are problems on the builders (especially given that we
have a dead aix-ppc64 builder).
Change-Id: I78da615c3b540d8925ed7b3226e199280eb7451d
Reviewed-on: https://go-review.googlesource.com/c/go/+/229983
Reviewed-by: Cherry Zhang <cherryyz@google.com>
The ReadOnly attribute was used to do copy on write when applying
relocations to symbols with read-only backing stores. Now that we
always apply relocations in the output buffer (mmap or heap), it
is always writeable. No need to tamper with the ReadOnly
attribute anymore.
Wasm is an exception, where we don't copy symbol contents to the
output buffer first. Do copy-on-write there.
This is in preparation of converting reloc to using the loader.
Change-Id: I15e53b7c162b9124e6689dfd8eb45cbe2ffd7153
Reviewed-on: https://go-review.googlesource.com/c/go/+/229991
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Currently, we run Asmb before reloc, except on Wasm, where the
order is reversed. However, Asmb is no-op on Wasm. So we can
always run Asmb first.
Change-Id: Ifb8989d8150ebdd5777deb05cbccec16f8e36d82
Reviewed-on: https://go-review.googlesource.com/c/go/+/229990
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
They also don't need to do anything for Adddynrel. So we can just
enable it.
Change-Id: If85fceca63a7b3cb5a09e5db224c3018060e86de
Reviewed-on: https://go-review.googlesource.com/c/go/+/229993
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Recreation of CL 229863 that was removed from the repo because it
included the linker binary.
Change-Id: I5e96afa079b1217df6e7cba63a107546bd96ef76
Reviewed-on: https://go-review.googlesource.com/c/go/+/230028
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
It is supposed to work around symbol movement in machosymorder.
But machosymorder doesn't actually move symbols around.
Change-Id: Ibdc2ad41aaa8cd49e865088aa1ddb7ab399736cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/230279
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>
The symbol alignment is set based on its size. In dynreloc2
symbol size may change (e.g. elfdynhash2). So the alignment must
be set after dynreloc2.
Noticed this while debugging nondeterministic build on Solaris.
Idx Name Size VMA LMA File off Algn
8 .hash 000000c8 000000000048add2 000000000048add2 0008add2 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
This doesn't look right, as the section address is not a multiple
of its alignment.
Change-Id: I23534cbc59695b7bc241838173fcc71dde95b195
Reviewed-on: https://go-review.googlesource.com/c/go/+/230278
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>
Add elf/ARM arch support for the new dodata() phase.
Change-Id: Iadd772b01036c6c5be95bcc6017f6c05d45a24c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/229868
Reviewed-by: Cherry Zhang <cherryyz@google.com>
They don't have fancy Adddynrel stuff, so we can just enable it.
Change-Id: I84082c3187d8a9ffa3a9c5458959794df0e3c2b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/230030
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This probably breaks darwin/arm64. Will fix.
Change-Id: I8be168985124f971e9d8ab5bc95c303336dd705b
Reviewed-on: https://go-review.googlesource.com/c/go/+/230019
Reviewed-by: Than McIntosh <thanm@google.com>
It should check the name of the symbol being added, not the
GC data symbol we're generating.
Change-Id: I123679778ee542b8d1f5c15bf090fa3578025c19
Reviewed-on: https://go-review.googlesource.com/c/go/+/230018
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Tweak the code in the amd64 version of adddynrel to avoid creating a
symbol updated for the symbol being processed until it's clear we need
to alter its relocations. This should help performance for the
PIE+internal linking scenario.
Reviewed-on: https://go-review.googlesource.com/c/go/+/229866
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Change-Id: Id25adfd81a5bbd2dde0f80a83b976397ba6abfb5
Reviewed-on: https://go-review.googlesource.com/c/go/+/230026
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Previous CL introduced index fingerprint in the object files.
This CL implements the second part: checking fingerprint
consistency in the linker when packages are loaded.
Change-Id: I05dd4c4045a65adfd95e77b625d6c75a7a70e4f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/229618
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>
The new object files use indices for symbol references, instead
of names. Fundamental to the design, it requires that the
importing and imported packages have consistent view of symbol
indices. The Go command should already ensure this, when using
"go build". But in case it goes wrong, it could lead to obscure
errors like run-time crashes. It would be better to check the
index consistency at build time.
To do that, we add a fingerprint to each object file, which is
a hash of symbol indices. In the object file it records the
fingerprints of all imported packages, as well as its own
fingerprint. At link time, the linker checks that a package's
fingerprint matches the fingerprint recorded in the importing
packages, and issue an error if they don't match.
This CL does the first part: introducing the fingerprint in the
object file, and propagating fingerprints through
importing/exporting by the compiler. It is not yet used by the
linker. Next CL will do.
Change-Id: I0aa372da652e4afb11f2867cb71689a3e3f9966e
Reviewed-on: https://go-review.googlesource.com/c/go/+/229617
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
In the code there are conditions like !ctxt.IsDarwin(). This will
accidentally be true if HeadType is not yet set. Panic when
HeadType is not set, to catch errors.
Change-Id: Ic891123f27f0276fff5a4b5d29e5b1f7ebbb94ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/229869
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
So we can use it to set per-OS flags.
Also set flagnewDoData after archinit, where IsELF is set.
This should correct the logic of setting flagnewDoData.
Change-Id: I18c7252f141aa35119005c252becc9d7cb74f2f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/229867
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Add elf/386 arch support for the new dodata() phase.
Change-Id: I78341dfe70a90719d95c0044183980f348a3369f
Reviewed-on: https://go-review.googlesource.com/c/go/+/229797
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
It doesn't do what it says. It has been like that since Go 1.4.
The current ouput is pretty useless. Remove it.
Change-Id: Id9b4ba04139aaf7ea59acbd51428b1c992115389
Reviewed-on: https://go-review.googlesource.com/c/go/+/229859
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>
This patch begins the work of converting the linker's dodata phase to
work with loader APIs. Passes all.bash on linux/amd64, but hasn't been
tested on anything else (more arch-specific code needs to be written).
Use of the new dodata() phase is currently gated by a temporary
command line flag ("-newdodata"), and there is code in the linker's
main routine to insure that we only use the new version for the right
GOOS/GOARCH (currently restricted to ELF + AMD64).
Change-Id: Ied3966677d2a450bc3e0990e0f519b3fceaab806
Reviewed-on: https://go-review.googlesource.com/c/go/+/229706
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Move the guts of ctxt.Errorf into loader.Loader, so that we can make
calls to it from functions that have a "*loader.Loader" available but
not a "ctxt *Link". This is needed to start converting hooks like
"adddynrel" in the arch-specific portions of the linker to use loader
APIs.
Change-Id: Ieedd4583b66504be0e77d7f3fbadafe0d2307a69
Reviewed-on: https://go-review.googlesource.com/c/go/+/229497
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>
Clients may need to invoke the loader.Reloc2.SetType method to reset
the type of a relocation from external flavor to internal flavor,
meaning that the external type add-in needs to be zeroed (this is
needed when adding dynsym entries).
Add a new SymbolBuider method to support mutating the type of a reloc
for an external symbol, so that the external type can be changed as
well (Reloc2 doesn't have access to that). Also add similar methods
for updating target symbol and addend, so as to have a consistent
interface for ext reloc mutation.
Change-Id: I8e26cdae0a0f353019acba5f9c8a0506e3970266
Reviewed-on: https://go-review.googlesource.com/c/go/+/229604
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Allow for the possibility that a client could call newExtSym(), then
ask for the section of the new sym before SetSectSym is called on it
(check in SymSect for this case).
Change-Id: I7bd78e7b3b7618943705b616f62ea78c4a1b68d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/229603
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Use a separate directory for TestBuildFortvOS test files.
Remove a bad comment in TestTrampoline.
Change-Id: I2dc07ae575ec3f73fb7cea26743094b11a41b464
Reviewed-on: https://go-review.googlesource.com/c/go/+/229619
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Allow go generate to process packages that contain invalid code. Ignore
errors when loading the package, but process only files which have a
valid package clause. Set $GOPACKAGE individually for each file, based
on the package clause.
Add test script for go generate and invalid packages.
Fixes#36422
Change-Id: I91ea088346a1548ccd6678b4595a527b948331ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/229097
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Recommend use of GOINSECURE over -insecure flang and clarify that GOINSECURE
environment variable does not also imply GONOSUMDB.
Updates #37519 by adding documentation as discussed.
Change-Id: Ia8ab6b3ed1aa559343b72e4ca76c372ee6bf1941
GitHub-Last-Rev: 8d86991f0c
GitHub-Pull-Request: golang/go#38572
Reviewed-on: https://go-review.googlesource.com/c/go/+/229223
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
In mid-Walk, we rewrite calls to variadic functions to use explicit
slice literals; e.g., rewriting f(a,b,c) into f([]T{a,b,c}...).
However, it would be useful to do that rewrite much earlier in the
compiler, so that other compiler passes can be simplified.
This CL refactors the rewrite logic into a new fixVariadicCall
function, which subsequent CLs can more easily move into earlier
compiler passes.
Passes toolstash-check -race.
Change-Id: I408e655f2d3aa00446a2e6accf8765abc3b16a8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/229486
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
ioutil.TempDir doesn't like path separators in its pattern. Modify
(*common).TempDir to replace path separators with underscores before
using the test name as a pattern for ioutil.TempDir.
Fixes#38465.
Change-Id: I9e8ae48b99648b2bf9f561762e845165aff01972
Reviewed-on: https://go-review.googlesource.com/c/go/+/229399
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
unsafe.Pointer safety rule #4 says "The compiler handles a Pointer
converted to a uintptr in the argument list of a call". Within escape
analysis, we've always required this be a single conversion
unsafe.Pointer->uintptr conversion, but the corresponding logic in
order is somewhat laxer, allowing arbitrary chains of OCONVNOPs from
unsafe.Pointer to uintptr.
This CL changes order to be stricter to match escape analysis.
Passes toolstash-check.
Change-Id: Iadd210d2123accb2020f5728ea2a47814f703352
Reviewed-on: https://go-review.googlesource.com/c/go/+/229578
Reviewed-by: Ian Lance Taylor <iant@golang.org>