From 130ad87ab7b02a87401246d4a5f0c3f00fc7d709 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 1 Dec 2016 22:48:52 -0800 Subject: [PATCH] cmd/link: don't overalign ELF reloc sections Internal linking on an ELF system creates two reloc sections, which must be adjacent. The default is to base section alignment on the section size, but doing that for ELF reloc sections can introduce a gap. Set the reloc section alignment explicitly to avoid that. Fixes #18044. Change-Id: I8ccc131e60937d30c5f715a34c7803258833fc2f Reviewed-on: https://go-review.googlesource.com/33872 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/go_test.go | 9 +++++++++ src/cmd/link/internal/ld/data.go | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 6c597ed744c..1c84512ed49 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -3718,3 +3718,12 @@ func TestLinkXImportPathEscape(t *testing.T) { tg.t.Fatal(`incorrect output: expected "linkXworked\n"`) } } + +// Issue 18044. +func TestLdBindNow(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + tg.parallel() + tg.setenv("LD_BIND_NOW", "1") + tg.run("help") +} diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index eaf6aa20808..ed8193294ec 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -1976,6 +1976,13 @@ func dodataSect(ctxt *Link, symn obj.SymKind, syms []*Symbol) (result []*Symbol, copy(syms[first+2:], syms[first+1:second]) syms[first+0] = rel syms[first+1] = plt + + // Make sure alignment doesn't introduce a gap. + // Setting the alignment explicitly prevents + // symalign from basing it on the size and + // getting it wrong. + rel.Align = int32(SysArch.RegSize) + plt.Align = int32(SysArch.RegSize) } }