aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-07-27 11:36:41 -0400
committerCherry Zhang <cherryyz@google.com>2020-07-27 16:04:55 +0000
commit19a932ceb8dc0059754e1f986c86daba3a4fb14e (patch)
tree843cb75b26223ddd5283dabdadee97b1e6a26757 /misc
parent8696ae82c94f0a7707cbbbdf2cec44e93edf5b23 (diff)
downloadgo-19a932ceb8dc0059754e1f986c86daba3a4fb14e.tar.gz
go-19a932ceb8dc0059754e1f986c86daba3a4fb14e.zip
cmd/link: don't mark shared library symbols reachable unconditionally
During the transitioning period, we mark symbols from Go shared libraries reachable unconditionally. That might be useful when there was still a large portion of the linker using sym.Symbols, and only reachable symbols were converted to sym.Symbols. Marking them reachable brings them to the dynamic symbol table, even if they are not needed, increased the binary size unexpectedly. That time has passed. Now we largely operate on loader symbols, and it is not needed to mark them reachable anymore. Fixes #40416. Change-Id: I1e2bdb93a960ba7dc96575fabe15af93d8e95329 Reviewed-on: https://go-review.googlesource.com/c/go/+/244839 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/testshared/shared_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/misc/cgo/testshared/shared_test.go b/misc/cgo/testshared/shared_test.go
index f8dabbe7a0..5e0893784b 100644
--- a/misc/cgo/testshared/shared_test.go
+++ b/misc/cgo/testshared/shared_test.go
@@ -462,6 +462,7 @@ func TestTrivialExecutable(t *testing.T) {
run(t, "trivial executable", "../../bin/trivial")
AssertIsLinkedTo(t, "../../bin/trivial", soname)
AssertHasRPath(t, "../../bin/trivial", gorootInstallDir)
+ checkSize(t, "../../bin/trivial", 100000) // it is 19K on linux/amd64, 100K should be enough
}
// Build a trivial program in PIE mode that links against the shared runtime and check it runs.
@@ -470,6 +471,18 @@ func TestTrivialExecutablePIE(t *testing.T) {
run(t, "trivial executable", "./trivial.pie")
AssertIsLinkedTo(t, "./trivial.pie", soname)
AssertHasRPath(t, "./trivial.pie", gorootInstallDir)
+ checkSize(t, "./trivial.pie", 100000) // it is 19K on linux/amd64, 100K should be enough
+}
+
+// Check that the file size does not exceed a limit.
+func checkSize(t *testing.T, f string, limit int64) {
+ fi, err := os.Stat(f)
+ if err != nil {
+ t.Fatalf("stat failed: %v", err)
+ }
+ if sz := fi.Size(); sz > limit {
+ t.Errorf("file too large: got %d, want <= %d", sz, limit)
+ }
}
// Build a division test program and check it runs.