diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-02-12 17:16:46 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-02-12 17:16:46 +0000 |
commit | 29786d4c161e6fd458fb2f1abc58a9f3401ee7f7 (patch) | |
tree | d0f2822cd564783aabfca22128a79dc1227c735c /llvm/lib/CodeGen | |
parent | 40957cc2ce05a4355cf9f267b9d7930eee1a5093 (diff) | |
download | bcm5719-llvm-29786d4c161e6fd458fb2f1abc58a9f3401ee7f7.tar.gz bcm5719-llvm-29786d4c161e6fd458fb2f1abc58a9f3401ee7f7.zip |
Put each jump table in an independent section if the function is too.
This allows the linker to GC both, fixing pr22557.
llvm-svn: 228937
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 22 |
2 files changed, 25 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 7fb84605071..aacc486aa14 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1177,6 +1177,7 @@ void AsmPrinter::EmitJumpTableInfo() { // Pick the directive to use to print the jump table entries, and switch to // 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. @@ -1187,13 +1188,11 @@ void AsmPrinter::EmitJumpTableInfo() { // FIXME: this isn't the right predicate, should be based on the MCSection // for the function. F->isWeakForLinker()) { - OutStreamer.SwitchSection( - getObjFileLowering().SectionForGlobal(F, *Mang, TM)); + OutStreamer.SwitchSection(TLOF.SectionForGlobal(F, *Mang, TM)); } else { // Otherwise, drop it in the readonly section. const MCSection *ReadOnlySection = - getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly(), - /*C=*/nullptr); + TLOF.getSectionForJumpTable(*F, *Mang, TM); OutStreamer.SwitchSection(ReadOnlySection); JTInDiffSection = true; } diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index eac1245d829..0a49f5ff9fe 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -334,6 +334,28 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, return DataRelROSection; } +const MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable( + const Function &F, Mangler &Mang, const TargetMachine &TM) const { + // If the function can be removed, produce a unique section so that + // the table doesn't prevent the removal. + const Comdat *C = F.getComdat(); + bool EmitUniqueSection = TM.getFunctionSections() || C; + if (!EmitUniqueSection) + return ReadOnlySection; + + SmallString<128> Name(".rodata."); + TM.getNameWithPrefix(Name, &F, Mang, true); + + unsigned Flags = ELF::SHF_ALLOC; + StringRef Group = ""; + if (C) { + Flags |= ELF::SHF_GROUP; + Group = C->getName(); + } + + return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, Group); +} + /// getSectionForConstant - Given a mergeable constant with the /// specified size and relocation information, return a section that it /// should be placed in. |