mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
4d2d89ff42
commit
723f199edd
1 changed files with 5 additions and 0 deletions
|
|
@ -950,6 +950,11 @@ func elfdynhash(ctxt *Link) {
|
|||
}
|
||||
|
||||
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
|
||||
if elfverneed != 0 {
|
||||
elfWriteDynEntSym(ctxt, s, elf.DT_VERNEED, gnuVersionR.Sym())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue