Commit 5e7110b9 authored by OneOfOne's avatar OneOfOne Committed by Ian Lance Taylor

cmd/link: fix elf64phdr to allow using upx (and other broken ELF loaders).

The linker already applies the fix for elf32, so this just extends it to elf64.

Inspired by https://github.com/pwaller/goupx

Fixes #13974

Change-Id: I65d92b5be9590657060a0e8e80ff5b86ba40017f
Reviewed-on: https://go-review.googlesource.com/18690Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c7754c8f
......@@ -850,7 +850,26 @@ func Elfinit() {
}
}
// Make sure PT_LOAD is aligned properly and
// that there is no gap,
// correct ELF loaders will do this implicitly,
// but buggy ELF loaders like the one in some
// versions of QEMU and UPX won't.
func fixElfPhdr(e *ElfPhdr) {
frag := int(e.vaddr & (e.align - 1))
e.off -= uint64(frag)
e.vaddr -= uint64(frag)
e.paddr -= uint64(frag)
e.filesz += uint64(frag)
e.memsz += uint64(frag)
}
func elf64phdr(e *ElfPhdr) {
if e.type_ == PT_LOAD {
fixElfPhdr(e)
}
Thearch.Lput(e.type_)
Thearch.Lput(e.flags)
Thearch.Vput(e.off)
......@@ -863,16 +882,7 @@ func elf64phdr(e *ElfPhdr) {
func elf32phdr(e *ElfPhdr) {
if e.type_ == PT_LOAD {
// Correct ELF loaders will do this implicitly,
// but buggy ELF loaders like the one in some
// versions of QEMU won't.
frag := int(e.vaddr & (e.align - 1))
e.off -= uint64(frag)
e.vaddr -= uint64(frag)
e.paddr -= uint64(frag)
e.filesz += uint64(frag)
e.memsz += uint64(frag)
fixElfPhdr(e)
}
Thearch.Lput(e.type_)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment