summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-03-23 17:47:39 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-03-23 17:47:39 +0000
commit77df5169a8323919b74084fb15154d9a1609f570 (patch)
tree5302e06482e68dc73facbf783bab69c67ada2b04
parent2ca626570fa1f2837bd0cea06303ed46890c6480 (diff)
WinCOFF: Add support for -ffunction-sections
This is a pretty straight forward translation for COFF, we just need to stick the function in a COMDAT section marked as IMAGE_COMDAT_SELECT_NODUPLICATES. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204565 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/TargetLoweringObjectFileImpl.cpp13
-rw-r--r--test/CodeGen/X86/global-sections.ll8
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index a2f4810cb6c..8f113d79162 100644
--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -768,18 +768,23 @@ static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
const MCSection *TargetLoweringObjectFileCOFF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM) const {
+ // If we have -ffunction-sections then we should emit the global value to a
+ // uniqued section specifically for it.
+ // TODO: Implement -fdata-sections.
+ bool EmitUniquedSection = Kind.isText() && TM.getFunctionSections();
// If this global is linkonce/weak and the target handles this by emitting it
// into a 'uniqued' section name, create and return the section now.
- if (GV->isWeakForLinker()) {
+ if (GV->isWeakForLinker() || EmitUniquedSection) {
const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
unsigned Characteristics = getCOFFSectionFlags(Kind);
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
MCSymbol *Sym = TM.getSymbol(GV, Mang);
- return getContext().getCOFFSection(Name, Characteristics,
- Kind, Sym->getName(),
- COFF::IMAGE_COMDAT_SELECT_ANY);
+ return getContext().getCOFFSection(
+ Name, Characteristics, Kind, Sym->getName(),
+ GV->isWeakForLinker() ? COFF::IMAGE_COMDAT_SELECT_ANY
+ : COFF::IMAGE_COMDAT_SELECT_NODUPLICATES);
}
if (Kind.isText())
diff --git a/test/CodeGen/X86/global-sections.ll b/test/CodeGen/X86/global-sections.ll
index c031821f9a6..c768c303c87 100644
--- a/test/CodeGen/X86/global-sections.ll
+++ b/test/CodeGen/X86/global-sections.ll
@@ -3,6 +3,7 @@
; RUN: llc < %s -mtriple=i386-apple-darwin10 -relocation-model=static | FileCheck %s -check-prefix=DARWIN-STATIC
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 | FileCheck %s -check-prefix=DARWIN64
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -fdata-sections | FileCheck %s -check-prefix=LINUX-SECTIONS
+; RUN: llc < %s -mtriple=i686-pc-win32 -ffunction-sections | FileCheck %s -check-prefix=WIN32-SECTIONS
; int G1;
@@ -176,3 +177,10 @@
; LINUX-SECTIONS: .LG14:
; LINUX-SECTIONS: .asciz "foo"
; LINUX-SECTIONS: .size .LG14, 4
+
+define void @G15() {
+ ret void
+}
+
+; WIN32-SECTIONS: .section .text,"xr",one_only,_G15
+; WIN32-SECTIONS: .globl _G15