This is an archive of the discontinued LLVM Phabricator instance.

Make ObjectFileMachO work on non-darwin platforms
ClosedPublic

Authored by labath on May 16 2018, 3:00 AM.

Details

Summary

Before this patch we were unable to write cross-platform MachO tests
because the parsing code did not compile on other platforms. The reason
for that was that ObjectFileMachO depended on
RegisterContextDarwin_arm(64)? (presumably for core file parsing) and
the two Register Context classes uses constants from the system headers
(KERN_SUCCESS, KERN_INVALID_ARGUMENT).

As far as I can tell, these two files don't actually interact with the
darwin kernel -- they are used only in ObjectFileMachO and MacOSX-Kernel
process plugin (even though it has "kernel" in the name, this one
communicates with it via network packets and not syscalls). So there is
no good reason to use os-specific error codes here. In fact, the
RegisterContextDarwin_i386/x86_64 classes and the code which uses them
already use 0/-1 constants for these purposes, so changing the arm
context to do the same makes the code more consistent.

This is the only change necessary (apart from build system glue) to make
ObjectFileMachO work on other platforms. To demonstrate that, I remove
REQUIRES:darwin from our (only) cross-platform mach-o test.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.May 16 2018, 3:00 AM
aprantl added inline comments.May 16 2018, 8:53 AM
source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
1037 ↗(On Diff #147029)

Could we keep this as a local constant?
perhaps with an #ifndef KERN_INVALID_ARGUMENT clause?

labath added inline comments.May 16 2018, 9:02 AM
source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
1037 ↗(On Diff #147029)

We could. I didn't do that originally, as RegisterContextDarwin_x86_64::WriteGPR() looks exactly like this function, and it uses -1 already, but that works for me as well.

clayborg accepted this revision.May 16 2018, 10:58 AM
This revision is now accepted and ready to land.May 16 2018, 10:58 AM
jasonmolenda accepted this revision.May 16 2018, 12:25 PM

Thanks for untangling this Pavel, I hadn't noticed we weren't building this plugin for non-darwin systems. I'd agree with Adrian's comment that we should have a constants like LLDB_KERNEL_SUCCESS / LLDB_KERNEL_INVALID_ARGUMENT, I think the place where -1 was being returned currently would be considered incorrect (it's probably my fault for all I know ;)

Does that mean we can now also remove the #ifdef APPLE from the objectfile unit tests?

Does that mean we can now also remove the #ifdef APPLE from the objectfile unit tests?

Which ones do you mean? I wasn't aware we had any. The thing I know of, which would be interesting to enable is the MachO core file tests. This can't be done yet because the respective process plugin is apple-only, but I haven't looked at what it would take to enable it everywhere.

labath updated this revision to Diff 147286.May 17 2018, 4:13 AM

This is the version with new symbolic constants. I put them in a new file, as I
couldn't think of a better place for them.

I didn't want to put them in a too generic place as I don't think we should
encourage their use (we should convert error to one of our standard errors types
as soon as possible). On the other hand, they are used in two files, so they
can't be internal to a compilation unit. There wasn't anything reasonable in the
overlap of the existing includes of the two files, so I created a new file
instead.

aprantl added inline comments.May 17 2018, 9:08 AM
source/Plugins/Process/Utility/RegisterContextDarwinConstants.h
18 ↗(On Diff #147286)

I think I would prefer

#ifndef KERN_INVALID_ARGUMENT
#define KERN_INVALID_ARGUMENT 4
#endif

over renaming the constant. I think that that is less confusing to read and we use that pattern in other places in LLDB, too.

Does that mean we can now also remove the #ifdef APPLE from the objectfile unit tests?

Which ones do you mean? I wasn't aware we had any. The thing I know of, which would be interesting to enable is the MachO core file tests. This can't be done yet because the respective process plugin is apple-only, but I haven't looked at what it would take to enable it everywhere.

Sorry, I was confused. I was thinking about the HostInfoMacOSX class unit test which I added at the same time and somehow the two got conflated in my memory.

labath updated this revision to Diff 147341.May 17 2018, 10:00 AM
  • Use #ifndef approach for handling the constants.
clayborg accepted this revision.May 17 2018, 10:05 AM
This revision was automatically updated to reflect the committed changes.