<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ObjFile feels a bit overtemplatized"
   href="https://bugs.llvm.org/show_bug.cgi?id=50180">50180</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ObjFile feels a bit overtemplatized
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>MachO
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>gkm@fb.com, jezreel@gmail.com, llvm-bugs@lists.llvm.org, smeenai@fb.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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 :)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>