This is an archive of the discontinued LLVM Phabricator instance.

[tools][llvm-objcopy] Enable --discard-all for MachO
ClosedPublic

Authored by alexander-shaposhnikov on Feb 25 2020, 12:21 AM.

Details

Summary

In this diff we enable the option --discard-all for MachO.

Test plan: make check-all

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: abrachet. · View Herald Transcript
MaskRay added inline comments.Feb 25 2020, 8:59 AM
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
72

Is this binutils's behavior? I cannot find a reference to N_EXT.

alexander-shaposhnikov marked an inline comment as done.Feb 25 2020, 10:47 AM
alexander-shaposhnikov added inline comments.
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
72

I was looking at how other tools in LLVM check if a macho symbol is global
https://llvm.org/doxygen/MachOObjectFile_8cpp_source.html#l01854
+ checked that on a simple examples cctools's strip -x does the same as llvm-strip.

MaskRay added inline comments.Feb 25 2020, 10:41 PM
llvm/test/tools/llvm-objcopy/MachO/discard-all.test
5

## for comments.

llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
72

I think it is slightly better to use

if (Config.DiscardMode == DiscardType::All && !(N->n_type & MachO::N_EXT))
  return true;

Can you check if objcopy --discard-locals works?

If there are other checks in the future, we won't have to update return !static_cast<bool>(N->n_type & MachO::N_EXT);

179–180

Since --discard-locals has not been implemented, --discard-locals should still be rejected.

alexander-shaposhnikov marked an inline comment as done.Feb 25 2020, 11:23 PM
alexander-shaposhnikov added inline comments.
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
72

yes, there is an equivalent (e.g. in cctools strip) for the option -X, -X is an alias to --discard-locals,
it's also documented here https://www.unix.com/man-page/osx/1/strip/, that option is not implemented in llvm-objcopy for MachO yet, but it's not hard to add (in a separate diff).

Looks good from my point of view, but I don't know enough about the Mach-O to verify the behaviour of the option.

llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
178–179

Nit: clang-format.

MaskRay accepted this revision.Feb 26 2020, 8:38 AM

Looks good from my point of view. I also don't know enough about Mach-O, though...

This revision is now accepted and ready to land.Feb 26 2020, 8:38 AM
smeenai accepted this revision.Feb 26 2020, 12:57 PM

LGTM from the Mach-O perspective.

llvm/test/tools/llvm-objcopy/MachO/discard-all.test
11

This is verifying that it produces identical output for two different runs, right? Not that it didn't modify the input?

This revision was automatically updated to reflect the committed changes.
alexander-shaposhnikov marked an inline comment as done.Feb 26 2020, 2:41 PM
alexander-shaposhnikov added inline comments.
llvm/test/tools/llvm-objcopy/MachO/discard-all.test
11

yup