]> Cypherpunks repositories - gostls13.git/commit
cmd/link: apply -X options after loading symbols
authorRuss Cox <rsc@golang.org>
Tue, 9 Jan 2018 15:10:46 +0000 (10:10 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 9 Jan 2018 21:46:11 +0000 (21:46 +0000)
commit28639df158a19b2bbceda43fb67ca7cb685d8e34
tree3dedee33d1d08ce02a5e8bfef2929c5c92dfa99a
parentbf897845363eee8e39d3d4c02d3aadc864b5faf0
cmd/link: apply -X options after loading symbols

The linker has been applying -X options before loading symbols,
meaning that when it sees -X y=z it creates a symbol named y
and initializes its string data to z. The symbol named y is marked
"DUPOK" so that when the actual packages are loaded, no error is
emitted when the real y is seen. The predefined y's data is used
instead of whatever the real y says.

If we define -X y=z and we never load y, then the predefined symbol
is dropped during dead code elimination, but not in shared library
builds. Shared library builds must include all symbols, so we have to
be more careful about not defining symbols that wouldn't have
appeared anyway.

To be more careful, save the -X settings until after all the symbols
are loaded from the packages, and then apply the string changes
to whatever symbols are known (but ignore the ones that were not
loaded at all). This ends up being simpler anyway, since it doesn't
depend on DUPOK magic.

Makes CL 86835 safe.

Fixes #23273.

Change-Id: Ib4c9b2d5eafa97c5a8114401dbec0134c76be54f
Reviewed-on: https://go-review.googlesource.com/86915
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/go.go
src/cmd/link/internal/ld/main.go