This is an archive of the discontinued LLVM Phabricator instance.

[llvm-lib] Add support for ARM64EC libraries.

Authored by jacek on Feb 7 2023, 5:00 PM.



ARM64EC allows having both pure ARM64 objects and ARM64EC in the same archive. This allows using single static library for linking pure ARM64, pure ARM64EC or mixed modules (what MS calls ARM64X: a single module that may be used in both modes). To achieve that, such static libraries need two separated symbol maps. The usual map contains only pure ARM64 symbols, while a new /<ECSYMBOLS>/ section contains EC symbols. EC symbols map has very similar format to the usual map, except it doesn't contain object offsets and uses offsets from regular map instead. This is true even for pure ARM64EC static library: it will simply have 0 symbols in the symbol map.

Diff Detail

Event Timeline

jacek created this revision.Feb 7 2023, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 5:00 PM
jacek requested review of this revision.Feb 7 2023, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 5:00 PM

I'll try to find time to review in more detail soon... unless someone else wants to review. (I'm not really that familiar with this code, but I doubt anyone has looked at it in years anyway.) Leaving a couple quick comments from my first glance.

If you're going to number your patches, please use some sort of consistent numbering... but you don't need to number a "series" like this. Just stacking them in Phabricator is enough. Maybe change the refactoring patches to explicitly put [NFC] in the title.




Do we need to mess with this inference code to make mixed archives work correctly?

jacek updated this revision to Diff 495948.Feb 8 2023, 2:21 PM
jacek retitled this revision from [llvm-lib 5/5] Add support for ARM64EC libraries. to [llvm-lib] Add support for ARM64EC libraries..

Thanks! The new version implements better logic for inferred machine type. I'm not sure if there are any recommendations about compatibility: I checked with lib.exe and it simply always requires explicit machine type for ARM64EC. If I try to create pure ARM64EC library with no -machine: argument, it just fails. I guess it's fine to do better than that, but I may follow that if preferred.

jacek updated this revision to Diff 506995.Mar 21 2023, 8:38 AM
jacek marked an inline comment as done.

The new version also allows including x86_64 object files in ARM64EC libraries. I originally avoided expressing target in writeArchive call, but it now doesn't have enough info to decide what kind of symbol map to produce (if only x86_64 binaries are passed, it can't deduce if it's meant to be x86_64 or ARM64EC library).

I also added a few more tests and I will add another patch to llvm-nm for printing EC symbol map, which allows for better tests.

jacek updated this revision to Diff 507404.Mar 22 2023, 9:51 AM

I reconsidered support for inferring ARM64EC target from object files and followed MSVC lib, which requires an explicit -machine argument. This makes the patch a bit smaller. Allowing inferring machine type makes type checks much weaker and could potentially unintentionally allow users to mix x86_64 and aarch64 objects. I don't have strong opinion on this, I will restore that code if it's preferred. I also rebased the patch.

jacek added a comment.Apr 17 2023, 5:54 AM

llvm-lib will need a bit more changes for ARM64X support, they are part of D148517.

This revision is now accepted and ready to land.Apr 18 2023, 10:28 AM
This revision was landed with ongoing or failed builds.Apr 21 2023, 5:46 AM
This revision was automatically updated to reflect the committed changes.

Hello and good afternoon from the UK,

I believe this is 1 of 3 patches that may have caused the following build bot to begin failing, are you able to take a look?

Warm regards,
Tom W

jacek added a comment.Apr 21 2023, 7:13 AM

Yes, sorry about that. I created with missing REQUIRES statements.