2018-11-22 06:01:10 +08:00
|
|
|
; RUN: llc -function-sections -mtriple=x86_64-windows-itanium < %s | FileCheck %s
|
|
|
|
; RUN: llc -function-sections -mtriple=x86_64-windows-msvc < %s | FileCheck %s
|
|
|
|
; RUN: llc -function-sections -mtriple=x86_64-w64-windows-gnu < %s | FileCheck %s --check-prefix=GNU
|
|
|
|
; RUN: llc -function-sections -mtriple=i686-w64-windows-gnu < %s | FileCheck %s --check-prefix=GNU32
|
2020-03-16 07:17:52 +08:00
|
|
|
; RUN: llc -function-sections -mtriple=x86_64-w64-windows-gnu < %s -filetype=obj | llvm-objdump - --headers | FileCheck %s --check-prefix=GNUOBJ
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
|
|
|
|
; GCC and MSVC handle comdats completely differently. Make sure we do the right
|
|
|
|
; thing for each.
|
|
|
|
|
2018-11-22 06:01:10 +08:00
|
|
|
; Modeled on this C++ source, with additional modifications for
|
|
|
|
; -ffunction-sections:
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
; int bar(int);
|
|
|
|
; __declspec(selectany) int gv = 42;
|
|
|
|
; inline int foo(int x) { return bar(x) + gv; }
|
|
|
|
; int main() { return foo(1); }
|
|
|
|
|
|
|
|
$_Z3fooi = comdat any
|
|
|
|
|
|
|
|
$gv = comdat any
|
|
|
|
|
|
|
|
@gv = weak_odr dso_local global i32 42, comdat, align 4
|
|
|
|
|
|
|
|
; Function Attrs: norecurse uwtable
|
|
|
|
define dso_local i32 @main() #0 {
|
|
|
|
entry:
|
|
|
|
%call = tail call i32 @_Z3fooi(i32 1)
|
|
|
|
ret i32 %call
|
|
|
|
}
|
|
|
|
|
2018-11-22 06:01:10 +08:00
|
|
|
; CHECK: .section .text,"xr",one_only,main
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
; CHECK: main:
|
2018-11-22 06:01:10 +08:00
|
|
|
; GNU: .section .text$main,"xr",one_only,main
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
; GNU: main:
|
2018-11-22 06:01:10 +08:00
|
|
|
; GNU32: .section .text$main,"xr",one_only,_main
|
|
|
|
; GNU32: _main:
|
|
|
|
|
|
|
|
define dso_local x86_fastcallcc i32 @fastcall(i32 %x, i32 %y) {
|
|
|
|
%rv = add i32 %x, %y
|
|
|
|
ret i32 %rv
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK: .section .text,"xr",one_only,fastcall
|
|
|
|
; CHECK: fastcall:
|
|
|
|
; GNU: .section .text$fastcall,"xr",one_only,fastcall
|
|
|
|
; GNU: fastcall:
|
|
|
|
; GNU32: .section .text$fastcall,"xr",one_only,@fastcall@8
|
|
|
|
; GNU32: @fastcall@8:
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
|
|
|
|
; Function Attrs: inlinehint uwtable
|
|
|
|
define linkonce_odr dso_local i32 @_Z3fooi(i32 %x) #1 comdat {
|
|
|
|
entry:
|
|
|
|
%call = tail call i32 @_Z3bari(i32 %x)
|
|
|
|
%0 = load i32, i32* @gv, align 4
|
|
|
|
%add = add nsw i32 %0, %call
|
|
|
|
ret i32 %add
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK: .section .text,"xr",discard,_Z3fooi
|
|
|
|
; CHECK: _Z3fooi:
|
|
|
|
; CHECK: .section .data,"dw",discard,gv
|
|
|
|
; CHECK: gv:
|
|
|
|
; CHECK: .long 42
|
|
|
|
|
|
|
|
; GNU: .section .text$_Z3fooi,"xr",discard,_Z3fooi
|
|
|
|
; GNU: _Z3fooi:
|
|
|
|
; GNU: .section .data$gv,"dw",discard,gv
|
|
|
|
; GNU: gv:
|
|
|
|
; GNU: .long 42
|
|
|
|
|
2018-11-22 06:01:10 +08:00
|
|
|
; GNU32: .section .text$_Z3fooi,"xr",discard,__Z3fooi
|
2018-06-22 07:06:33 +08:00
|
|
|
; GNU32: __Z3fooi:
|
2018-11-22 06:01:10 +08:00
|
|
|
; GNU32: .section .data$gv,"dw",discard,_gv
|
2018-06-22 07:06:33 +08:00
|
|
|
; GNU32: _gv:
|
|
|
|
; GNU32: .long 42
|
|
|
|
|
|
|
|
|
[CodeGen] Add text section prefix for COFF object file
Text section prefix is created in CodeGenPrepare, it's file format independent implementation, text section name is written into object file in TargetLoweringObjectFile, it's file format dependent implementation, port code of adding text section prefix to text section name from ELF to COFF.
Different with ELF that use '.' as concatenation character, COFF use '$' as concatenation character. That is, concatenation character is variable, so split concatenation character from text section prefix.
Text section prefix is existing feature of ELF, it can help to reduce icache and itlb misses, it's also make possible aggregate other compilers e.g. v8 created same prefix sections. Furthermore, the recent feature Machine Function Splitter (basic block level text prefix section) is based on text section prefix.
Reviewed By: pengfei, rnk
Differential Revision: https://reviews.llvm.org/D92073
2020-12-08 17:57:03 +08:00
|
|
|
define linkonce_odr dso_local i32 @_Z3fooj(i32 %x) !section_prefix !0 {
|
|
|
|
entry:
|
|
|
|
%call = tail call i32 @_Z3bari(i32 %x)
|
|
|
|
%0 = load i32, i32* @gv, align 4
|
|
|
|
%add = add nsw i32 %0, %call
|
|
|
|
ret i32 %add
|
|
|
|
}
|
|
|
|
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
; Make sure the assembler puts the .xdata and .pdata in sections with the right
|
|
|
|
; names.
|
|
|
|
; GNUOBJ: .text$_Z3fooi
|
[CodeGen] [WinException] Only produce handler data at the end of the function if needed
If we are going to write handler data (that is written as variable
length data following after the unwind info in .xdata), we need to
emit the handler data immediately, but for cases where no such
info is going to be written, skip emitting it right away. (Unwind
info for all remaining functions that hasn't gotten it emitted
directly is emitted at the end.)
This does slightly change the ordering of sections (triggering a
bunch of updates to DebugInfo/COFF tests), but the change should be
benign.
This also matches GCC's assembly output, which doesn't output
.seh_handlerdata unless it actually is needed.
For ARM64, the unwind info can be packed into the runtime function
entry itself (leaving no data in the .xdata section at all), but
that can only be done if there's no follow-on data in the .xdata
section. If emission of the unwind info is triggered via
EmitWinEHHandlerData (or the .seh_handlerdata directive), which
implicitly switches to the .xdata section, there's a chance of the
caller wanting to pass further data there, so the packed format
can't be used in that case.
Differential Revision: https://reviews.llvm.org/D87448
2020-09-10 18:33:00 +08:00
|
|
|
; GNUOBJ: .xdata$_Z3fooi
|
[CodeGen] Add text section prefix for COFF object file
Text section prefix is created in CodeGenPrepare, it's file format independent implementation, text section name is written into object file in TargetLoweringObjectFile, it's file format dependent implementation, port code of adding text section prefix to text section name from ELF to COFF.
Different with ELF that use '.' as concatenation character, COFF use '$' as concatenation character. That is, concatenation character is variable, so split concatenation character from text section prefix.
Text section prefix is existing feature of ELF, it can help to reduce icache and itlb misses, it's also make possible aggregate other compilers e.g. v8 created same prefix sections. Furthermore, the recent feature Machine Function Splitter (basic block level text prefix section) is based on text section prefix.
Reviewed By: pengfei, rnk
Differential Revision: https://reviews.llvm.org/D92073
2020-12-08 17:57:03 +08:00
|
|
|
; GNUOBJ: .text$unlikely$_Z3fooj
|
|
|
|
; GNUOBJ: .xdata$unlikely$_Z3fooj
|
Revert "[CodeGen] [WinException] Only produce handler data at the end of the function if needed"
This caused an explosion in ICF times during linking on Windows when libfuzzer
instrumentation is enabled. For a small binary we see ICF time go from ~0 to
~10 s. For a large binary it goes from ~1 s to forevert (I gave up after 30
minutes).
See comment on the code review.
> If we are going to write handler data (that is written as variable
> length data following after the unwind info in .xdata), we need to
> emit the handler data immediately, but for cases where no such
> info is going to be written, skip emitting it right away. (Unwind
> info for all remaining functions that hasn't gotten it emitted
> directly is emitted at the end.)
>
> This does slightly change the ordering of sections (triggering a
> bunch of updates to DebugInfo/COFF tests), but the change should be
> benign.
>
> This also matches GCC's assembly output, which doesn't output
> .seh_handlerdata unless it actually is needed.
>
> For ARM64, the unwind info can be packed into the runtime function
> entry itself (leaving no data in the .xdata section at all), but
> that can only be done if there's no follow-on data in the .xdata
> section. If emission of the unwind info is triggered via
> EmitWinEHHandlerData (or the .seh_handlerdata directive), which
> implicitly switches to the .xdata section, there's a chance of the
> caller wanting to pass further data there, so the packed format
> can't be used in that case.
>
> Differential Revision: https://reviews.llvm.org/D87448
This reverts commit 36c64af9d7f97414d48681b74352c9684077259b.
2020-11-03 20:01:55 +08:00
|
|
|
; GNUOBJ: .data$gv
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
; GNUOBJ: .pdata$_Z3fooi
|
[CodeGen] Add text section prefix for COFF object file
Text section prefix is created in CodeGenPrepare, it's file format independent implementation, text section name is written into object file in TargetLoweringObjectFile, it's file format dependent implementation, port code of adding text section prefix to text section name from ELF to COFF.
Different with ELF that use '.' as concatenation character, COFF use '$' as concatenation character. That is, concatenation character is variable, so split concatenation character from text section prefix.
Text section prefix is existing feature of ELF, it can help to reduce icache and itlb misses, it's also make possible aggregate other compilers e.g. v8 created same prefix sections. Furthermore, the recent feature Machine Function Splitter (basic block level text prefix section) is based on text section prefix.
Reviewed By: pengfei, rnk
Differential Revision: https://reviews.llvm.org/D92073
2020-12-08 17:57:03 +08:00
|
|
|
; GNUOBJ: .pdata$unlikely$_Z3fooj
|
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
2018-06-22 04:27:38 +08:00
|
|
|
|
|
|
|
declare dso_local i32 @_Z3bari(i32)
|
|
|
|
|
|
|
|
attributes #0 = { norecurse uwtable }
|
|
|
|
attributes #1 = { inlinehint uwtable }
|
[CodeGen] Add text section prefix for COFF object file
Text section prefix is created in CodeGenPrepare, it's file format independent implementation, text section name is written into object file in TargetLoweringObjectFile, it's file format dependent implementation, port code of adding text section prefix to text section name from ELF to COFF.
Different with ELF that use '.' as concatenation character, COFF use '$' as concatenation character. That is, concatenation character is variable, so split concatenation character from text section prefix.
Text section prefix is existing feature of ELF, it can help to reduce icache and itlb misses, it's also make possible aggregate other compilers e.g. v8 created same prefix sections. Furthermore, the recent feature Machine Function Splitter (basic block level text prefix section) is based on text section prefix.
Reviewed By: pengfei, rnk
Differential Revision: https://reviews.llvm.org/D92073
2020-12-08 17:57:03 +08:00
|
|
|
!0 = !{!"function_section_prefix", !"unlikely"}
|