1
0
mirror of https://github.com/golang/go synced 2024-11-26 08:07:57 -07:00

cmd/link: set correct flags in .dynamic for PIE buildmode

For internal linking, when generating a PIE binary, set the proper
.dynamic section flags to mark the binary as position-independent.

Fixes #46747.

Change-Id: I2b899148c6d06f92c9d12257a9761278b4236dfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/328089
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>
This commit is contained in:
Than McIntosh 2021-06-15 08:01:54 -04:00
parent 4d2d89ff42
commit 723f199edd

View File

@ -950,6 +950,11 @@ func elfdynhash(ctxt *Link) {
} }
s = ldr.CreateSymForUpdate(".dynamic", 0) s = ldr.CreateSymForUpdate(".dynamic", 0)
if ctxt.BuildMode == BuildModePIE {
// https://github.com/bminor/glibc/blob/895ef79e04a953cac1493863bcae29ad85657ee1/elf/elf.h#L986
const DTFLAGS_1_PIE = 0x08000000
Elfwritedynent(ctxt.Arch, s, elf.DT_FLAGS_1, uint64(DTFLAGS_1_PIE))
}
elfverneed = nfile elfverneed = nfile
if elfverneed != 0 { if elfverneed != 0 {
elfWriteDynEntSym(ctxt, s, elf.DT_VERNEED, gnuVersionR.Sym()) elfWriteDynEntSym(ctxt, s, elf.DT_VERNEED, gnuVersionR.Sym())