[llvm] [Object] Remove restriction universal archives having both IR and native (PR #67505)
Daniel RodrÃguez Troitiño via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 12:47:32 PDT 2023
================
@@ -134,65 +140,57 @@ Expected<Slice> Slice::create(const Archive &A, LLVMContext *LLVMCtx) {
.c_str());
if (Bin->isMachO()) {
MachOObjectFile *O = cast<MachOObjectFile>(Bin);
- if (IRFO) {
- return createStringError(
- std::errc::invalid_argument,
- "archive member %s is a MachO, while previous archive member "
- "%s was an IR LLVM object",
- O->getFileName().str().c_str(), IRFO->getFileName().str().c_str());
- }
- if (MFO &&
- std::tie(MFO->getHeader().cputype, MFO->getHeader().cpusubtype) !=
- std::tie(O->getHeader().cputype, O->getHeader().cpusubtype)) {
+ auto ObjectCPU = getMachoCPUFromObjectFile(O);
+ if (!ObjectCPU)
+ return ObjectCPU.takeError();
+
+ if (CPU && CPU != *ObjectCPU) {
+ // If CPU != nullptr, one of MFO, IRFO will be != nullptr.
+ StringRef PreviousName = MFO ? MFO->getFileName() : IRFO->getFileName();
return createStringError(
std::errc::invalid_argument,
("archive member " + O->getFileName() + " cputype (" +
- Twine(O->getHeader().cputype) + ") and cpusubtype(" +
- Twine(O->getHeader().cpusubtype) +
+ Twine(ObjectCPU->first) + ") and cpusubtype(" +
+ Twine(ObjectCPU->second) +
") does not match previous archive members cputype (" +
- Twine(MFO->getHeader().cputype) + ") and cpusubtype(" +
- Twine(MFO->getHeader().cpusubtype) +
- ") (all members must match) " + MFO->getFileName())
+ Twine(CPU->first) + ") and cpusubtype(" + Twine(CPU->second) +
+ ") (all members must match) " + PreviousName)
.str()
.c_str());
}
if (!MFO) {
ChildOrErr.get().release();
MFO.reset(O);
+ if (!CPU)
+ CPU.emplace(*ObjectCPU);
}
} else if (Bin->isIR()) {
IRObjectFile *O = cast<IRObjectFile>(Bin);
- if (MFO) {
- return createStringError(std::errc::invalid_argument,
- "archive member '%s' is an LLVM IR object, "
- "while previous archive member "
- "'%s' was a MachO",
- O->getFileName().str().c_str(),
- MFO->getFileName().str().c_str());
+ auto ObjectCPU = getMachoCPUFromTriple(O->getTargetTriple());
----------------
drodriguez wrote:
I think it will need to be `Expected<MachoCPUTy>`, but I will change it, if we want to avoid `auto`.
https://github.com/llvm/llvm-project/pull/67505
More information about the llvm-commits
mailing list