COFF: Change symbol resolution order for entry and /include.
authorRui Ueyama <ruiu@google.com>
Fri, 26 Jun 2015 03:44:00 +0000 (03:44 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 26 Jun 2015 03:44:00 +0000 (03:44 +0000)
commit32f8e1cb4e1975f4bba05af655df79af00665f8d
tree1f3b658dd485843ab37ee8329d40862cc020666d
parentccde19d77ec8e990bedeea2a7190beb3f42cce06
COFF: Change symbol resolution order for entry and /include.

We were resolving entry symbols and /include'd symbols after all other
symbols are resolved. But looks like it's too late. I found that it
causes some program to fail to link.

Let's say we have an object file A which defines symbols X and Y in an
archive. We also have another file B after A which defines X, Y and
_DLLMainCRTStartup in another archive. They conflict each other, so
either A or B can be linked.

If we have _DLLMainCRTStartup as an undefined symbol, file B is always
chosen. If not, there's a chance that A is chosen. If the linker
find it needs _DllMainCRTStartup after that, it's too late.

This patch adds undefined symbols to the symbol table as soon as
possible to fix the issue.

llvm-svn: 240757
lld/COFF/Config.h
lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/SymbolTable.cpp
lld/test/COFF/include2.test
lld/test/COFF/order.test