This is an archive of the discontinued LLVM Phabricator instance.

[LLD][COFF] Set OrdinalBase to 1 for export table
ClosedPublic

Authored by alvinhochun on Sep 18 2022, 11:09 AM.

Details

Summary

Before this, LLD sets OrdinalBase to 0, which deviates from usual
practices. This technically would allow LLD to export a symbol using
ordinal 0, however LLD never use export ordinal 0, which results in
binaries with export tables always having an empty export at ordinal 0.

This change makes LLD set OrdinalBase to 1 and not create the empty
export with ordinal 0, which makes its behaviour more in line with both
the MSVC linker and the GNU linker.

Diff Detail

Event Timeline

alvinhochun created this revision.Sep 18 2022, 11:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2022, 11:09 AM
alvinhochun requested review of this revision.Sep 18 2022, 11:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2022, 11:09 AM

Looks great to me, thanks! I've wondered about this difference to other tools (although I haven't used link.exe that much that I'd have noticed the difference there too), but never enough to dig into it.

I didn't review how the other tools does it - I trust your judgement that link.exe also does it like this, where I trust link.exe much more as reference than ld.bfd.

Leaving open if @rnk wants to have a look too, otherwise I'd be happy to approve this in a couple days.

lld/test/COFF/export-all.s
11

Shouldn't this just be changed into a plain # CHECK: Name: comdatFunc?

alvinhochun added inline comments.Sep 19 2022, 5:38 AM
lld/test/COFF/export-all.s
11

I thought we can use this CHECK and CHECK-SAME combo to make sure that the first symbol will be the expected comdatFunc instead of an empty entry. Though other tests has already covered this case, so your suggestion is fine too. Feel free to change it when committing, thanks.

mstorsjo added inline comments.Sep 19 2022, 6:34 AM
lld/test/COFF/export-all.s
11

Oh, right, that's a neat way of enforcing that - although AFAIK an uncommon idiom for writing tests. No strong opinion on it anyway.

mstorsjo accepted this revision.Oct 2 2022, 12:19 AM

Leaving open if @rnk wants to have a look too, otherwise I'd be happy to approve this in a couple days.

It seems I forgot about this one; approving now, will apply later.

This revision is now accepted and ready to land.Oct 2 2022, 12:19 AM
This revision was automatically updated to reflect the committed changes.