This is an archive of the discontinued LLVM Phabricator instance.

COFF: Add test for ld/section created import library
AbandonedPublic

Authored by martell on Aug 3 2015, 8:47 AM.

Details

Reviewers
ruiu
Summary

This is a simple test to use an ld created import library with the lld COFF linker

As discussed here

http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-July/088556.html

Diff Detail

Event Timeline

martell updated this revision to Diff 31238.Aug 3 2015, 8:47 AM
martell retitled this revision from to COFF: Add test for ld/section created import library.
martell updated this object.
martell added a reviewer: ruiu.
martell added subscribers: lld, llvm-commits.

Hi rui,

I noticed that x86 support seems to be complete so as promised I would create a test case for when using ld libraries.
The final offset in the code for the test may have to be changed.
We won't know the exact values until support has been added I suppose :)

Kind Regards
Martell

ruiu edited edge metadata.Aug 3 2015, 10:27 AM
ruiu added a subscriber: ruiu.

Martell,

Thank you for the test cases. I'll try to support that.

ruiu added a comment.Aug 3 2015, 7:15 PM

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.

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)
}

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

martell abandoned this revision.Aug 13 2015, 8:24 PM