From: Wedson Almeida Filho Date: Mon, 2 May 2016 23:28:23 +0000 (+0100) Subject: cmd/internal/obj/x86: On amd64, relocation type for and indirect call is pc-relative. X-Git-Tag: go1.8beta1~968 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=13c829e5f6c541359c7bb213774ef9bbba9ddb77;p=gostls13.git cmd/internal/obj/x86: On amd64, relocation type for and indirect call is pc-relative. With this change, the code in bug #15609 compiles and runs properly: 0000000000401070 : 401070: ff 15 aa 7e 06 00 callq *0x67eaa(%rip) # 468f20 401076: c3 retq 0000000000468f20 g O .rodata 0000000000000008 main.pointer Fixes #15609 Change-Id: Iebb4d5a9f9fff335b693f4efcc97882fe04eefd7 Reviewed-on: https://go-review.googlesource.com/22950 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- diff --git a/src/cmd/internal/obj/x86/asm6.go b/src/cmd/internal/obj/x86/asm6.go index c023775f90..7efc30e03c 100644 --- a/src/cmd/internal/obj/x86/asm6.go +++ b/src/cmd/internal/obj/x86/asm6.go @@ -3691,7 +3691,11 @@ func doasm(ctxt *obj.Link, p *obj.Prog) { ctxt.AsmBuf.Put2(byte(op), o.op[z+1]) r = obj.Addrel(ctxt.Cursym) r.Off = int32(p.Pc + int64(ctxt.AsmBuf.Len())) - r.Type = obj.R_ADDR + if p.Mode == 64 { + r.Type = obj.R_PCREL + } else { + r.Type = obj.R_ADDR + } r.Siz = 4 r.Add = p.To.Offset r.Sym = p.To.Sym diff --git a/test/fixedbugs/issue15609.dir/call.go b/test/fixedbugs/issue15609.dir/call.go new file mode 100644 index 0000000000..41a489cebd --- /dev/null +++ b/test/fixedbugs/issue15609.dir/call.go @@ -0,0 +1,7 @@ +// +build !amd64,!386 + +package main + +func jump() { + target() +} diff --git a/test/fixedbugs/issue15609.dir/call_386.s b/test/fixedbugs/issue15609.dir/call_386.s new file mode 100644 index 0000000000..751084c485 --- /dev/null +++ b/test/fixedbugs/issue15609.dir/call_386.s @@ -0,0 +1,8 @@ +#include "textflag.h" + +DATA ·pointer(SB)/4, $·target(SB) +GLOBL ·pointer(SB),RODATA,$4 + +TEXT ·jump(SB),NOSPLIT,$4 + CALL *·pointer(SB) + RET diff --git a/test/fixedbugs/issue15609.dir/call_amd64.s b/test/fixedbugs/issue15609.dir/call_amd64.s new file mode 100644 index 0000000000..09fbe5dfc4 --- /dev/null +++ b/test/fixedbugs/issue15609.dir/call_amd64.s @@ -0,0 +1,8 @@ +#include "textflag.h" + +DATA ·pointer(SB)/8, $·target(SB) +GLOBL ·pointer(SB),RODATA,$8 + +TEXT ·jump(SB),NOSPLIT,$8 + CALL *·pointer(SB) + RET diff --git a/test/fixedbugs/issue15609.dir/call_decl.go b/test/fixedbugs/issue15609.dir/call_decl.go new file mode 100644 index 0000000000..d9c5a4e9f0 --- /dev/null +++ b/test/fixedbugs/issue15609.dir/call_decl.go @@ -0,0 +1,5 @@ +// +build amd64 386 + +package main + +func jump() diff --git a/test/fixedbugs/issue15609.dir/main.go b/test/fixedbugs/issue15609.dir/main.go new file mode 100644 index 0000000000..4855e31e5e --- /dev/null +++ b/test/fixedbugs/issue15609.dir/main.go @@ -0,0 +1,14 @@ +package main + +var called bool + +func target() { + called = true +} + +func main() { + jump() + if !called { + panic("target not called") + } +}