]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: don't overalign ELF reloc sections
authorIan Lance Taylor <iant@golang.org>
Fri, 2 Dec 2016 06:48:52 +0000 (22:48 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 2 Dec 2016 07:13:18 +0000 (07:13 +0000)
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 <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/go_test.go
src/cmd/link/internal/ld/data.go

index 6c597ed744c6a3a6e7f5f8b574903ca03a736065..1c84512ed49cabb109d3df407bdb66506893d570 100644 (file)
@@ -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")
+}
index eaf6aa20808b0a288354a8195d6ca84931899886..ed8193294ec631d8e26a21a098446918cb45c7d3 100644 (file)
@@ -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)
                }
        }