[llvm] [BOLT] Err when linking objects of different architectures (PR #66770)

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 05:49:10 PDT 2023


https://github.com/mtvec created https://github.com/llvm/llvm-project/pull/66770

This could happen, for example, when instrumenting an AArch64 binary on an x86 host because the instrumentation library is always built for the host.

Note that this check will probably need to be refined in the future as merely having the same architecture does not guarantee objects can be linked. For example, on RISC-V, the float ABI of all objects should match.

>From f8b4bdb2c229f56a49e44904c430ac963977e6ea Mon Sep 17 00:00:00 2001
From: Job Noorman <jnoorman at igalia.com>
Date: Tue, 19 Sep 2023 14:39:38 +0200
Subject: [PATCH] [BOLT] Err when linking objects of different architectures

This could happen, for example, when instrumenting an AArch64 binary on
an x86 host because the instrumentation library is always built for the
host.

Note that this check will probably need to be refined in the future as
merely having the same architecture does not guarantee objects can be
linked. For example, on RISC-V, the float ABI of all objects should
match.
---
 bolt/lib/Rewrite/JITLinkLinker.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/bolt/lib/Rewrite/JITLinkLinker.cpp b/bolt/lib/Rewrite/JITLinkLinker.cpp
index ebbe2edd915fb6d..74f7967d6909ef2 100644
--- a/bolt/lib/Rewrite/JITLinkLinker.cpp
+++ b/bolt/lib/Rewrite/JITLinkLinker.cpp
@@ -179,6 +179,13 @@ void JITLinkLinker::loadObject(MemoryBufferRef Obj,
     exit(1);
   }
 
+  if ((*LG)->getTargetTriple().getArch() != BC.TheTriple->getArch()) {
+    errs() << "BOLT-ERROR: linking object withg arch "
+           << (*LG)->getTargetTriple().getArchName()
+           << " into context with arch " << BC.TheTriple->getArchName() << "\n";
+    exit(1);
+  }
+
   auto Ctx = std::make_unique<Context>(*this, MapSections);
   jitlink::link(std::move(*LG), std::move(Ctx));
 }



More information about the llvm-commits mailing list