[llvm] r203921 - [ppc64] Avoid copy relocs in named rodata sections

Ulrich Weigand ulrich.weigand at de.ibm.com
Fri Mar 14 05:45:23 PDT 2014


Author: uweigand
Date: Fri Mar 14 07:45:22 2014
New Revision: 203921

URL: http://llvm.org/viewvc/llvm-project?rev=203921&view=rev
Log:
[ppc64] Avoid copy relocs in named rodata sections

Commit r181723 introduced code to avoid placing initialized variables
needing relocations into the .rodata section, which avoid copy relocs
that do not work as expected on ppc64 function references.

The same treatment is also needed for *named* .rodata.XXX sections.
This patch changes PPC64LinuxTargetObjectFile::SelectSectionForGlobal
to modify "Kind" *before* calling the default SelectSectionForGlobal
routine, instead of first calling the default routine and then just
checking for the (main) .rodata section afterwards.


Added:
    llvm/trunk/test/CodeGen/PowerPC/vtable-reloc.ll
Modified:
    llvm/trunk/lib/Target/PowerPC/PPCTargetObjectFile.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetObjectFile.cpp?rev=203921&r1=203920&r2=203921&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCTargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCTargetObjectFile.cpp Fri Mar 14 07:45:22 2014
@@ -25,13 +25,6 @@ Initialize(MCContext &Ctx, const TargetM
 const MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
     const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
     const TargetMachine &TM) const {
-
-  const MCSection *DefaultSection = 
-    TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
-
-  if (DefaultSection != ReadOnlySection)
-    return DefaultSection;
-
   // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
   // when we have a constant that contains global relocations.  This is
   // necessary because of this ABI's handling of pointers to functions in
@@ -46,14 +39,17 @@ const MCSection *PPC64LinuxTargetObjectF
   // linker, so we must use DataRelROSection instead of ReadOnlySection.
   // For more information, see the description of ELIMINATE_COPY_RELOCS in
   // GNU ld.
-  const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
+  if (Kind.isReadOnly()) {
+    const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
 
-  if (GVar && GVar->isConstant() &&
-      (GVar->getInitializer()->getRelocationInfo() ==
-       Constant::GlobalRelocations))
-    return DataRelROSection;
+    if (GVar && GVar->isConstant() &&
+        (GVar->getInitializer()->getRelocationInfo() ==
+         Constant::GlobalRelocations))
+      Kind = SectionKind::getReadOnlyWithRel();
+  }
 
-  return DefaultSection;
+  return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind,
+                                                             Mang, TM);
 }
 
 const MCExpr *PPC64LinuxTargetObjectFile::

Added: llvm/trunk/test/CodeGen/PowerPC/vtable-reloc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/vtable-reloc.ll?rev=203921&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/vtable-reloc.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/vtable-reloc.ll Fri Mar 14 07:45:22 2014
@@ -0,0 +1,11 @@
+; RUN: llc -O0 < %s | FileCheck %s
+
+target datalayout = "E-m:e-i64:64-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"
+
+ at _ZTV3foo = linkonce_odr unnamed_addr constant [1 x i8*] [i8* bitcast (void ()* @__cxa_pure_virtual to i8*)]
+declare void @__cxa_pure_virtual()
+
+; CHECK: .section .data.rel.ro
+; CHECK: .quad __cxa_pure_virtual
+





More information about the llvm-commits mailing list