[PATCH][lld][PECOFF] Add Support for entry point symbol name
Rui Ueyama
ruiu at google.com
Tue Jul 30 16:19:25 PDT 2013
Besides Chandler's comment, here's mine.
> diff --git lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
> index 34dc1fb..fb5c3a3 100644
> --- lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
> +++ lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
> @@ -351,6 +355,15 @@ public:
> layout->_virtualAddr += rva;
> }
>
> + uint64_t getAtomVirtualAddress(StringRef name) {
> + for (auto atomLayout : _atomLayouts) {
> + if (atomLayout->_atom->name() == name) {
> + return atomLayout->_virtualAddr;
> + }
> + }
> + return 0;
> + }
> +
Nit: you can omit {} for "for" and "if" in this case.
> @@ -747,6 +760,20 @@ public:
> peHeader->setSizeOfInitializedData(rdata->size() + data->size());
> peHeader->setNumberOfSections(_numSections);
> peHeader->setSizeOfImage(_imageSizeInMemory);
> +
> + // Find the virtual address of the entry point symbol if any.
> + // PECOFF spec says that entry point for dll images is optional, in
which
> + // case must be set to 0.
> + if (_PECOFFTargetInfo.entrySymbolName().empty() &&
> + _PECOFFTargetInfo.getImageType() == PECOFFTargetInfo::IMAGE_DLL)
{
> + peHeader->setAddressOfEntryPoint(0);
> + } else {
> + uint64_t entryPointAddress = text->getAtomVirtualAddress(
> + _PECOFFTargetInfo.entrySymbolName());
> + if (entryPointAddress != 0) {
> + peHeader->setAddressOfEntryPoint(entryPointAddress);
> + }
> + }
> }
I'd make this a separate function to keep build() as concise as possible.
On Tue, Jul 30, 2013 at 4:12 PM, Chandler Carruth <chandlerc at google.com>wrote:
>
> On Tue, Jul 30, 2013 at 3:46 PM, Jesús Serrano García <
> dagonoweda at gmail.com> wrote:
>
>> Looks like the entry function name should be _mainCRTStartup if
>> subsystem is "console",
>> _WinMainCRTStartup if subsystem is "windows", and "__DllMainCRTStartup"
>> for DLL.
>> See http://msdn.microsoft.com/en-us/library/f9t8842e(v=vs.80).aspx.
>>
>> I think this is rather a Visual Studio convention for its C runtime
>> library, and the PECOFF spec says nothing about it, so I though that
>> "_main" is a good default entry point name, taking into account that
>> there is currently no CRT guidelines (or at least I'm unaware of them) in
>> the lld project.
>
>
> Sorry for the ambiguity, but the goal of all the PECOFF work in LLD is to
> support linking in a compatible way for Windows. If you have another
> usecase for linking PECOFF, you should raise that on the discussion list
> (not the commit list) as it'll need a separate design from what we're
> currently working on.
>
> For now, as Rui has said, we should follow the MSDN spec he cited.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130730/a619e8f0/attachment.html>
More information about the llvm-commits
mailing list