llvm.org GIT mirror llvm / 0c78583
Put jump tables in unique sections on COFF. If a function is going in an unique section (because of -ffunction-sections for example), putting a jump table in .rodata will keep .rodata alive and that will keep alive any other function that also has a jump table. Instead, put the jump table in a unique section that is associated with the function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231961 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
3 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
146146 SectionKind Kind, Mangler &Mang,
147147 const TargetMachine &TM) const override;
148148
149 const MCSection *
150 getSectionForJumpTable(const Function &F, Mangler &Mang,
151 const TargetMachine &TM) const override;
152
149153 /// Extract the dependent library name from a linker option string. Returns
150154 /// StringRef() if the option does not specify a library.
151155 StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
947947 return DataSection;
948948 }
949949
950 const MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable(
951 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
952 // If the function can be removed, produce a unique section so that
953 // the table doesn't prevent the removal.
954 const Comdat *C = F.getComdat();
955 bool EmitUniqueSection = TM.getFunctionSections() || C;
956 if (!EmitUniqueSection)
957 return ReadOnlySection;
958
959 // FIXME: we should produce a symbol for F instead.
960 if (F.hasPrivateLinkage())
961 return ReadOnlySection;
962
963 MCSymbol *Sym = TM.getSymbol(&F, Mang);
964 StringRef COMDATSymName = Sym->getName();
965
966 SectionKind Kind = SectionKind::getReadOnly();
967 const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
968 unsigned Characteristics = getCOFFSectionFlags(Kind);
969 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
970
971 return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName,
972 COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE);
973 }
974
950975 StringRef TargetLoweringObjectFileCOFF::
951976 getDepLibFromLinkerOpt(StringRef LinkerOption) const {
952977 const char *LibCmd = "/DEFAULTLIB:";
55 ; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -function-sections | FileCheck %s -check-prefix=LINUX-FUNC-SECTIONS
66 ; RUN: llc < %s -mtriple=x86_64-pc-linux -data-sections -function-sections -relocation-model=pic | FileCheck %s -check-prefix=LINUX-SECTIONS-PIC
77 ; RUN: llc < %s -mtriple=i686-pc-win32 -data-sections -function-sections | FileCheck %s -check-prefix=WIN32-SECTIONS
8 ; RUN: llc < %s -mtriple=i686-pc-win32 -function-sections | FileCheck %s -check-prefix=WIN32-FUNC-SECTIONS
89
910 define void @F1() {
1011 ret void
4647 ; LINUX-FUNC-SECTIONS: .size F2,
4748 ; LINUX-FUNC-SECTIONS-NEXT: .cfi_endproc
4849 ; LINUX-FUNC-SECTIONS-NEXT: .section .rodata.F2,"a",@progbits
50
51 ; WIN32-FUNC-SECTIONS: .section .text,"xr",one_only,_F2
52 ; WIN32-FUNC-SECTIONS-NOT: .section
53 ; WIN32-FUNC-SECTIONS: .section .rdata,"dr",associative,_F2
54
4955
5056 ; LINUX-SECTIONS-PIC: .section .text.F2,"ax",@progbits
5157 ; LINUX-SECTIONS-PIC: .size F2,