[llvm] r229203 - Revert "On ELF, put PIC jump tables in a non executable section."

Matthias Braun matze at braunis.de
Fri Feb 13 17:16:55 PST 2015


Author: matze
Date: Fri Feb 13 19:16:54 2015
New Revision: 229203

URL: http://llvm.org/viewvc/llvm-project?rev=229203&view=rev
Log:
Revert "On ELF, put PIC jump tables in a non executable section."

This reverts commit r228939.

The commit broke something in the output of exception handling tables on
darwin x86-64.

Modified:
    llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
    llvm/trunk/test/CodeGen/X86/global-sections.ll

Modified: llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h?rev=229203&r1=229202&r2=229203&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h Fri Feb 13 19:16:54 2015
@@ -60,9 +60,6 @@ public:
   getSectionForJumpTable(const Function &F, Mangler &Mang,
                          const TargetMachine &TM) const override;
 
-  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
-                                           const Function &F) const override;
-
   /// Return an MCExpr to use for a reference to the specified type info global
   /// variable from exception handling information.
   const MCExpr *

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=229203&r1=229202&r2=229203&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Fri Feb 13 19:16:54 2015
@@ -98,9 +98,6 @@ public:
   getSectionForJumpTable(const Function &F, Mangler &Mang,
                          const TargetMachine &TM) const;
 
-  virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
-                                                   const Function &F) const;
-
   /// Targets should implement this method to assign a section to globals with
   /// an explicit section specfied. The implementation of this method can
   /// assume that GV->hasSection() is true.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=229203&r1=229202&r2=229203&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Feb 13 19:16:54 2015
@@ -1178,14 +1178,23 @@ void AsmPrinter::EmitJumpTableInfo() {
   // the appropriate section.
   const Function *F = MF->getFunction();
   const TargetLoweringObjectFile &TLOF = getObjFileLowering();
-  bool JTInDiffSection = !TLOF.shouldPutJumpTableInFunctionSection(
-      MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32,
-      *F);
-  if (JTInDiffSection) {
+  bool JTInDiffSection = false;
+  if (// In PIC mode, we need to emit the jump table to the same section as the
+      // function body itself, otherwise the label differences won't make sense.
+      // FIXME: Need a better predicate for this: what about custom entries?
+      MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 ||
+      // We should also do if the section name is NULL or function is declared
+      // in discardable section
+      // FIXME: this isn't the right predicate, should be based on the MCSection
+      // for the function.
+      F->isWeakForLinker()) {
+    OutStreamer.SwitchSection(TLOF.SectionForGlobal(F, *Mang, TM));
+  } else {
     // Otherwise, drop it in the readonly section.
     const MCSection *ReadOnlySection =
         TLOF.getSectionForJumpTable(*F, *Mang, TM);
     OutStreamer.SwitchSection(ReadOnlySection);
+    JTInDiffSection = true;
   }
 
   EmitAlignment(Log2_32(

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=229203&r1=229202&r2=229203&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Fri Feb 13 19:16:54 2015
@@ -356,13 +356,6 @@ const MCSection *TargetLoweringObjectFil
   return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, Group);
 }
 
-bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
-    bool UsesLabelDifference, const Function &F) const {
-  // We can always create relative relocations, so use another section
-  // that can be marked non-executable.
-  return false;
-}
-
 /// getSectionForConstant - Given a mergeable constant with the
 /// specified size and relocation information, return a section that it
 /// should be placed in.

Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=229203&r1=229202&r2=229203&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Fri Feb 13 19:16:54 2015
@@ -275,24 +275,6 @@ const MCSection *TargetLoweringObjectFil
   return getSectionForConstant(SectionKind::getReadOnly(), /*C=*/nullptr);
 }
 
-bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
-    bool UsesLabelDifference, const Function &F) const {
-  // In PIC mode, we need to emit the jump table to the same section as the
-  // function body itself, otherwise the label differences won't make sense.
-  // FIXME: Need a better predicate for this: what about custom entries?
-  if (UsesLabelDifference)
-    return true;
-
-  // We should also do if the section name is NULL or function is declared
-  // in discardable section
-  // FIXME: this isn't the right predicate, should be based on the MCSection
-  // for the function.
-  if (F.isWeakForLinker())
-    return true;
-
-  return false;
-}
-
 /// getSectionForConstant - Given a mergable constant with the
 /// specified size and relocation information, return a section that it
 /// should be placed in.

Modified: llvm/trunk/test/CodeGen/X86/global-sections.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-sections.ll?rev=229203&r1=229202&r2=229203&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/global-sections.ll (original)
+++ llvm/trunk/test/CodeGen/X86/global-sections.ll Fri Feb 13 19:16:54 2015
@@ -3,7 +3,6 @@
 ; RUN: llc < %s -mtriple=i386-apple-darwin10 -relocation-model=static | FileCheck %s -check-prefix=DARWIN-STATIC
 ; RUN: llc < %s -mtriple=x86_64-apple-darwin10 | FileCheck %s -check-prefix=DARWIN64
 ; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -data-sections -function-sections | FileCheck %s -check-prefix=LINUX-SECTIONS
-; RUN: llc < %s -mtriple=x86_64-pc-linux -data-sections -function-sections -relocation-model=pic | FileCheck %s -check-prefix=LINUX-SECTIONS-PIC
 ; RUN: llc < %s -mtriple=i686-pc-win32 -data-sections -function-sections | FileCheck %s -check-prefix=WIN32-SECTIONS
 
 define void @F1() {
@@ -42,11 +41,6 @@ bb5:
 ; LINUX-SECTIONS-NEXT: .cfi_endproc
 ; LINUX-SECTIONS-NEXT: .section        .rodata.F2,"a", at progbits
 
-; LINUX-SECTIONS-PIC: .section        .text.F2,"ax", at progbits
-; LINUX-SECTIONS-PIC: .size   F2,
-; LINUX-SECTIONS-PIC-NEXT: .cfi_endproc
-; LINUX-SECTIONS-PIC-NEXT: .section        .rodata.F2,"a", at progbits
-
 ; int G1;
 @G1 = common global i32 0
 





More information about the llvm-commits mailing list