This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Check platform and version while constructing ObjFile and DylibFile
ClosedPublic

Authored by oontvoo on Mar 4 2021, 1:59 PM.

Details

Diff Detail

Event Timeline

oontvoo created this revision.Mar 4 2021, 1:59 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
oontvoo requested review of this revision.Mar 4 2021, 1:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2021, 1:59 PM
oontvoo retitled this revision from [lld-macho] Check platform and version when constructor ObjFile to [lld-macho] Check platform and version in constructor ObjFile.Mar 4 2021, 2:15 PM
int3 added a comment.Mar 4 2021, 2:27 PM

Neat. Could you clean up the clang-tidy issues? Kind of hard to review the code with all that in the way.

Also, I think the method is getting large enough, it would be nice to factor out the arch/platform check into a separate method.

Finally, don't forget about the test :)

oontvoo updated this revision to Diff 328383.Mar 4 2021, 9:41 PM

Updated diff:

  • made clang-tidy happy
  • added test
oontvoo updated this revision to Diff 328387.Mar 4 2021, 9:49 PM

more test

int3 added inline comments.Mar 5 2021, 9:29 AM
lld/MachO/InputFiles.cpp
351

ultra nit: given that you're casting cmd->platform to a PlatformKind below, why not do it here too for uniformity?

364–368

how about constructing another VersionTuple instance and compare that against platformInfo.minimum?

that way you can also use VersionTuple::getAsString() below

513

no need to repeat the type name on the same line

677

seems kind of janky to pass in a function here just so we can prepend "dylib". I think it's clear enough that it's a dylib from the name (and if it's not, we should update toString so that all our error messages are uniform). Basically I think it would be cleaner to just pass in the InputFile *

lld/MachO/InputFiles.h
179

nice, I like the convenient casting. But I don't think there's a need to move this function into the header

int3 added inline comments.Mar 5 2021, 9:35 AM
lld/test/MachO/incompat-version.s
1 ↗(On Diff #328387)

Can we merge this test into invalid/incompatible-arch.s? (and rename the file to incompatible-target or something). That test file is pretty small as-is and this test is covering very similar functionality.

(In general we put tests that only check for error handling into invalid/.)

oontvoo updated this revision to Diff 328600.Mar 5 2021, 11:35 AM
oontvoo marked 6 inline comments as done.

updated diff:

  • moved test into existing incompatible-arch.s
  • added additional test case to cover the ObjFile path
  • fixed other styling issues
lld/MachO/InputFiles.h
179

It's a templated function, so you can't put it in the cpp file.

If we put it in the cpp file, then it can only be a static local function.

oontvoo retitled this revision from [lld-macho] Check platform and version in constructor ObjFile to [lld-macho] Check platform and version while constructing ObjFile and DylibFile.Mar 5 2021, 11:38 AM
int3 added inline comments.Mar 5 2021, 12:15 PM
lld/MachO/InputFiles.h
179

Oh, I didn't realize this was being used in ObjC.cpp

lld/test/MachO/invalid/incompatible-arch.s
11–12

doesn't seem like the -o %t/new.dylib is necessary given that we have -o /dev/null later

16

nit: use hyphens for uniformity with things like CHECK-NEXT

19–22

I'm guessing you created a bitcode file in order to specify the platform? You can actually specify it by compiling a regular assembly file via llvm-mc:

llvm-mc -filetype=obj -triple=x86_64-apple-macos14.0

oontvoo updated this revision to Diff 328637.Mar 5 2021, 1:42 PM
oontvoo marked 3 inline comments as done.

Updated test to specify the platform version with llvm-mc rather than going through the trouble of using a bitcode file

lld/test/MachO/invalid/incompatible-arch.s
19–22

Good to know!

int3 accepted this revision.Mar 5 2021, 1:54 PM

lgtm!

lld/test/MachO/invalid/incompatible-arch.s
0–6
This revision is now accepted and ready to land.Mar 5 2021, 1:54 PM
oontvoo updated this revision to Diff 328651.Mar 5 2021, 2:34 PM
oontvoo marked an inline comment as done.

updated diff

This revision was landed with ongoing or failed builds.Mar 5 2021, 2:35 PM
This revision was automatically updated to reflect the committed changes.
Harbormaster completed remote builds in B92221: Diff 328383.
int3 added inline comments.Mar 5 2021, 7:19 PM
lld/MachO/InputFiles.cpp
345

oh I just noticed that you passed in the Configuration as a parameter. It's not necessary since config is a global singleton

oontvoo marked an inline comment as done.Mar 6 2021, 8:32 AM
oontvoo added inline comments.
lld/MachO/InputFiles.cpp
345

it was kind of intentional since I didn't like using a global variable in this context .
But now it seemed a lot of other places did that too. Sent a NFC to fix it at https://reviews.llvm.org/D98115