This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Patch: Support toc relative access to dynamic symbols from static code.
- From: Kyle Butt <iteratee at google dot com>
- To: binutils at sourceware dot org
- Date: Tue, 17 Nov 2015 16:52:41 -0800
- Subject: Patch: Support toc relative access to dynamic symbols from static code.
- Authentication-results: sourceware.org; auth=none
This patch allows TOC16_* relocations to reference external global
symbols. Previously llvm was not emitting such accesses, but they are
allowed by the abi.
diff --git a/gold/powerpc.cc b/gold/powerpc.cc
index 3a013ef..7e330c3 100644
--- a/gold/powerpc.cc
+++ b/gold/powerpc.cc
@@ -6036,10 +6036,27 @@ Target_powerpc<size, big_endian>::Scan::global(
case elfcpp::R_PPC64_ADDR16_HIGHESTA:
case elfcpp::R_PPC64_ADDR16_DS:
case elfcpp::R_PPC64_ADDR16_LO_DS:
+ case elfcpp::R_PPC64_TOC16:
+ case elfcpp::R_PPC64_TOC16_LO:
+ case elfcpp::R_PPC64_TOC16_HI:
+ case elfcpp::R_PPC64_TOC16_HA:
+ case elfcpp::R_PPC64_TOC16_DS:
+ case elfcpp::R_PPC64_TOC16_LO_DS:
case elfcpp::R_POWERPC_ADDR14:
case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
{
+ // The toc-relative relocations need a GOT section
+ switch (r_type)
+ case elfcpp::R_PPC64_TOC16:
+ case elfcpp::R_PPC64_TOC16_LO:
+ case elfcpp::R_PPC64_TOC16_HI:
+ case elfcpp::R_PPC64_TOC16_HA:
+ case elfcpp::R_PPC64_TOC16_DS:
+ case elfcpp::R_PPC64_TOC16_LO_DS:
+ target->got_section(symtab, layout);
+ break;
+
// Make a PLT entry if necessary.
if (gsym->needs_plt_entry())
{
@@ -6248,16 +6265,6 @@ Target_powerpc<size, big_endian>::Scan::global(
}
break;
- case elfcpp::R_PPC64_TOC16:
- case elfcpp::R_PPC64_TOC16_LO:
- case elfcpp::R_PPC64_TOC16_HI:
- case elfcpp::R_PPC64_TOC16_HA:
- case elfcpp::R_PPC64_TOC16_DS:
- case elfcpp::R_PPC64_TOC16_LO_DS:
- // We need a GOT section.
- target->got_section(symtab, layout);
- break;
-
case elfcpp::R_POWERPC_GOT_TLSGD16:
case elfcpp::R_POWERPC_GOT_TLSGD16_LO:
case elfcpp::R_POWERPC_GOT_TLSGD16_HI: