diff options
| author | Joel Sing <joel@sing.id.au> | 2019-09-20 03:25:16 +1000 |
|---|---|---|
| committer | Joel Sing <joel@sing.id.au> | 2019-11-06 17:03:51 +0000 |
| commit | a2b1dc863fe8effbb2aba2598fd37d3944c1dc4f (patch) | |
| tree | 925190eb558df3880f34324978ec4c1dbd2ce7f2 /src/cmd/internal/objabi | |
| parent | 4cb926001cbc068dac62012d86ed1dfbd0a66690 (diff) | |
| download | go-a2b1dc863fe8effbb2aba2598fd37d3944c1dc4f.tar.xz | |
cmd/link,cmd/internal/objabi: factor out direct call identification
Factor out the direct CALL identification code from objabi.IsDirectJump and
use this in two places that have separately maintained lists of reloc types.
Provide an objabi.IsDirectCallOrJump function that implements the original
behaviour of objabi.IsDirectJump.
Change-Id: I48131bae92b2938fd7822110d53df0b4ffb35766
Reviewed-on: https://go-review.googlesource.com/c/go/+/196577
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/objabi')
| -rw-r--r-- | src/cmd/internal/objabi/reloctype.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/cmd/internal/objabi/reloctype.go b/src/cmd/internal/objabi/reloctype.go index 5dc9356fe1..aed7e2a74d 100644 --- a/src/cmd/internal/objabi/reloctype.go +++ b/src/cmd/internal/objabi/reloctype.go @@ -223,16 +223,34 @@ const ( R_XCOFFREF ) +// IsDirectCall reports whether r is a relocation for a direct call. +// A direct call is a CALL instruction that takes the target address +// as an immediate. The address is embedded into the instruction, possibly +// with limited width. An indirect call is a CALL instruction that takes +// the target address in register or memory. +func (r RelocType) IsDirectCall() bool { + switch r { + case R_CALL, R_CALLARM, R_CALLARM64, R_CALLMIPS, R_CALLPOWER: + return true + } + return false +} + // IsDirectJump reports whether r is a relocation for a direct jump. -// A direct jump is a CALL or JMP instruction that takes the target address -// as immediate. The address is embedded into the instruction, possibly -// with limited width. -// An indirect jump is a CALL or JMP instruction that takes the target address -// in register or memory. +// A direct jump is a JMP instruction that takes the target address +// as an immediate. The address is embedded into the instruction, possibly +// with limited width. An indirect jump is a JMP instruction that takes +// the target address in register or memory. func (r RelocType) IsDirectJump() bool { switch r { - case R_CALL, R_CALLARM, R_CALLARM64, R_CALLPOWER, R_CALLMIPS, R_JMPMIPS: + case R_JMPMIPS: return true } return false } + +// IsDirectCallOrJump reports whether r is a relocation for a direct +// call or a direct jump. +func (r RelocType) IsDirectCallOrJump() bool { + return r.IsDirectCall() || r.IsDirectJump() +} |
