mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 18:46:06 +00:00

ORC supports loading relocatable object files into a JIT'd process. The raw "add object file" API (ObjectLayer::add) accepts plain relocatable object files as llvm::MemoryBuffers only and does not check that the object file's format or architecture are compatible with the process that it will be linked in to. This API is flexible, but places the burden of error checking and universal binary support on clients. This commit introduces a new utility, loadRelocatableObject, that takes a path to load and a target triple and then: 1. If the path does not exist, returns a FileError containing the invalid path. 2. If the path points to a MachO universal binary, identifies and returns MemoryBuffer covering the slice that matches the given triple (checking that the slice really does contains a valid MachO relocatable object with a compatible arch). 3. If the path points to a regular relocatable object file, verifies that the format and architecture are compatible with the triple. Clients can use loadRelocatableObject in the common case of loading object files from disk to simplify their code. Note: Error checking for ELF and COFF is left as a FIXME. rdar://133653290