This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Check for arch compatibility when loading ObjFiles and TBDs
ClosedPublic

Authored by int3 on Feb 22 2021, 11:13 AM.

Details

Summary

The silent failures had confused me a few times.

I haven't added a similar check for platform yet as we don't yet have logic to
infer the platform automatically, and so adding that check would require
updating dozens of test files.

Diff Detail

Event Timeline

int3 created this revision.Feb 22 2021, 11:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2021, 11:13 AM
int3 requested review of this revision.Feb 22 2021, 11:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2021, 11:13 AM
int3 planned changes to this revision.Feb 22 2021, 11:43 AM
int3 updated this revision to Diff 325569.Feb 22 2021, 2:25 PM

update test

thakis accepted this revision.Feb 23 2021, 7:00 AM
thakis added a subscriber: thakis.

ELF and COFF do this a bit earlier, COFF in SymbolTable::addFile() which has the nicer diag I suggest below -- but otherwise I don't like the COFF approach much, since it parses the whole InputFile, which adds its symbols, and only after that it checks the arch. Checking the arch first and returning early if it doens't match, like this does, seems better. ELF does it in doParseFile(), with a similar timing to this patch. Maybe we could make it look a bit more like the ELF port, to keep the different lld ports consistent in parts where they don't need to be different?

lld/MachO/InputFiles.cpp
487

should the diag mention the arch of the source file too? "file has architecture x86 which is incompatible with output architecture x64" or similar?

This revision is now accepted and ready to land.Feb 23 2021, 7:00 AM
int3 added a comment.Feb 23 2021, 10:59 AM

Maybe we could make it look a bit more like the ELF port, to keep the different lld ports consistent in parts where they don't need to be different?

Yup, that's the plan :) I'll tackle that when I add support for arch inference: https://bugs.llvm.org/show_bug.cgi?id=49277

int3 updated this revision to Diff 325956.Feb 23 2021, 6:37 PM

print file arch in error message

This revision was landed with ongoing or failed builds.Feb 23 2021, 7:02 PM
This revision was automatically updated to reflect the committed changes.

Hi. (in case you didn't know already) This is failing on one of our bots:
http://lab.llvm.org:8011/#/builders/53/builds/1386

This bot only enables ARM and AArch64 targets so I think you need a "REQUIRES" line for the new tests, like lld/test/MachO/header.s has.

int3 added a comment.Feb 24 2021, 6:43 AM

Thanks for the heads up, just pushed rG9ced8b3b614c.