[PATCH] D137360: [Linker] Remove nocallback attribute while linking

Gulfem Savrun Yeniceri via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 17:12:50 PDT 2022


gulfem updated this revision to Diff 473378.
gulfem marked an inline comment as not done.
gulfem added a comment.

Added a test case and addressed feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137360/new/

https://reviews.llvm.org/D137360

Files:
  llvm/lib/Linker/LinkModules.cpp
  llvm/test/Linker/Inputs/drop-attribute.ll
  llvm/test/Linker/drop-attribute.ll


Index: llvm/test/Linker/drop-attribute.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/drop-attribute.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-link %s %p/Inputs/drop-attribute.ll -S -o - | FileCheck %s
+
+; Test case that checks that nocallback attribute is dropped during linking.
+
+; CHECK: define i32 @main()
+define i32 @main() {
+entry:
+  call void @test_nocallback()
+  ret i32 0
+}
+
+; CHECK-NOT: Function Attrs:
+; CHECK: declare void @test_nocallback()
+declare void @test_nocallback() nocallback
+
+; CHECK-NOT: attributes #0 = { }
+
Index: llvm/test/Linker/Inputs/drop-attribute.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/Inputs/drop-attribute.ll
@@ -0,0 +1,4 @@
+define void @bar() {
+entry:
+  ret void
+}
Index: llvm/lib/Linker/LinkModules.cpp
===================================================================
--- llvm/lib/Linker/LinkModules.cpp
+++ llvm/lib/Linker/LinkModules.cpp
@@ -375,8 +375,15 @@
        GV.hasAvailableExternallyLinkage()))
     return false;
 
-  if (GV.isDeclaration())
+  // Since nocallback function attribute is treated as a hint on
+  // the module level, it is removed while linking modules.
+  if (GV.isDeclaration()) {
+    if (auto *F = dyn_cast<Function>(&GV))
+      if (F->hasFnAttribute(llvm::Attribute::NoCallback))
+        F->removeFnAttr(llvm::Attribute::NoCallback);
+
     return false;
+  }
 
   LinkFrom ComdatFrom = LinkFrom::Dst;
   if (const Comdat *SC = GV.getComdat()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137360.473378.patch
Type: text/x-patch
Size: 1554 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221105/bd784f5f/attachment.bin>


More information about the llvm-commits mailing list