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

Matthias Braun mbraun at apple.com
Fri Feb 13 17:20:28 PST 2015


Hi Rafael,

I reverted this commit for now as it also breaks a bunch of llvm-testsuite programs (at least on darwin):
FAIL: External/SPEC/CFP2006/447_dealII/447_dealII.execution_time (849 of 1696)
FAIL: External/SPEC/CFP2006/450_soplex/450_soplex.execution_time (850 of 1696)
FAIL: External/SPEC/CINT2006/483_xalancbmk/483_xalancbmk.execution_time (851 of 1696)
FAIL: MultiSource/Applications/hbd/hbd.execution_time (852 of 1696)
FAIL: MultiSource/Applications/kimwitu++/kc.execution_time (853 of 1696)
FAIL: MultiSource/Applications/lambda-0_1_3/lambda.execution_time (854 of 1696)
FAIL: MultiSource/Benchmarks/Bullet/bullet.execution_time (855 of 1696)
FAIL: MultiSource/Benchmarks/Prolangs-C++/employ/employ.execution_time (856 of 1696)
I tracked the lambda one down to a change in the way some exception handling table is emitter I believe:

 GCC_except_table4:
 Lexception4:
...
    .byte   0                       ##   On action: cleanup
    .align  2
-   .section    __TEXT,__text,regular,pure_instructions
-   .align  2, 0x90
+   .align  2
 L4_0_set_50 = LBB4_50-LJTI4_0
 L4_0_set_5 = LBB4_5-LJTI4_0
...
    .long   L4_0_set_10
    .long   L4_0_set_40

+   .section    __TEXT,__text,regular,pure_instructions
    .globl  __ZN24lambda_expression_parser10definitionEPP11arglst_node
    .align  4, 0x90

assembly files are attached.

- Matthias


> On Feb 13, 2015, at 2:56 PM, Anna Zaks <ganna at apple.com> wrote:
> 
> Rafael,
> 
> This commit is causing a lot of ASan Unit test failures on darwin:
> http://lab.llvm.org:8080/green/view/All/job/clang-stage1-cmake-RA_check/1487/console <http://lab.llvm.org:8080/green/view/All/job/clang-stage1-cmake-RA_check/1487/console>
> 
> Some are failing with EXC_I386_GPFLT some with EXC_BAD_ACCESS.
> 
> Please, revert.
> 
> Thank you,
> Anna.
> 
>> On Feb 12, 2015, at 9:46 AM, Rafael Espindola <rafael.espindola at gmail.com <mailto:rafael.espindola at gmail.com>> wrote:
>> 
>> Author: rafael
>> Date: Thu Feb 12 11:46:49 2015
>> New Revision: 228939
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=228939&view=rev <http://llvm.org/viewvc/llvm-project?rev=228939&view=rev>
>> Log:
>> On ELF, put PIC jump tables in a non executable section.
>> 
>> Fixes PR22558.
>> 
>> 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=228939&r1=228938&r2=228939&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h?rev=228939&r1=228938&r2=228939&view=diff>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (original)
>> +++ llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h Thu Feb 12 11:46:49 2015
>> @@ -60,6 +60,9 @@ 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=228939&r1=228938&r2=228939&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=228939&r1=228938&r2=228939&view=diff>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
>> +++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Thu Feb 12 11:46:49 2015
>> @@ -98,6 +98,9 @@ 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=228939&r1=228938&r2=228939&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=228939&r1=228938&r2=228939&view=diff>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Thu Feb 12 11:46:49 2015
>> @@ -1178,23 +1178,14 @@ void AsmPrinter::EmitJumpTableInfo() {
>>   // the appropriate section.
>>   const Function *F = MF->getFunction();
>>   const TargetLoweringObjectFile &TLOF = getObjFileLowering();
>> -  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 {
>> +  bool JTInDiffSection = !TLOF.shouldPutJumpTableInFunctionSection(
>> +      MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32,
>> +      *F);
>> +  if (JTInDiffSection) {
>>     // 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=228939&r1=228938&r2=228939&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=228939&r1=228938&r2=228939&view=diff>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Thu Feb 12 11:46:49 2015
>> @@ -356,6 +356,13 @@ 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=228939&r1=228938&r2=228939&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=228939&r1=228938&r2=228939&view=diff>
>> ==============================================================================
>> --- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
>> +++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Thu Feb 12 11:46:49 2015
>> @@ -275,6 +275,24 @@ 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=228939&r1=228938&r2=228939&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-sections.ll?rev=228939&r1=228938&r2=228939&view=diff>
>> ==============================================================================
>> --- llvm/trunk/test/CodeGen/X86/global-sections.ll (original)
>> +++ llvm/trunk/test/CodeGen/X86/global-sections.ll Thu Feb 12 11:46:49 2015
>> @@ -3,6 +3,7 @@
>> ; 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() {
>> @@ -41,6 +42,11 @@ 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
>> 
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/0dc2bd83/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bad.s
Type: application/octet-stream
Size: 49262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/0dc2bd83/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/0dc2bd83/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: good.s
Type: application/octet-stream
Size: 49268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/0dc2bd83/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/0dc2bd83/attachment-0002.html>


More information about the llvm-commits mailing list