[PATCH] D11724: COFF: Add test for ld/section created import library

Rui Ueyama ruiu at google.com
Wed Aug 5 14:51:00 PDT 2015


On Mon, Aug 3, 2015 at 10:36 PM, Martell Malone <martellmalone at gmail.com>
wrote:

> From my reading on how gnuld handles PE/COFF
> It uses a linker script that describes how it lays out its idata section.
> From i386pe.x
>
>   .idata BLOCK(__section_alignment__) :
>   {
>     /* This cannot currently be handled with grouped sections.
> 	See pe.em:sort_sections.  */
>     SORT(*)(.idata$2)
>     SORT(*)(.idata$3)
>     /* These zeroes mark the end of the import list.  */
>     LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
>     SORT(*)(.idata$4)
>     SORT(*)(.idata$5)
>     SORT(*)(.idata$6)
>     SORT(*)(.idata$7)
>   }
>
>
Yeah, I found that too and it (especially the way how it creates a gap
between .idata$3 and .idata$4) looks really hacky. I also found that GNU ld
has a special logic to order .idata$<n> sections.

At first I thought that I could mimic GNU ld and MSVC linker to generate
the .idata section, but seems like it would really mess up the DLL import
table generation code. We probably should keep the existing logic.

I then tried to detect dlltool-style import files and read them as if they
were short import libraries, so that I can keep the existing code. That
didn't work well because it's not easy to detect dlltool-style import files
in a reliable manner without sacrificing performance.

It feels to me that it makes more sense to add a new option to dlltool to
generate short import libraries. It shouldn't be that hard. Martell, what
do you think?

> Under ld/emultempl/pep.em in binutils it describes how it converts the MS import library to its format.
> see here http://github.com/bminor/binutils-gdb/blob/master/ld/emultempl/pep.em#L1625
> From the code in this function and the rest of pep.em we can see how it handles it.
> I'm sure this will make more sense to you however as you know what the MS format is.
>
> I assume the conversion will have to go the other way for us
> I think the most notable thing is the use of idata7 instead of idata6 for the dll name
> We could use that as a check?
> Then hijack it pulling out the function names once we see this being used and insert it into the sections like a MS generated one
>
> You might have a much cleaner solution however. :)
>
> If this isn't enough insight into what you need I can do more digging.
> Just ping me and let me know
>
>
> On Tue, Aug 4, 2015 at 3:15 AM, Rui Ueyama <ruiu at google.com> wrote:
>
>> ruiu added a comment.
>>
>> Do you know anything about how GNU ld handles these import libraries? My
>> linker is able to read it and construct .idata section, but the resulting
>> .idata section is not going to be in correct format. If GNU linker is able
>> to generate a correct .idata section from this type of import libraries,
>> there must be something I'm missing in my linker.
>>
>>
>> http://reviews.llvm.org/D11724
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150805/51f6dfdf/attachment.html>


More information about the llvm-commits mailing list