[llvm] r204565 - WinCOFF: Add support for -ffunction-sections
David Majnemer
david.majnemer at gmail.com
Sun Mar 23 10:47:40 PDT 2014
Author: majnemer
Date: Sun Mar 23 12:47:39 2014
New Revision: 204565
URL: http://llvm.org/viewvc/llvm-project?rev=204565&view=rev
Log:
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.
Modified:
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/trunk/test/CodeGen/X86/global-sections.ll
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=204565&r1=204564&r2=204565&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Sun Mar 23 12:47:39 2014
@@ -768,18 +768,23 @@ static const char *getCOFFSectionNameFor
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())
Modified: llvm/trunk/test/CodeGen/X86/global-sections.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-sections.ll?rev=204565&r1=204564&r2=204565&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/global-sections.ll (original)
+++ llvm/trunk/test/CodeGen/X86/global-sections.ll Sun Mar 23 12:47:39 2014
@@ -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
More information about the llvm-commits
mailing list