This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] Support dumping segment information in -chained_fixups
ClosedPublic

Authored by BertalanD on Aug 16 2022, 6:08 AM.

Details

Summary

[llvm-objdump] Support dumping segment information with -chained_fixups

This commit adds the definitions for dyld_chained_starts_in_image,
dyld_chained_starts_in_segment, and related enums. Dumping their
contents is possible with the -chained_fixups flag of llvm-otool.

The chained-fixups.yaml test was changed to cover bindings/rebases, as
well as weak imports, weak symbols and flat namespace symbols. Now that
we have actual fixup entries, the __DATA segment contains data that
would need to be hexdumped in YAML. We also test empty pages (to look
for the "DYLD_CHAINED_PTR_START_NONE" annotation), so the YAML would end
up quite large. So instead, this commit includes a binary file.

When Apple's effort to upstream their chained fixups code continues,
we'll replace this code with the then-upstreamed code. But we need
something in the meantime for testing ld64.lld's chained fixups code.

Diff Detail

Event Timeline

BertalanD created this revision.Aug 16 2022, 6:08 AM
BertalanD requested review of this revision.Aug 16 2022, 6:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2022, 6:08 AM
thakis accepted this revision.Aug 16 2022, 6:23 AM

Thanks!

llvm/include/llvm/BinaryFormat/MachO.h
2091

Do these have to swap the variably-sized tail too?

llvm/lib/Object/MachOObjectFile.cpp
4780

keep comment?

4794

nit: maybe const ref

This revision is now accepted and ready to land.Aug 16 2022, 6:23 AM
BertalanD updated this revision to Diff 452994.Aug 16 2022, 7:09 AM
BertalanD marked an inline comment as done.
BertalanD marked 2 inline comments as done.
BertalanD added inline comments.
llvm/include/llvm/BinaryFormat/MachO.h
2091

That's not possible because getStructOrErr<T> only copies sizeof(T) bytes of data. We manually swap the tail elements when reading them in getChainedFixupsSegments.

llvm/lib/Object/MachOObjectFile.cpp
4780

oops, fat fingered a Command-C. fixed.

https://buildkite.com/llvm-project/premerge-checks/builds/108031#0182a6ff-11e6-458e-baee-b8afd9d5669b I wonder if presubmit can't handle binary files well. Maybe presubmit just llvm/test/tools/llvm-objdump/MachO/Inputs/chained-fixups.macho-x86_64 and rebase this, to see if presubmit likes it more then.

llvm/include/llvm/BinaryFormat/MachO.h
2091

Maybe add a comment to that end.

BertalanD updated this revision to Diff 453024.Aug 16 2022, 8:34 AM
BertalanD marked 2 inline comments as done.
BertalanD edited the summary of this revision. (Show Details)
thakis added inline comments.Aug 17 2022, 12:49 PM
llvm/test/tools/llvm-objdump/MachO/chained-fixups.test
59

This needs an additional - in front of target (or no = – I prefer adding the - though)

BertalanD marked an inline comment as done.Aug 18 2022, 12:29 AM
llvm/test/tools/llvm-objdump/MachO/chained-fixups.test