COFF: Infer entry point as early as possible, but not too early.
On Windows, we have four different main functions, {w,}{main,WinMain}.
The linker has to choose a corresponding entry point function among
{w,}{main,WinMain}CRTStartup. These entry point functions are defined
in the standard library. The linker resolves one of them by looking at
which main function is defined and adding a corresponding undefined
symbol to the symbol table.
Object files containing entry point functions conflicts each other.
For example, we cannot resolve both mainCRTStartup and WinMainCRTStartup
because other symbols defined in the files conflict.
Previously, we inferred CRT function name at the very end of name
resolution. I found that that is sometimes too late. If the linker
already linked one of these four archive member objects, it's too late
to change the decision.
The right thing to do here is to infer entry point name after adding
all symbols from command line files and before adding any other files
(which are specified by directive sections). This patch does that.
llvm-svn: 241236
2015-07-02 11:15:15 +08:00
|
|
|
# RUN: yaml2obj < %s > %t.obj
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: not lld-link /out:%t.exe %t.obj /verbose > %t.log 2>&1
|
COFF: Infer entry point as early as possible, but not too early.
On Windows, we have four different main functions, {w,}{main,WinMain}.
The linker has to choose a corresponding entry point function among
{w,}{main,WinMain}CRTStartup. These entry point functions are defined
in the standard library. The linker resolves one of them by looking at
which main function is defined and adding a corresponding undefined
symbol to the symbol table.
Object files containing entry point functions conflicts each other.
For example, we cannot resolve both mainCRTStartup and WinMainCRTStartup
because other symbols defined in the files conflict.
Previously, we inferred CRT function name at the very end of name
resolution. I found that that is sometimes too late. If the linker
already linked one of these four archive member objects, it's too late
to change the decision.
The right thing to do here is to infer entry point name after adding
all symbols from command line files and before adding any other files
(which are specified by directive sections). This patch does that.
llvm-svn: 241236
2015-07-02 11:15:15 +08:00
|
|
|
# RUN: FileCheck %s < %t.log
|
|
|
|
|
|
|
|
# CHECK: Entry name inferred: WinMainCRTStartup
|
|
|
|
|
|
|
|
---
|
|
|
|
header:
|
|
|
|
Machine: IMAGE_FILE_MACHINE_AMD64
|
|
|
|
Characteristics: []
|
|
|
|
sections:
|
|
|
|
- Name: .text
|
|
|
|
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
|
|
|
|
Alignment: 4
|
|
|
|
SectionData: B82A000000C3
|
|
|
|
- Name: .drectve
|
|
|
|
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
|
2016-03-18 00:56:31 +08:00
|
|
|
Alignment: 1
|
COFF: Infer entry point as early as possible, but not too early.
On Windows, we have four different main functions, {w,}{main,WinMain}.
The linker has to choose a corresponding entry point function among
{w,}{main,WinMain}CRTStartup. These entry point functions are defined
in the standard library. The linker resolves one of them by looking at
which main function is defined and adding a corresponding undefined
symbol to the symbol table.
Object files containing entry point functions conflicts each other.
For example, we cannot resolve both mainCRTStartup and WinMainCRTStartup
because other symbols defined in the files conflict.
Previously, we inferred CRT function name at the very end of name
resolution. I found that that is sometimes too late. If the linker
already linked one of these four archive member objects, it's too late
to change the decision.
The right thing to do here is to infer entry point name after adding
all symbols from command line files and before adding any other files
(which are specified by directive sections). This patch does that.
llvm-svn: 241236
2015-07-02 11:15:15 +08:00
|
|
|
SectionData: 2f616c7465726e6174656e616d653a6d61696e3d57696e4d61696e00 # /alternatename:main=WinMain
|
|
|
|
symbols:
|
|
|
|
- Name: .text
|
|
|
|
Value: 0
|
|
|
|
SectionNumber: 1
|
|
|
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
|
|
|
ComplexType: IMAGE_SYM_DTYPE_NULL
|
|
|
|
StorageClass: IMAGE_SYM_CLASS_STATIC
|
|
|
|
SectionDefinition:
|
|
|
|
Length: 6
|
|
|
|
NumberOfRelocations: 0
|
|
|
|
NumberOfLinenumbers: 0
|
|
|
|
CheckSum: 0
|
|
|
|
Number: 0
|
|
|
|
- Name: WinMain
|
|
|
|
Value: 0
|
|
|
|
SectionNumber: 1
|
|
|
|
SimpleType: IMAGE_SYM_TYPE_NULL
|
|
|
|
ComplexType: IMAGE_SYM_DTYPE_NULL
|
|
|
|
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
|
|
|
...
|