[llvm] [Linker] Propagate `nobuiltin` attributes when linking known libcalls (PR #89431)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 19 11:45:12 PDT 2024


================
@@ -1605,14 +1611,27 @@ Error IRLinker::run() {
 
   DstM.setTargetTriple(SrcTriple.merge(DstTriple));
 
+  // Update the target triple's libcall information if it was changed.
+  Libcalls.updateLibcalls(Triple(DstM.getTargetTriple()));
+
   // Loop over all of the linked values to compute type mappings.
   computeTypeMapping();
 
+  bool AddsLibcalls;
   std::reverse(Worklist.begin(), Worklist.end());
   while (!Worklist.empty()) {
     GlobalValue *GV = Worklist.back();
     Worklist.pop_back();
 
+    // If the module already contains libcall functions we need every function
+    // linked in to have `nobuiltin` attributes. Otherwise check if this is a
+    // libcall definition.
+    if (Function *F = dyn_cast<Function>(GV); F && Libcalls.hasLibcalls()) {
+      F->setAttributes(F->getAttributes().addFnAttribute(
+          F->getParent()->getContext(), Attribute::NoBuiltin));
----------------
jhuber6 wrote:

Updated

https://github.com/llvm/llvm-project/pull/89431


More information about the llvm-commits mailing list