This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF, MinGW] Implement the GNU ld flag --kill-at
ClosedPublic

Authored by mstorsjo on Mar 9 2018, 1:44 AM.

Details

Summary

GNU ld has got a number of different flags for adjusting how to behave around stdcall functions. The --kill-at flag strips the trailing sdcall suffix from exported functions (which otherwise is included by default in MinGW setups).

This also strips it from the corresponding import library though. That makes it hard to link to such an import library from code that calls the functions - but this matches what GNU ld does with this flag. Therefore, this flag is probably not sensibly used together with import libraries, but probably mostly when creating some sort of plugin, or if creating the import library separately with dlltool.

Reviewing both the COFF and MinGW parts of the patch at once, I can commit them separately if the change itself is fine.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Mar 9 2018, 1:44 AM
rnk accepted this revision.Mar 14 2018, 9:38 AM

lgtm

I'm curious, what is the use case for this feature? The binutils docs describe exactly what it does but not why one would want to use it.

test/COFF/def-export-stdcall.s
75 ↗(On Diff #137705)

We might as well test vectorcall for completeness.

This revision is now accepted and ready to land.Mar 14 2018, 9:38 AM
ruiu accepted this revision.Mar 14 2018, 10:36 AM

LGTM

COFF/DriverUtils.cpp
586 ↗(On Diff #137705)

Please also say that this is MinGW-specific.

592 ↗(On Diff #137705)

You can flip the condition to return early.

In D44292#1037301, @rnk wrote:

lgtm

I'm curious, what is the use case for this feature? The binutils docs describe exactly what it does but not why one would want to use it.

In mingw tools, there's much less of the automatic stdcall mangling/matching that makes it sane in link.exe. If you do void __declspec(dllexport) __stdcall PluginEntry(...) { in mingw, the object file export directive will be -export:PluginEntry@X, and you'll end up exporting it with the literal @X suffix in the dll - which --kill-at fixes.

COFF/DriverUtils.cpp
586 ↗(On Diff #137705)

Ok, will do.

592 ↗(On Diff #137705)

Oh, indeed. (I had an else clause here at some point, but it turned out to be unnecessary.)

test/COFF/def-export-stdcall.s
75 ↗(On Diff #137705)

GCC doesn't support vectorcall, so there's no reference on how it should behave with that.

rnk added inline comments.Mar 14 2018, 12:21 PM
test/COFF/def-export-stdcall.s
75 ↗(On Diff #137705)

Sure, but the code you wrote seems like it will apply to vectorcall, so we have some emergent behavior in this corner case and we should validate that it stays the same over time.

mstorsjo added inline comments.Mar 14 2018, 1:18 PM
test/COFF/def-export-stdcall.s
75 ↗(On Diff #137705)

Sure, will add.

This revision was automatically updated to reflect the committed changes.