[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 06:19:19 PDT 2023


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

>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 1/2] [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));
 }

>From 67da4e5b8f9ac5a035658bb6649fe380377b21a3 Mon Sep 17 00:00:00 2001
From: Job Noorman <jnoorman at igalia.com>
Date: Tue, 19 Sep 2023 15:02:54 +0200
Subject: [PATCH 2/2] Fix typo

---
 bolt/lib/Rewrite/JITLinkLinker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/JITLinkLinker.cpp b/bolt/lib/Rewrite/JITLinkLinker.cpp
index 74f7967d6909ef2..5c7f3101a53eaa5 100644
--- a/bolt/lib/Rewrite/JITLinkLinker.cpp
+++ b/bolt/lib/Rewrite/JITLinkLinker.cpp
@@ -180,7 +180,7 @@ void JITLinkLinker::loadObject(MemoryBufferRef Obj,
   }
 
   if ((*LG)->getTargetTriple().getArch() != BC.TheTriple->getArch()) {
-    errs() << "BOLT-ERROR: linking object withg arch "
+    errs() << "BOLT-ERROR: linking object with arch "
            << (*LG)->getTargetTriple().getArchName()
            << " into context with arch " << BC.TheTriple->getArchName() << "\n";
     exit(1);



More information about the llvm-commits mailing list