Skip to content

Commit c0c730d

Browse files
ianlancetayloraclements
authored andcommitted
[release-branch.go1.5] 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/16529 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-on: https://go-review.googlesource.com/16982 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
1 parent 8b3f554 commit c0c730d

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/cmd/link/internal/amd64/asm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
141141

142142
return
143143

144-
case 256 + ld.R_X86_64_GOTPCREL:
144+
case 256 + ld.R_X86_64_GOTPCREL, 256 + ld.R_X86_64_GOTPCRELX, 256 + ld.R_X86_64_REX_GOTPCRELX:
145145
if targ.Type != obj.SDYNIMPORT {
146146
// have symbol
147147
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {

src/cmd/link/internal/ld/elf.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,23 @@ const (
348348
R_X86_64_DTPOFF32 = 21
349349
R_X86_64_GOTTPOFF = 22
350350
R_X86_64_TPOFF32 = 23
351-
R_X86_64_COUNT = 24
351+
R_X86_64_PC64 = 24
352+
R_X86_64_GOTOFF64 = 25
353+
R_X86_64_GOTPC32 = 26
354+
R_X86_64_GOT64 = 27
355+
R_X86_64_GOTPCREL64 = 28
356+
R_X86_64_GOTPC64 = 29
357+
R_X86_64_GOTPLT64 = 30
358+
R_X86_64_PLTOFF64 = 31
359+
R_X86_64_SIZE32 = 32
360+
R_X86_64_SIZE64 = 33
361+
R_X86_64_GOTPC32_TLSDEC = 34
362+
R_X86_64_TLSDESC_CALL = 35
363+
R_X86_64_TLSDESC = 36
364+
R_X86_64_IRELATIVE = 37
365+
R_X86_64_PC32_BND = 40
366+
R_X86_64_GOTPCRELX = 41
367+
R_X86_64_REX_GOTPCRELX = 42
352368
R_AARCH64_ABS64 = 257
353369
R_AARCH64_ABS32 = 258
354370
R_AARCH64_CALL26 = 283
@@ -382,7 +398,6 @@ const (
382398
R_ALPHA_GLOB_DAT = 25
383399
R_ALPHA_JMP_SLOT = 26
384400
R_ALPHA_RELATIVE = 27
385-
R_ALPHA_COUNT = 28
386401
R_ARM_NONE = 0
387402
R_ARM_PC24 = 1
388403
R_ARM_ABS32 = 2
@@ -422,7 +437,6 @@ const (
422437
R_ARM_RABS32 = 253
423438
R_ARM_RPC24 = 254
424439
R_ARM_RBASE = 255
425-
R_ARM_COUNT = 38
426440
R_386_NONE = 0
427441
R_386_32 = 1
428442
R_386_PC32 = 2
@@ -454,7 +468,11 @@ const (
454468
R_386_TLS_DTPMOD32 = 35
455469
R_386_TLS_DTPOFF32 = 36
456470
R_386_TLS_TPOFF32 = 37
457-
R_386_COUNT = 38
471+
R_386_TLS_GOTDESC = 39
472+
R_386_TLS_DESC_CALL = 40
473+
R_386_TLS_DESC = 41
474+
R_386_IRELATIVE = 42
475+
R_386_GOT32X = 43
458476
R_PPC_NONE = 0
459477
R_PPC_ADDR32 = 1
460478
R_PPC_ADDR24 = 2
@@ -492,7 +510,6 @@ const (
492510
R_PPC_SECTOFF_LO = 34
493511
R_PPC_SECTOFF_HI = 35
494512
R_PPC_SECTOFF_HA = 36
495-
R_PPC_COUNT = 37
496513
R_PPC_TLS = 67
497514
R_PPC_DTPMOD32 = 68
498515
R_PPC_TPREL16 = 69
@@ -533,7 +550,6 @@ const (
533550
R_PPC_EMB_RELST_HA = 114
534551
R_PPC_EMB_BIT_FLD = 115
535552
R_PPC_EMB_RELSDA = 116
536-
R_PPC_EMB_COUNT = R_PPC_EMB_RELSDA - R_PPC_EMB_NADDR32 + 1
537553
R_PPC64_REL24 = R_PPC_REL24
538554
R_PPC64_JMP_SLOT = R_PPC_JMP_SLOT
539555
R_PPC64_ADDR64 = 38

src/cmd/link/internal/ld/ldelf.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,12 +1001,15 @@ func reltype(pn string, elftype int, siz *uint8) int {
10011001
'6' | R_X86_64_PC32<<24,
10021002
'6' | R_X86_64_PLT32<<24,
10031003
'6' | R_X86_64_GOTPCREL<<24,
1004+
'6' | R_X86_64_GOTPCRELX<<24,
1005+
'6' | R_X86_64_REX_GOTPCRELX<<24,
10041006
'8' | R_386_32<<24,
10051007
'8' | R_386_PC32<<24,
10061008
'8' | R_386_GOT32<<24,
10071009
'8' | R_386_PLT32<<24,
10081010
'8' | R_386_GOTOFF<<24,
10091011
'8' | R_386_GOTPC<<24,
1012+
'8' | R_386_GOT32X<<24,
10101013
'9' | R_PPC64_REL24<<24:
10111014
*siz = 4
10121015

src/cmd/link/internal/x86/asm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
7878

7979
return
8080

81-
case 256 + ld.R_386_GOT32:
81+
case 256 + ld.R_386_GOT32, 256 + ld.R_386_GOT32X:
8282
if targ.Type != obj.SDYNIMPORT {
8383
// have symbol
8484
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {

0 commit comments

Comments
 (0)