This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Fix bug in reading of cpusubtype field
ClosedPublic

Authored by oontvoo on Dec 7 2022, 12:55 PM.

Diff Detail

Event Timeline

oontvoo created this revision.Dec 7 2022, 12:55 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 7 2022, 12:55 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
oontvoo requested review of this revision.Dec 7 2022, 12:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2022, 12:55 PM
int3 added a comment.Dec 7 2022, 1:27 PM

Is there a test we could write here? How do the other bits in cpusubtype get set?

lld/MachO/InputFiles.cpp
234–241
thakis added a subscriber: thakis.Dec 8 2022, 5:31 AM
thakis added inline comments.
lld/MachO/InputFiles.cpp
234–241

also cpuType, cpuSubtype

oontvoo marked 2 inline comments as done.Dec 8 2022, 7:33 AM
oontvoo updated this revision to Diff 481272.Dec 8 2022, 7:33 AM

addressed review comments + added missing tests

Is there a test we could write here? How do the other bits in cpusubtype get set?

Added the test to fat-arch.s
(Without this, it'd throw an error when linking the %t.fat.bundle : ld64.lld: error: unable to find matching architecture in fat-arch.s.tmp.fat.exec.out )

lld/test/MachO/fat-arch.s
15

(removed because this doesn't work for arm and we don't really need it)

oontvoo updated this revision to Diff 481337.Dec 8 2022, 9:42 AM

rebase + fix typo

int3 accepted this revision.Dec 8 2022, 1:49 PM

Thanks!

lld/test/MachO/fat-arch.s
18
This revision is now accepted and ready to land.Dec 8 2022, 1:49 PM
int3 retitled this revision from [lld-macho] Fix bug in reading cpuSubType field. to [lld-macho] Fix bug in reading of cpusubtype field.Dec 8 2022, 2:14 PM
oontvoo updated this revision to Diff 481500.Dec 8 2022, 7:09 PM
oontvoo marked an inline comment as done.

addressed review comment + rebase

This revision was landed with ongoing or failed builds.Dec 8 2022, 7:10 PM
This revision was automatically updated to reflect the committed changes.
dyung added a subscriber: dyung.Dec 8 2022, 8:14 PM

@oontvoo the test you added is failing if the AArch64 target is not built: https://lab.llvm.org/buildbot/#/builders/139/builds/32439

dyung added a comment.Dec 8 2022, 10:45 PM

@oontvoo the test you added is failing if the AArch64 target is not built: https://lab.llvm.org/buildbot/#/builders/139/builds/32439

I've marked the test as requiring aarch64 to fix the bots in 9c381c430e41.

Thanks for the revert!

seems like we just have to skip tests on windows for now (llvm-mc error)

oontvoo reopened this revision.Dec 9 2022, 7:13 AM
This revision is now accepted and ready to land.Dec 9 2022, 7:13 AM
oontvoo updated this revision to Diff 481644.Dec 9 2022, 7:13 AM

updated tests and reland

This revision was automatically updated to reflect the committed changes.

reverted - will have a look later. Sorry for the breakage~!

Thanks for the fast revert! :)

Thanks for the fast revert! :)

@thakis What kind of Mac do you have? Is it arm64? Just curious since I can't seem to reproduce the crash on my machines ( Mac (x86) and Linux)
Thanks!

Thanks for the fast revert! :)

@thakis What kind of Mac do you have? Is it arm64? Just curious since I can't seem to reproduce the crash on my machines ( Mac (x86) and Linux)
Thanks!

P.S: oh, never mind - I think this test is bad because otool doesn't really guarantee which slice it picks when printing.

oontvoo reopened this revision.Dec 16 2022, 7:01 PM
This revision is now accepted and ready to land.Dec 16 2022, 7:01 PM
oontvoo updated this revision to Diff 483710.EditedDec 16 2022, 7:01 PM

reland 2nd attempt

New changes:

Fix tests to dump both slices in the fat-archive because otool
isn't deterministic about which slice it prints across different archs.
(It printed x86 on x86 machines but arm64 on arm64, this was why
the test failed on arm64)

Fingers crossed - 3rd time is 🍀

This revision was landed with ongoing or failed builds.Dec 16 2022, 7:04 PM
This revision was automatically updated to reflect the committed changes.

Thanks! Looking at the error more closely, it doesn't make a lot of sense. This bundle (%t.fat.bundle was created with -arch x86_64), and yet it ended up being an arm64 (ie., with CPU=16777228) ...
I suspect we have a bug somewhere that causes the target to be whatever host machine's arch rather than what was passed via -arch 🤔

oontvoo reopened this revision.Dec 17 2022, 8:35 PM
This revision is now accepted and ready to land.Dec 17 2022, 8:35 PM
oontvoo updated this revision to Diff 483799.Dec 17 2022, 8:35 PM

Reland #3: temporarily disabled checking cpu type after link due to suspected bug (described above).
(The current test that the link succeeded should be sufficient because
the link would have failed prior to this patch).

This revision was landed with ongoing or failed builds.Dec 17 2022, 8:36 PM
This revision was automatically updated to reflect the committed changes.