From 29786d4c161e6fd458fb2f1abc58a9f3401ee7f7 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 12 Feb 2015 17:16:46 +0000 Subject: 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 --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp') 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. -- cgit v1.2.3