From deeebf5655eeb91e93e60dbda5c3df294b4d5130 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Fri, 26 Apr 2024 13:10:36 +0000 Subject: [PATCH] cmd/link/internal/ld: more fixes to TestElfBindNow readonly .got check 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 Reviewed-by: abner chenc LUCI-TryBot-Result: Go LUCI --- src/cmd/link/internal/ld/elf_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cmd/link/internal/ld/elf_test.go b/src/cmd/link/internal/ld/elf_test.go index 46af7625f3..843b067e19 100644 --- a/src/cmd/link/internal/ld/elf_test.go +++ b/src/cmd/link/internal/ld/elf_test.go @@ -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"}, }, }