mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
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
This commit is contained in:
@@ -147,6 +147,10 @@ public:
|
|||||||
SectionKind Kind, Mangler &Mang,
|
SectionKind Kind, Mangler &Mang,
|
||||||
const TargetMachine &TM) const override;
|
const TargetMachine &TM) const override;
|
||||||
|
|
||||||
|
const MCSection *
|
||||||
|
getSectionForJumpTable(const Function &F, Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const override;
|
||||||
|
|
||||||
/// Extract the dependent library name from a linker option string. Returns
|
/// Extract the dependent library name from a linker option string. Returns
|
||||||
/// StringRef() if the option does not specify a library.
|
/// StringRef() if the option does not specify a library.
|
||||||
StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
|
StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
|
||||||
|
@@ -948,6 +948,31 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
|||||||
return DataSection;
|
return DataSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MCSection *TargetLoweringObjectFileCOFF::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;
|
||||||
|
|
||||||
|
// FIXME: we should produce a symbol for F instead.
|
||||||
|
if (F.hasPrivateLinkage())
|
||||||
|
return ReadOnlySection;
|
||||||
|
|
||||||
|
MCSymbol *Sym = TM.getSymbol(&F, Mang);
|
||||||
|
StringRef COMDATSymName = Sym->getName();
|
||||||
|
|
||||||
|
SectionKind Kind = SectionKind::getReadOnly();
|
||||||
|
const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
|
||||||
|
unsigned Characteristics = getCOFFSectionFlags(Kind);
|
||||||
|
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
|
||||||
|
|
||||||
|
return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName,
|
||||||
|
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE);
|
||||||
|
}
|
||||||
|
|
||||||
StringRef TargetLoweringObjectFileCOFF::
|
StringRef TargetLoweringObjectFileCOFF::
|
||||||
getDepLibFromLinkerOpt(StringRef LinkerOption) const {
|
getDepLibFromLinkerOpt(StringRef LinkerOption) const {
|
||||||
const char *LibCmd = "/DEFAULTLIB:";
|
const char *LibCmd = "/DEFAULTLIB:";
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -function-sections | FileCheck %s -check-prefix=LINUX-FUNC-SECTIONS
|
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -function-sections | FileCheck %s -check-prefix=LINUX-FUNC-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=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
|
; RUN: llc < %s -mtriple=i686-pc-win32 -data-sections -function-sections | FileCheck %s -check-prefix=WIN32-SECTIONS
|
||||||
|
; RUN: llc < %s -mtriple=i686-pc-win32 -function-sections | FileCheck %s -check-prefix=WIN32-FUNC-SECTIONS
|
||||||
|
|
||||||
define void @F1() {
|
define void @F1() {
|
||||||
ret void
|
ret void
|
||||||
@@ -48,6 +49,11 @@ bb5:
|
|||||||
; LINUX-FUNC-SECTIONS-NEXT: .cfi_endproc
|
; LINUX-FUNC-SECTIONS-NEXT: .cfi_endproc
|
||||||
; LINUX-FUNC-SECTIONS-NEXT: .section .rodata.F2,"a",@progbits
|
; LINUX-FUNC-SECTIONS-NEXT: .section .rodata.F2,"a",@progbits
|
||||||
|
|
||||||
|
; WIN32-FUNC-SECTIONS: .section .text,"xr",one_only,_F2
|
||||||
|
; WIN32-FUNC-SECTIONS-NOT: .section
|
||||||
|
; WIN32-FUNC-SECTIONS: .section .rdata,"dr",associative,_F2
|
||||||
|
|
||||||
|
|
||||||
; LINUX-SECTIONS-PIC: .section .text.F2,"ax",@progbits
|
; LINUX-SECTIONS-PIC: .section .text.F2,"ax",@progbits
|
||||||
; LINUX-SECTIONS-PIC: .size F2,
|
; LINUX-SECTIONS-PIC: .size F2,
|
||||||
; LINUX-SECTIONS-PIC-NEXT: .cfi_endproc
|
; LINUX-SECTIONS-PIC-NEXT: .cfi_endproc
|
||||||
|
Reference in New Issue
Block a user