cmd/link: support PIE internal linking on darwin/amd64

This CL adds support of PIE internal linking on darwin/amd64.

This is also preparation for supporting internal linking on
darwin/arm64 (macOS), which requires PIE for everything.

Updates #38485.

Change-Id: I2ed58583dcc102f5e0521982491fc7ba6f2754ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/261642
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-10-11 15:48:22 -04:00
parent c8eea1633e
commit f46a5b1e45
10 changed files with 289 additions and 54 deletions

View file

@ -420,3 +420,21 @@ func (sb *SymbolBuilder) MakeWritable() {
sb.l.SetAttrReadOnly(sb.symIdx, false)
}
}
func (sb *SymbolBuilder) AddUleb(v uint64) {
if v < 128 { // common case: 1 byte
sb.AddUint8(uint8(v))
return
}
for {
c := uint8(v & 0x7f)
v >>= 7
if v != 0 {
c |= 0x80
}
sb.AddUint8(c)
if c&0x80 == 0 {
break
}
}
}