[llvm-bugs] [Bug 50180] New: ObjFile feels a bit overtemplatized
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 30 06:58:50 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50180
Bug ID: 50180
Summary: ObjFile feels a bit overtemplatized
Product: lld
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: MachO
Assignee: unassignedbugs at nondot.org
Reporter: nicolasweber at gmx.de
CC: gkm at fb.com, jezreel at gmail.com,
llvm-bugs at lists.llvm.org, smeenai at fb.com
These methods in InputFiles.cpp are templatized on LP:
getPlatformInfo()
ObjFile::parse()
DylibFile::parse()
They use the template parameter to pick either mach_header or mach_header_64.
mach_header and mach_header_64 are the same except that the latter is one word
larger.
I think the template here is mostly unnecessary. For reading fields of
mach_header / mach_header_64 , we can use mach_header for both file formats
since the fields actually carrying data are the same.
For getting the offset in findCommand<>(), instead of
const uint8_t *p = reinterpret_cast<const uint8_t *>(hdr) + sizeof(Header);
we could do
const uint8_t *p = reinterpret_cast<const uint8_t *>(hdr);
if (reinterpret_cast<const mac_header *>(hdr)->magic == MH_MAGIC_64 ||
reinterpret_cast<const mac_header *>(hdr)->magic == MH_CIGAM_64)
p += sizeof(mach_header_64);
else
p += sizeof(mach_header);
(...which could be a method on InputFile).
Not super important, but it would've been a bit easier to read and understand
to me at least :)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210430/386e5e19/attachment.html>
More information about the llvm-bugs
mailing list