]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: handle absolute address relocation in C objects for internal linking PIE
authorCherry Zhang <cherryyz@google.com>
Sun, 9 Feb 2020 22:00:27 +0000 (17:00 -0500)
committerCherry Zhang <cherryyz@google.com>
Fri, 21 Feb 2020 21:33:57 +0000 (21:33 +0000)
For an absolute address relocation in C objects (e.g.
R_X86_64_64), we turn it into an R_ADDR relocation and handle it
the same way. For internal linking PIE, this R_ADDR relocation
cannot be resolved statically. We need to generate a dynamic
relocation for it. This CL makes it so.

This fixes internal linking PIE on the dev.boringcrypto branch.
Test will be enabled in the next CL.

Change-Id: I9bdd6517ccd79cbbe9c64844a31536bf3da37616
Reviewed-on: https://go-review.googlesource.com/c/go/+/218837
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm64/asm.go

index 74fa8dbb90489ee438897e3d8c14e3bd0c6c86dc..5de77180fcc456ff000bb14192d2422c5b218cf1 100644 (file)
@@ -174,6 +174,12 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
                        ld.Errorf(s, "unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
                }
                r.Type = objabi.R_ADDR
+               if ctxt.BuildMode == ld.BuildModePIE && ctxt.LinkMode == ld.LinkInternal {
+                       // For internal linking PIE, this R_ADDR relocation cannot
+                       // be resolved statically. We need to generate a dynamic
+                       // relocation. Let the code below handle it.
+                       break
+               }
                return true
 
        // Handle relocations found in Mach-O object files.
index 690116de0101988ac32bee8955d1c07b3ad31383..ef9540b2a7b5f70a6912a12ab7984c0c8980f095 100644 (file)
@@ -172,6 +172,12 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
                        ld.Errorf(s, "unexpected R_AARCH64_ABS64 relocation for dynamic symbol %s", targ.Name)
                }
                r.Type = objabi.R_ADDR
+               if ctxt.BuildMode == ld.BuildModePIE && ctxt.LinkMode == ld.LinkInternal {
+                       // For internal linking PIE, this R_ADDR relocation cannot
+                       // be resolved statically. We need to generate a dynamic
+                       // relocation. Let the code below handle it.
+                       break
+               }
                return true
 
        case objabi.ElfRelocOffset + objabi.RelocType(elf.R_AARCH64_LDST8_ABS_LO12_NC):