Commit 13c829e5 authored by Wedson Almeida Filho's avatar Wedson Almeida Filho Committed by David Chase

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 <main.jump>:
  401070:	ff 15 aa 7e 06 00    	callq  *0x67eaa(%rip)        # 468f20 <main.pointer>
  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 <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent d5a8b9f5
......@@ -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
......
// +build !amd64,!386
package main
func jump() {
target()
}
#include "textflag.h"
DATA ·pointer(SB)/4, target(SB)
GLOBL ·pointer(SB),RODATA,$4
TEXT ·jump(SB),NOSPLIT,$4
CALL *·pointer(SB)
RET
#include "textflag.h"
DATA ·pointer(SB)/8, target(SB)
GLOBL ·pointer(SB),RODATA,$8
TEXT ·jump(SB),NOSPLIT,$8
CALL *·pointer(SB)
RET
// +build amd64 386
package main
func jump()
package main
var called bool
func target() {
called = true
}
func main() {
jump()
if !called {
panic("target not called")
}
}
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