COFF: Handle mangled entry symbol name.

Compilers recognize "main" function and don't mangle its name.
But if you use a different function as a user-defined entry name,
and if you didn't define that function with extern C, your entry
point function name is mangled. And the linker has to be able to
find that. This is relatively rare but can happen.

llvm-svn: 240953
This commit is contained in:
Rui Ueyama 2015-06-29 14:43:07 +00:00
parent 3cdc37c5bc
commit 2d5e917bce
2 changed files with 43 additions and 0 deletions

View File

@ -580,6 +580,16 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
break;
}
// Windows specific -- if entry point is not found,
// search for its mangled names.
if (!Config->EntryName.empty() && !Symtab.find(Config->EntryName)) {
StringRef Name;
Symbol *Sym;
std::tie(Name, Sym) = Symtab.findMangled(Config->EntryName);
if (Sym)
Symtab.rename(Config->EntryName, Name);
}
// Windows specific -- resolve dllexported symbols.
for (Export &E : Config->Exports) {
StringRef Name;

View File

@ -0,0 +1,33 @@
# RUN: yaml2obj < %s > %t.obj
# RUN: lld -flavor link2 /out:%t.exe /entry:main %t.obj
---
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: 000000000000
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
Selection: IMAGE_COMDAT_SELECT_ANY
- Name: '?main@@YAHXZ'
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_FUNCTION
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
...