[PATCH] D155736: Fix __cfi_check not aligned to 4k on relocatable files with no executable code

2023-08-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks check-clang: http://45.33.8.238/linux/114361/step_7.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155736

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155736: Fix __cfi_check not aligned to 4k on relocatable files with no executable code

2023-08-03 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

It seems this patch broke the Solaris/amd64 buildbot 
:

  FAIL: Clang::cfi-check-fail.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155736

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155736: Fix __cfi_check not aligned to 4k on relocatable files with no executable code

2023-08-03 Thread Yi Kong via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7cacb2f6efe: Fix __cfi_check not aligned to 4k on 
relocatable files with no executable code (authored by kongyi).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155736

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/cfi-cross-dso-align.c


Index: clang/test/CodeGen/cfi-cross-dso-align.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-cross-dso-align.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+int a;
+
+// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], 
ptr %[[DATA:.*]]) align 4096
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3445,14 +3445,12 @@
   llvm::Function *F = llvm::Function::Create(
   llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
   llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  F->setAlignment(llvm::Align(4096));
   CGM.setDSOLocal(F);
   llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
-  // FIXME: consider emitting an intrinsic call like
-  // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
-  // which can be lowered in CrossDSOCFI pass to the actual contents of
-  // __cfi_check. This would allow inlining of __cfi_check calls.
-  llvm::CallInst::Create(
-  llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
+  // CrossDSOCFI pass is not executed if there is no executable code.
+  SmallVector Args{F->getArg(2), F->getArg(1)};
+  llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
   llvm::ReturnInst::Create(Ctx, nullptr, BB);
 }
 
@@ -3546,9 +3544,6 @@
   }
 
   FinishFunction();
-  // The only reference to this function will be created during LTO link.
-  // Make sure it survives until then.
-  CGM.addUsedGlobal(F);
 }
 
 void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {


Index: clang/test/CodeGen/cfi-cross-dso-align.c
===
--- /dev/null
+++ clang/test/CodeGen/cfi-cross-dso-align.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+int a;
+
+// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], ptr %[[DATA:.*]]) align 4096
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3445,14 +3445,12 @@
   llvm::Function *F = llvm::Function::Create(
   llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
   llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  F->setAlignment(llvm::Align(4096));
   CGM.setDSOLocal(F);
   llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
-  // FIXME: consider emitting an intrinsic call like
-  // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
-  // which can be lowered in CrossDSOCFI pass to the actual contents of
-  // __cfi_check. This would allow inlining of __cfi_check calls.
-  llvm::CallInst::Create(
-  llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
+  // CrossDSOCFI pass is not executed if there is no executable code.
+  SmallVector Args{F->getArg(2), F->getArg(1)};
+  llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
   llvm::ReturnInst::Create(Ctx, nullptr, BB);
 }
 
@@ -3546,9 +3544,6 @@
   }
 
   FinishFunction();
-  // The only reference to this function will be created during LTO link.
-  // Make sure it survives until then.
-  CGM.addUsedGlobal(F);
 }
 
 void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits