[lld-macho] De-templatize mach_header operations
authorJez Ng <jezng@fb.com>
Mon, 3 May 2021 22:31:23 +0000 (18:31 -0400)
committerJez Ng <jezng@fb.com>
Mon, 3 May 2021 22:31:23 +0000 (18:31 -0400)
commit001ba65375f79a76491677cc2de05637f15a7a57
tree10bc333dbd16d39288889773fb33e0b4384aefa3
parent88ca010cc1854059c9e4a668750cd981e44238bc
[lld-macho] De-templatize mach_header operations

@thakis pointed out that `mach_header` and `mach_header_64`
actually have the same set of (used) fields, with the 64-bit version
having extra padding. So we can access the fields we need using the
single `mach_header` type instead of using templates to switch between
the two.

I also spotted a potential issue where hasObjCSection tries to parse a
file w/o checking if it does indeed match the target arch... As such,
I've added a quick magic number check to ensure we don't access invalid
memory during `findCommand()`.

Addresses PR50180.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D101724
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/MachO/ObjC.cpp
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Target.h
lld/MachO/Writer.cpp
lld/MachO/Writer.h
lld/test/MachO/objc.s