From e5062a6caf754de30b4ecba5bf670ee250f78554 Mon Sep 17 00:00:00 2001 From: jasonliu Date: Thu, 6 Aug 2020 13:19:59 +0000 Subject: [XCOFF][AIX] Put each jump table in an independent section if -ffunction-sections is specified If a function is in a unique section, putting all jump tables in .rodata will prevent functions that have a jump table to get garbage collect by the linker. Therefore, we need to put jump table into a unique section as well. Reviewed By: Xiangling_L Differential Revision: https://reviews.llvm.org/D84761 --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 8ef91250423f..fc08fb95123b 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -2085,11 +2085,18 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal( MCSection *TargetLoweringObjectFileXCOFF::getSectionForJumpTable( const Function &F, const TargetMachine &TM) const { - assert (!TM.getFunctionSections() && "Unique sections not supported on XCOFF" - " yet."); assert (!F.getComdat() && "Comdat not supported on XCOFF."); - //TODO: Enable emiting jump table to unique sections when we support it. - return ReadOnlySection; + + if (!TM.getFunctionSections()) + return ReadOnlySection; + + // If the function can be removed, produce a unique section so that + // the table doesn't prevent the removal. + SmallString<128> NameStr(".rodata.jmp.."); + getNameWithPrefix(NameStr, &F, TM); + return getContext().getXCOFFSection(NameStr, XCOFF::XMC_RO, XCOFF::XTY_SD, + XCOFF::C_HIDEXT, + SectionKind::getReadOnly()); } bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection( -- cgit v1.2.3