[llvm] r179051 - Template the MachO types over the word size.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Apr 17 11:48:23 PDT 2013


> My current idea for a better compromise is to have the templated
> implementation that can be used by performance critical code but
> provide getters in the base class so non performance critical code can
> avoid using the templates. For example, in templated code asking for a
> relocation entry returns a raw pointer whose type encodes the
> endianness. In non templated code, the method in the base class
> returns a wrapper struct with a PointerIntPair that records the actual
> pointer and the endianness. The wrapper then provides getters like
> getAddress() and getPCRel().

Getting back to this. First of all, sorry to Jim for the original
change. I assumed organizing MachO. like ELF.h was a reasonable thing,
but in the end it is your file format.

I decided to prototype two alternatives over templating on word size
and endianness.

The PointerIntPair patch implements pointers that use a bit to
remember the endianness of what they point to and implement getters
that flip the bytes if needed. The types is Support/Endian.h are still
being  used behind the scenes so any code for which the getters are
two slow can template itself and use the raw typed pointers.

The InMemomryStruct patch is closer to a semantic revert. It flips
bytes one struct at a time.

They are both just prototypes. The InMemomryStruct in particular still
has a copy even on matching endianness. I pushed just until I was able
to delete the MachObjectFileMdille class to test that the ideas
worked.

The PointerIntPair turned out to be more code than I was expecting. On
the InMemomryStruct I was able to avoid copying structs with buffers
in them (which is where the nasty lifetime bugs were from), so I guess
I now prefer the InMemomryStruct patch a bit more if templating like
ELF.h is not acceptable.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PointerIntPair.patch
Type: application/octet-stream
Size: 120688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130417/41c47924/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InMemomryStruct.patch
Type: application/octet-stream
Size: 69261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130417/41c47924/attachment-0001.obj>


More information about the llvm-commits mailing list