[llvm-commits] [llvm] r167877 - in /llvm/trunk: lib/CodeGen/TargetLoweringObjectFileImpl.cpp test/MC/COFF/weak-symbol-section-specification.ll
Michael J. Spencer
bigcheesegs at gmail.com
Tue Nov 13 14:04:10 PST 2012
Author: mspencer
Date: Tue Nov 13 16:04:09 2012
New Revision: 167877
URL: http://llvm.org/viewvc/llvm-project?rev=167877&view=rev
Log:
[MC][COFF] Emit weak symbols to the correct section. Patch by Dmitry Puzirev!
Added:
llvm/trunk/test/MC/COFF/weak-symbol-section-specification.ll
Modified:
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=167877&r1=167876&r2=167877&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Tue Nov 13 16:04:09 2012
@@ -701,8 +701,19 @@
const MCSection *TargetLoweringObjectFileCOFF::
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
- return getContext().getCOFFSection(GV->getSection(),
- getCOFFSectionFlags(Kind),
+ int Selection = 0;
+ unsigned Characteristics = getCOFFSectionFlags(Kind);
+ SmallString<128> Name(GV->getSection().c_str());
+ if (GV->isWeakForLinker()) {
+ Selection = COFF::IMAGE_COMDAT_SELECT_ANY;
+ Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
+ MCSymbol *Sym = Mang->getSymbol(GV);
+ Name.append("$");
+ Name.append(Sym->getName().begin() + 1, Sym->getName().end());
+ }
+ return getContext().getCOFFSection(Name,
+ Characteristics,
+ Selection,
Kind);
}
Added: llvm/trunk/test/MC/COFF/weak-symbol-section-specification.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/weak-symbol-section-specification.ll?rev=167877&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/weak-symbol-section-specification.ll (added)
+++ llvm/trunk/test/MC/COFF/weak-symbol-section-specification.ll Tue Nov 13 16:04:09 2012
@@ -0,0 +1,23 @@
+; The purpose of this test is to verify that weak linkage type is not ignored by backend,
+; if section was specialized.
+
+; RUN: llc -filetype=obj -mtriple i686-pc-win32 %s -o - | coff-dump.py | FileCheck %s
+
+ at a = weak unnamed_addr constant { i32, i32, i32 } { i32 0, i32 0, i32 0}, section ".data"
+
+; CHECK: Name = .data$a
+; CHECK-NEXT: VirtualSize = 0
+; CHECK-NEXT: VirtualAddress = 0
+; CHECK-NEXT: SizeOfRawData = {{[0-9]+}}
+; CHECK-NEXT: PointerToRawData = 0x{{[0-9A-F]+}}
+; CHECK-NEXT: PointerToRelocations = 0x0
+; CHECK-NEXT: PointerToLineNumbers = 0x0
+; CHECK-NEXT: NumberOfRelocations = 0
+; CHECK-NEXT: NumberOfLineNumbers = 0
+; CHECK-NEXT: Charateristics = 0x40401040
+; CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
+; CHECK-NEXT: IMAGE_SCN_LNK_COMDAT
+; CHECK-NEXT: IMAGE_SCN_ALIGN_8BYTES
+; CHECK-NEXT: IMAGE_SCN_MEM_READ
+; CHECK-NEXT: SectionData =
+; CHECK-NEXT: 00 00 00 00 00 00 00 00 - 00 00 00 00
More information about the llvm-commits
mailing list