From baea3cd7c9e7ae27f7e5d44874a9afd249458df5 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sun, 9 Feb 2020 17:00:27 -0500 Subject: [PATCH] cmd/link: handle absolute address relocation in C objects for internal linking PIE 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/amd64/asm.go | 6 ++++++ src/cmd/link/internal/arm64/asm.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index 74fa8dbb90..5de77180fc 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -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. diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go index 690116de01..ef9540b2a7 100644 --- a/src/cmd/link/internal/arm64/asm.go +++ b/src/cmd/link/internal/arm64/asm.go @@ -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): -- 2.50.0