Commit 914db9f0 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/link: support new 386/amd64 relocations

The GNU binutils recently picked up support for new 386/amd64
relocations.  Add support for them in the Go linker when doing an
internal link.

The 386 relocation R_386_GOT32X was proposed in
https://groups.google.com/forum/#!topic/ia32-abi/GbJJskkid4I .  It can
be treated as identical to the R_386_GOT32 relocation.

The amd64 relocations R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX were
proposed in
https://groups.google.com/forum/#!topic/x86-64-abi/n9AWHogmVY0 .  They
can both be treated as identical to the R_X86_64_GOTPCREL relocation.

The purpose of the new relocations is to permit additional linker
relaxations in some cases.  We do not attempt to support those cases.

While we're at it, remove the unused and in some cases out of date
_COUNT names from ld/elf.go.

Fixes #13114.

Change-Id: I34ef07f6fcd00cdd2996038ecf46bb77a49e968b
Reviewed-on: https://go-review.googlesource.com/16529Reviewed-by: default avatarMinux Ma <minux@golang.org>
parent ce304585
...@@ -139,7 +139,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { ...@@ -139,7 +139,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
return return
case 256 + ld.R_X86_64_GOTPCREL: case 256 + ld.R_X86_64_GOTPCREL, 256 + ld.R_X86_64_GOTPCRELX, 256 + ld.R_X86_64_REX_GOTPCRELX:
if targ.Type != obj.SDYNIMPORT { if targ.Type != obj.SDYNIMPORT {
// have symbol // have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b { if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
......
...@@ -349,7 +349,23 @@ const ( ...@@ -349,7 +349,23 @@ const (
R_X86_64_DTPOFF32 = 21 R_X86_64_DTPOFF32 = 21
R_X86_64_GOTTPOFF = 22 R_X86_64_GOTTPOFF = 22
R_X86_64_TPOFF32 = 23 R_X86_64_TPOFF32 = 23
R_X86_64_COUNT = 24 R_X86_64_PC64 = 24
R_X86_64_GOTOFF64 = 25
R_X86_64_GOTPC32 = 26
R_X86_64_GOT64 = 27
R_X86_64_GOTPCREL64 = 28
R_X86_64_GOTPC64 = 29
R_X86_64_GOTPLT64 = 30
R_X86_64_PLTOFF64 = 31
R_X86_64_SIZE32 = 32
R_X86_64_SIZE64 = 33
R_X86_64_GOTPC32_TLSDEC = 34
R_X86_64_TLSDESC_CALL = 35
R_X86_64_TLSDESC = 36
R_X86_64_IRELATIVE = 37
R_X86_64_PC32_BND = 40
R_X86_64_GOTPCRELX = 41
R_X86_64_REX_GOTPCRELX = 42
R_AARCH64_ABS64 = 257 R_AARCH64_ABS64 = 257
R_AARCH64_ABS32 = 258 R_AARCH64_ABS32 = 258
...@@ -388,7 +404,6 @@ const ( ...@@ -388,7 +404,6 @@ const (
R_ALPHA_GLOB_DAT = 25 R_ALPHA_GLOB_DAT = 25
R_ALPHA_JMP_SLOT = 26 R_ALPHA_JMP_SLOT = 26
R_ALPHA_RELATIVE = 27 R_ALPHA_RELATIVE = 27
R_ALPHA_COUNT = 28
R_ARM_NONE = 0 R_ARM_NONE = 0
R_ARM_PC24 = 1 R_ARM_PC24 = 1
...@@ -429,7 +444,6 @@ const ( ...@@ -429,7 +444,6 @@ const (
R_ARM_RABS32 = 253 R_ARM_RABS32 = 253
R_ARM_RPC24 = 254 R_ARM_RPC24 = 254
R_ARM_RBASE = 255 R_ARM_RBASE = 255
R_ARM_COUNT = 38
R_386_NONE = 0 R_386_NONE = 0
R_386_32 = 1 R_386_32 = 1
...@@ -462,7 +476,11 @@ const ( ...@@ -462,7 +476,11 @@ const (
R_386_TLS_DTPMOD32 = 35 R_386_TLS_DTPMOD32 = 35
R_386_TLS_DTPOFF32 = 36 R_386_TLS_DTPOFF32 = 36
R_386_TLS_TPOFF32 = 37 R_386_TLS_TPOFF32 = 37
R_386_COUNT = 38 R_386_TLS_GOTDESC = 39
R_386_TLS_DESC_CALL = 40
R_386_TLS_DESC = 41
R_386_IRELATIVE = 42
R_386_GOT32X = 43
R_PPC_NONE = 0 R_PPC_NONE = 0
R_PPC_ADDR32 = 1 R_PPC_ADDR32 = 1
...@@ -501,7 +519,6 @@ const ( ...@@ -501,7 +519,6 @@ const (
R_PPC_SECTOFF_LO = 34 R_PPC_SECTOFF_LO = 34
R_PPC_SECTOFF_HI = 35 R_PPC_SECTOFF_HI = 35
R_PPC_SECTOFF_HA = 36 R_PPC_SECTOFF_HA = 36
R_PPC_COUNT = 37
R_PPC_TLS = 67 R_PPC_TLS = 67
R_PPC_DTPMOD32 = 68 R_PPC_DTPMOD32 = 68
R_PPC_TPREL16 = 69 R_PPC_TPREL16 = 69
...@@ -542,7 +559,6 @@ const ( ...@@ -542,7 +559,6 @@ const (
R_PPC_EMB_RELST_HA = 114 R_PPC_EMB_RELST_HA = 114
R_PPC_EMB_BIT_FLD = 115 R_PPC_EMB_BIT_FLD = 115
R_PPC_EMB_RELSDA = 116 R_PPC_EMB_RELSDA = 116
R_PPC_EMB_COUNT = R_PPC_EMB_RELSDA - R_PPC_EMB_NADDR32 + 1
R_PPC64_REL24 = R_PPC_REL24 R_PPC64_REL24 = R_PPC_REL24
R_PPC64_JMP_SLOT = R_PPC_JMP_SLOT R_PPC64_JMP_SLOT = R_PPC_JMP_SLOT
......
...@@ -1137,12 +1137,15 @@ func reltype(pn string, elftype int, siz *uint8) int { ...@@ -1137,12 +1137,15 @@ func reltype(pn string, elftype int, siz *uint8) int {
'6' | R_X86_64_PC32<<24, '6' | R_X86_64_PC32<<24,
'6' | R_X86_64_PLT32<<24, '6' | R_X86_64_PLT32<<24,
'6' | R_X86_64_GOTPCREL<<24, '6' | R_X86_64_GOTPCREL<<24,
'6' | R_X86_64_GOTPCRELX<<24,
'6' | R_X86_64_REX_GOTPCRELX<<24,
'8' | R_386_32<<24, '8' | R_386_32<<24,
'8' | R_386_PC32<<24, '8' | R_386_PC32<<24,
'8' | R_386_GOT32<<24, '8' | R_386_GOT32<<24,
'8' | R_386_PLT32<<24, '8' | R_386_PLT32<<24,
'8' | R_386_GOTOFF<<24, '8' | R_386_GOTOFF<<24,
'8' | R_386_GOTPC<<24, '8' | R_386_GOTPC<<24,
'8' | R_386_GOT32X<<24,
'9' | R_PPC64_REL24<<24: '9' | R_PPC64_REL24<<24:
*siz = 4 *siz = 4
......
...@@ -78,7 +78,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { ...@@ -78,7 +78,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
return return
case 256 + ld.R_386_GOT32: case 256 + ld.R_386_GOT32, 256 + ld.R_386_GOT32X:
if targ.Type != obj.SDYNIMPORT { if targ.Type != obj.SDYNIMPORT {
// have symbol // have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b { if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
......
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