This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][MachO] Implement -Ibinary
Needs ReviewPublic

Authored by seiya on Aug 19 2019, 1:53 AM.

Details

Summary

This patch implements -Ibinary for MachO (64bit only for now).

Event Timeline

seiya created this revision.Aug 19 2019, 1:53 AM
seiya planned changes to this revision.Aug 19 2019, 3:01 AM

I'll add another patch to isolate changes to CopyConfig.

seiya updated this revision to Diff 215991.Aug 19 2019, 2:46 PM
  • No such file or directory -> {{[Nn]}}o such file or directory
seiya updated this revision to Diff 216006.Aug 19 2019, 3:24 PM

Moved changes to CopyConfig to D66449.

seiya updated this revision to Diff 216007.Aug 19 2019, 3:27 PM

Added a newline at the end of file.

Harbormaster completed remote builds in B36988: Diff 216007.
jhenderson added inline comments.Aug 20 2019, 2:19 AM
llvm/test/tools/llvm-objcopy/MachO/binary-input.test
1

If I'm not mistaken, it should be Mach-O here rather than MachO.

2

contains the input...

llvm/tools/llvm-objcopy/MachO/MachOReader.h
9

You shouldn't need the relative path. You should just be able to do "CopyConfig.h". If that doesn't work, then there's something wrong with the include directories, I think. This might point to a bigger flaw in llvm-objcopy's include paths.

seiya updated this revision to Diff 216122.Aug 20 2019, 6:08 AM

Update CommandGuide.

seiya updated this revision to Diff 216125.Aug 20 2019, 6:19 AM
seiya marked 3 inline comments as done.

Addressed review comments.

Okay, no more comments from me. Somebody with more Mach-O experience should look at the rest.

I'll take a closer look at this diff this week, sorry about the delay

LGTM

llvm/test/tools/llvm-objcopy/MachO/binary-input.test
2

llvm-objcopy

5

Per the other patch, these should use -B i386:x86-64 as the main supported config

41

I believe you should be able to check for .input to appear in these strings as _input too, e.g. __binary_{{[_a-zA-Z0-9]*}}_input_size

seiya updated this revision to Diff 217088.Aug 26 2019, 1:24 AM
seiya marked 3 inline comments as done.

Addressed review comments and added test for arm64.

seiya marked 2 inline comments as done.Aug 26 2019, 1:33 AM
seiya added inline comments.
llvm/test/tools/llvm-objcopy/MachO/binary-input.test
20

Note that GNU objcopy sets MH_MAGIC instead of MH_MAGIC64 for aarch64:

$ gobjcopy -I binary -B aarch64 -O mach-o-arm64 foo.txt binary.arm64.o

$ llvm-readobj binary.arm64.o                                         
File: binary.arm64.o
Format: Mach-O 32-bit unknown         <- should be "Mach-O arm64"!
Arch: aarch64
AddressSize: 32bit

$ otool -h binary.arm64.o   
Mach header
      magic cputype cpusubtype  caps    filetype ncmds  ...
 0xfeedface 16777228          0  0x00           1     3    ...

I have no experience with aarch64 MachO objects, but AFAIK the magic should be MH_MAGIC64 (example). I believe it's a bug in GNU objcopy...