Skip to content

Commit 958b37e

Browse files
committed
Merging r347431:
------------------------------------------------------------------------ r347431 | rnk | 2018-11-21 14:01:10 -0800 (Wed, 21 Nov 2018) | 12 lines [mingw] Use unmangled name after the $ in the section name GCC does it this way, and we have to be consistent. This includes stdcall and fastcall functions with suffixes. I confirmed that a fastcall function named "foo" ends up in ".text$foo", not ".text$@foo@8". Based on a patch by Andrew Yohn! Fixes PR39218. Differential Revision: https://reviews.llvm.org/D54762 ------------------------------------------------------------------------ llvm-svn: 347931
1 parent 938be89 commit 958b37e

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,10 +1156,11 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
11561156
MCSymbol *Sym = TM.getSymbol(ComdatGV);
11571157
StringRef COMDATSymName = Sym->getName();
11581158

1159-
// Append "$symbol" to the section name when targetting mingw. The ld.bfd
1159+
// Append "$symbol" to the section name *before* IR-level mangling is
1160+
// applied when targetting mingw. This is what GCC does, and the ld.bfd
11601161
// COFF linker will not properly handle comdats otherwise.
11611162
if (getTargetTriple().isWindowsGNUEnvironment())
1162-
raw_svector_ostream(Name) << '$' << COMDATSymName;
1163+
raw_svector_ostream(Name) << '$' << ComdatGV->getName();
11631164

11641165
return getContext().getCOFFSection(Name, Characteristics, Kind,
11651166
COMDATSymName, Selection, UniqueID);

llvm/test/CodeGen/X86/mingw-comdats.ll

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
; RUN: llc -mtriple=x86_64-windows-itanium < %s | FileCheck %s
2-
; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
3-
; RUN: llc -mtriple=x86_64-w64-windows-gnu < %s | FileCheck %s --check-prefix=GNU
4-
; RUN: llc -mtriple=i686-w64-windows-gnu < %s | FileCheck %s --check-prefix=GNU32
5-
; RUN: llc -mtriple=x86_64-w64-windows-gnu < %s -filetype=obj | llvm-objdump - -headers | FileCheck %s --check-prefix=GNUOBJ
1+
; RUN: llc -function-sections -mtriple=x86_64-windows-itanium < %s | FileCheck %s
2+
; RUN: llc -function-sections -mtriple=x86_64-windows-msvc < %s | FileCheck %s
3+
; RUN: llc -function-sections -mtriple=x86_64-w64-windows-gnu < %s | FileCheck %s --check-prefix=GNU
4+
; RUN: llc -function-sections -mtriple=i686-w64-windows-gnu < %s | FileCheck %s --check-prefix=GNU32
5+
; RUN: llc -function-sections -mtriple=x86_64-w64-windows-gnu < %s -filetype=obj | llvm-objdump - -headers | FileCheck %s --check-prefix=GNUOBJ
66

77
; GCC and MSVC handle comdats completely differently. Make sure we do the right
88
; thing for each.
99

10-
; Generated with this C++ source:
10+
; Modeled on this C++ source, with additional modifications for
11+
; -ffunction-sections:
1112
; int bar(int);
1213
; __declspec(selectany) int gv = 42;
1314
; inline int foo(int x) { return bar(x) + gv; }
@@ -26,8 +27,24 @@ entry:
2627
ret i32 %call
2728
}
2829

30+
; CHECK: .section .text,"xr",one_only,main
2931
; CHECK: main:
32+
; GNU: .section .text$main,"xr",one_only,main
3033
; GNU: main:
34+
; GNU32: .section .text$main,"xr",one_only,_main
35+
; GNU32: _main:
36+
37+
define dso_local x86_fastcallcc i32 @fastcall(i32 %x, i32 %y) {
38+
%rv = add i32 %x, %y
39+
ret i32 %rv
40+
}
41+
42+
; CHECK: .section .text,"xr",one_only,fastcall
43+
; CHECK: fastcall:
44+
; GNU: .section .text$fastcall,"xr",one_only,fastcall
45+
; GNU: fastcall:
46+
; GNU32: .section .text$fastcall,"xr",one_only,@fastcall@8
47+
; GNU32: @fastcall@8:
3148

3249
; Function Attrs: inlinehint uwtable
3350
define linkonce_odr dso_local i32 @_Z3fooi(i32 %x) #1 comdat {
@@ -50,9 +67,9 @@ entry:
5067
; GNU: gv:
5168
; GNU: .long 42
5269

53-
; GNU32: .section .text$__Z3fooi,"xr",discard,__Z3fooi
70+
; GNU32: .section .text$_Z3fooi,"xr",discard,__Z3fooi
5471
; GNU32: __Z3fooi:
55-
; GNU32: .section .data$_gv,"dw",discard,_gv
72+
; GNU32: .section .data$gv,"dw",discard,_gv
5673
; GNU32: _gv:
5774
; GNU32: .long 42
5875

0 commit comments

Comments
 (0)