]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld: more fixes to TestElfBindNow readonly .got check
authorThan McIntosh <thanm@google.com>
Fri, 26 Apr 2024 13:10:36 +0000 (13:10 +0000)
committerThan McIntosh <thanm@google.com>
Fri, 26 Apr 2024 15:38:14 +0000 (15:38 +0000)
Second try at fixing the TestElfBindNow testpoint: don't try to check
for readonly ".got" section when using the external linker, since
there is code in some linkers (BFD in particular) that will skip
placing ".got" in relro if the section is below a specific size
threshold. Revised version of the test checks only for readonly
".dynamic" in the external linking case.

Fixes #67063.

Change-Id: Idb6b82ec7893baddf171654775587f6050fc6258
Reviewed-on: https://go-review.googlesource.com/c/go/+/581995
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/link/internal/ld/elf_test.go

index 46af7625f3e66c9fcbcff4f5a2f0484103fcdf13..843b067e19c33ea21e7b983b33638cc7f243413c 100644 (file)
@@ -194,12 +194,18 @@ func TestElfBindNow(t *testing.T) {
                progC = `package main; import "C"; func main() {}`
        )
 
-       // Note: for linux/amd64 and linux/arm64, for relro we'll always see
-       // a .got section when building with -buildmode=pie (in addition
-       // to .dynamic); for some other less mainstream archs (ppc64le,
-       // s390) this is not the case (on ppc64le for example we only see
-       // got refs from C objects). Hence we put ".dynamic" in the 'want RO'
-       // list below and ".got" in the 'want RO if present".
+       // Notes:
+       // - for linux/amd64 and linux/arm64, for relro we'll always see a
+       //   .got section when building with -buildmode=pie (in addition
+       //   to .dynamic); for some other less mainstream archs (ppc64le,
+       //   s390) this is not the case (on ppc64le for example we only
+       //   see got refs from C objects). Hence we put ".dynamic" in the
+       //   'want RO' list below and ".got" in the 'want RO if present".
+       // - when using the external linker, checking for read-only ".got"
+       //   is problematic since some linkers will only make the .got
+       //   read-only if its size is above a specific threshold, e.g.
+       //   https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/scripttempl/elf.sc;h=d5022fa502f24db23f396f337a6c8978fbc8415b;hb=6fde04116b4b835fa9ec3b3497fcac4e4a0637e2#l74 . For this reason, don't try to verify read-only .got
+       //   in the external linking case.
 
        tests := []struct {
                name                 string
@@ -256,8 +262,6 @@ func TestElfBindNow(t *testing.T) {
                        wantDf1Now:           true,
                        wantDf1Pie:           true,
                        wantSecsRO:           []string{".dynamic"},
-                       // NB: external linker produces .plt.got, not .got.plt
-                       wantSecsROIfPresent: []string{".got", ".got.plt"},
                },
        }