r352003 - [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls
Author: yln Date: Wed Jan 23 17:06:19 2019 New Revision: 352003 URL: http://llvm.org/viewvc/llvm-project?rev=352003&view=rev Log: [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls Summary: UBSan wants to detect when unreachable code is actually reached, so it adds instrumentation before every `unreachable` instruction. However, the optimizer will remove code after calls to functions marked with `noreturn`. To avoid this UBSan removes `noreturn` from both the call instruction as well as from the function itself. Unfortunately, ASan relies on this annotation to unpoison the stack by inserting calls to `_asan_handle_no_return` before `noreturn` functions. This is important for functions that do not return but access the the stack memory, e.g., unwinder functions *like* `longjmp` (`longjmp` itself is actually "double-proofed" via its interceptor). The result is that when ASan and UBSan are combined, the `noreturn` attributes are missing and ASan cannot unpoison the stack, so it has false positives when stack unwinding is used. Changes: # UBSan now adds the `expect_noreturn` attribute whenever it removes the `noreturn` attribute from a function # ASan additionally checks for the presence of this attribute Generated code: ``` call void @__asan_handle_no_return// Additionally inserted to avoid false positives call void @longjmp call void @__asan_handle_no_return call void @__ubsan_handle_builtin_unreachable unreachable ``` The second call to `__asan_handle_no_return` is redundant. This will be cleaned up in a follow-up patch. rdar://problem/40723397 Reviewers: delcypher, eugenis Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D56624 Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352003&r1=352002&r2=352003&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Jan 23 17:06:19 2019 @@ -4401,12 +4401,16 @@ RValue CodeGenFunction::EmitCall(const C if (UnusedReturnSizePtr) PopCleanupBlock(); -// Strip away the noreturn attribute to better diagnose unreachable UB. +// Replace the noreturn attribute to better diagnose unreachable UB. if (SanOpts.has(SanitizerKind::Unreachable)) { + // Also remove from function since CS.hasFnAttr(..) also checks attributes + // of the called function. if (auto *F = CS.getCalledFunction()) F->removeFnAttr(llvm::Attribute::NoReturn); CS.removeAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoReturn); + CS.addAttribute(llvm::AttributeList::FunctionIndex, + llvm::Attribute::ExpectNoReturn); } EmitUnreachable(Loc); Modified: cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp?rev=352003&r1=352002&r2=352003&view=diff == --- cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp (original) +++ cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Wed Jan 23 17:06:19 2019 @@ -2,38 +2,35 @@ extern void __attribute__((noreturn)) abort(); -// CHECK-LABEL: define void @_Z14calls_noreturnv +// CHECK-LABEL: define void @_Z14calls_noreturnv() void calls_noreturn() { + // CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR:#[0-9]+]] abort(); - // Check that there are no attributes on the call site. - // CHECK-NOT: call void @_Z5abortv{{.*}}# - // CHECK: __ubsan_handle_builtin_unreachable // CHECK: unreachable } struct A { - // CHECK: declare void @_Z5abortv{{.*}} [[ABORT_ATTR:#[0-9]+]] + // CHECK: declare void @_Z5abortv() [[EXTERN_FN_ATTR:#[0-9]+]] // CHECK-LABEL: define linkonce_odr void @_ZN1A5call1Ev void call1() { -// CHECK-NOT: call void @_ZN1A16does_not_return2Ev{{.*}}# +// CHECK: call void @_ZN1A16does_not_return2Ev({{.*}}) [[CALL_SITE_ATTR]] does_not_return2(); // CHECK: __ubsan_handle_builtin_unreachable // CHECK: unreachable } - // Test static members. + // Test static members. Checks are below after `struct A` scope ends. static void __attribute__((noreturn)) does_not_return1() { -// CHECK-NOT: call void @_Z5abortv{{.*}}# abort(); } // CHECK-LABEL: define linkonce_odr void @_ZN1A5call2Ev void call2() { -// CHECK-NOT: call void @_ZN1A16does_not_return1Ev{{.*}}# +// CHECK: call void @_ZN1A16does_not_return1Ev() [[CALL_SITE_ATTR]] does_not_return1(); // CHECK: __ubsan_handle_builtin_unreachable @@ -46,18 +43,18 @@ struct A { // CHECK-LABEL: define linkonce_odr void @_ZN1A5call3Ev void call3() { MemFn MF = &A::does_not_return
r352069 - Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls"
Author: yln Date: Thu Jan 24 10:04:21 2019 New Revision: 352069 URL: http://llvm.org/viewvc/llvm-project?rev=352069&view=rev Log: Revert "[Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls" This reverts commit cea84ab93aeb079a358ab1c8aeba6d9140ef8b47. Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352069&r1=352068&r2=352069&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Jan 24 10:04:21 2019 @@ -4401,16 +4401,12 @@ RValue CodeGenFunction::EmitCall(const C if (UnusedReturnSizePtr) PopCleanupBlock(); -// Replace the noreturn attribute to better diagnose unreachable UB. +// Strip away the noreturn attribute to better diagnose unreachable UB. if (SanOpts.has(SanitizerKind::Unreachable)) { - // Also remove from function since CS.hasFnAttr(..) also checks attributes - // of the called function. if (auto *F = CS.getCalledFunction()) F->removeFnAttr(llvm::Attribute::NoReturn); CS.removeAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoReturn); - CS.addAttribute(llvm::AttributeList::FunctionIndex, - llvm::Attribute::ExpectNoReturn); } EmitUnreachable(Loc); Modified: cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp?rev=352069&r1=352068&r2=352069&view=diff == --- cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp (original) +++ cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Thu Jan 24 10:04:21 2019 @@ -2,35 +2,38 @@ extern void __attribute__((noreturn)) abort(); -// CHECK-LABEL: define void @_Z14calls_noreturnv() +// CHECK-LABEL: define void @_Z14calls_noreturnv void calls_noreturn() { - // CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR:#[0-9]+]] abort(); + // Check that there are no attributes on the call site. + // CHECK-NOT: call void @_Z5abortv{{.*}}# + // CHECK: __ubsan_handle_builtin_unreachable // CHECK: unreachable } struct A { - // CHECK: declare void @_Z5abortv() [[EXTERN_FN_ATTR:#[0-9]+]] + // CHECK: declare void @_Z5abortv{{.*}} [[ABORT_ATTR:#[0-9]+]] // CHECK-LABEL: define linkonce_odr void @_ZN1A5call1Ev void call1() { -// CHECK: call void @_ZN1A16does_not_return2Ev({{.*}}) [[CALL_SITE_ATTR]] +// CHECK-NOT: call void @_ZN1A16does_not_return2Ev{{.*}}# does_not_return2(); // CHECK: __ubsan_handle_builtin_unreachable // CHECK: unreachable } - // Test static members. Checks are below after `struct A` scope ends. + // Test static members. static void __attribute__((noreturn)) does_not_return1() { +// CHECK-NOT: call void @_Z5abortv{{.*}}# abort(); } // CHECK-LABEL: define linkonce_odr void @_ZN1A5call2Ev void call2() { -// CHECK: call void @_ZN1A16does_not_return1Ev() [[CALL_SITE_ATTR]] +// CHECK-NOT: call void @_ZN1A16does_not_return1Ev{{.*}}# does_not_return1(); // CHECK: __ubsan_handle_builtin_unreachable @@ -43,18 +46,18 @@ struct A { // CHECK-LABEL: define linkonce_odr void @_ZN1A5call3Ev void call3() { MemFn MF = &A::does_not_return2; -// CHECK: call void %{{[0-9]+\(.*}}) [[CALL_SITE_ATTR]] (this->*MF)(); +// CHECK-NOT: call void %{{.*}}# // CHECK: __ubsan_handle_builtin_unreachable // CHECK: unreachable } // Test regular members. // CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return2Ev({{.*}}) - // CHECK-SAME: [[USER_FN_ATTR:#[0-9]+]] + // CHECK-SAME: [[DOES_NOT_RETURN_ATTR:#[0-9]+]] void __attribute__((noreturn)) does_not_return2() { -// CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR]] +// CHECK-NOT: call void @_Z5abortv(){{.*}}# abort(); // CHECK: call void @__ubsan_handle_builtin_unreachable @@ -65,9 +68,7 @@ struct A { } }; -// CHECK-LABEL: define linkonce_odr void @_ZN1A16does_not_return1Ev() -// CHECK-SAME: [[USER_FN_ATTR]] -// CHECK: call void @_Z5abortv() [[CALL_SITE_ATTR]] +// CHECK: define linkonce_odr void @_ZN1A16does_not_return1Ev() [[DOES_NOT_RETURN_ATTR]] void force_irgen() { A a; @@ -76,9 +77,5 @@ void force_irgen() { a.call3(); } -// 1) 'noreturn' should be removed from functions and call sites -// 2) 'expect_noreturn' added to call sites -// CHECK-LABEL: attributes -// CHECK: [[USER_FN_ATTR]] = { {{.*[^noreturn].*}} } -// CHECK: [[EXTERN_FN_ATTR]] = { {{.*[^noreturn].*}} } -// CHECK: [[CALL_SITE_ATTR]] = { expect_noreturn } +// CHECK-NOT: [[ABORT_ATTR]] = {{[^}]+}}noreturn +// CHECK-NOT: [[DOES_NOT_RETURN_ATTR]] = {{[^}]+}}noreturn ___
r352690 - [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls
Author: yln Date: Wed Jan 30 15:42:13 2019 New Revision: 352690 URL: http://llvm.org/viewvc/llvm-project?rev=352690&view=rev Log: [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls Summary: UBSan wants to detect when unreachable code is actually reached, so it adds instrumentation before every unreachable instruction. However, the optimizer will remove code after calls to functions marked with noreturn. To avoid this UBSan removes noreturn from both the call instruction as well as from the function itself. Unfortunately, ASan relies on this annotation to unpoison the stack by inserting calls to _asan_handle_no_return before noreturn functions. This is important for functions that do not return but access the the stack memory, e.g., unwinder functions *like* longjmp (longjmp itself is actually "double-proofed" via its interceptor). The result is that when ASan and UBSan are combined, the noreturn attributes are missing and ASan cannot unpoison the stack, so it has false positives when stack unwinding is used. Changes: Clang-CodeGen now directly insert calls to `__asan_handle_no_return` when a call to a noreturn function is encountered and both UBsan-unreachable and ASan are enabled. This allows UBSan to continue removing the noreturn attribute from functions without any changes to the ASan pass. Previously generated code: ``` call void @longjmp call void @__asan_handle_no_return call void @__ubsan_handle_builtin_unreachable ``` Generated code (for now): ``` call void @__asan_handle_no_return call void @longjmp call void @__asan_handle_no_return call void @__ubsan_handle_builtin_unreachable ``` rdar://problem/40723397 Reviewers: delcypher, eugenis, vsk Differential Revision: https://reviews.llvm.org/D57278 Added: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352690&r1=352689&r2=352690&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Jan 30 15:42:13 2019 @@ -4398,10 +4398,23 @@ RValue CodeGenFunction::EmitCall(const C // Strip away the noreturn attribute to better diagnose unreachable UB. if (SanOpts.has(SanitizerKind::Unreachable)) { + // Also remove from function since CI->hasFnAttr(..) also checks attributes + // of the called function. if (auto *F = CI->getCalledFunction()) F->removeFnAttr(llvm::Attribute::NoReturn); CI->removeAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoReturn); + + // Avoid incompatibility with ASan which relies on the `noreturn` + // attribute to insert handler calls. + if (SanOpts.has(SanitizerKind::Address)) { +SanitizerScope SanScope(this); +Builder.SetInsertPoint(CI); +auto *FnType = llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false); +auto *Fn = CGM.CreateRuntimeFunction(FnType, "__asan_handle_no_return"); +EmitNounwindRuntimeCall(Fn); +Builder.SetInsertPoint(CI->getParent()); + } } EmitUnreachable(Loc); Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=352690&r1=352689&r2=352690&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original) +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Jan 30 15:42:13 2019 @@ -4084,8 +4084,8 @@ public: /// passing to a runtime sanitizer handler. llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); - /// Create a basic block that will call a handler function in a - /// sanitizer runtime with the provided arguments, and create a conditional + /// Create a basic block that will either trap or call a handler function in + /// the UBSan runtime with the provided arguments, and create a conditional /// branch to it. void EmitCheck(ArrayRef> Checked, SanitizerHandler Check, ArrayRef StaticArgs, Added: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c?rev=352690&view=auto == --- cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c (added) +++ cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Wed Jan 30 15:42:13 2019 @@ -0,0 +1,21 @@ +// Ensure compatiblity of UBSan unreachable with ASan in the presence of +// noreturn functions. +// RUN: %clang_cc1 -fsanitize=unreachable,address -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s + +void my_longjmp(void) __attribute__((
Re: r352690 - [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls
Thank you, Eric, for the reproducer and instructions. Actionable and much appreciated.Can you test my updated patch on your build before I try again? updated_patch.patch Description: Binary data delta.diff Description: Binary data On Jan 31, 2019, at 6:19 AM, Eric Liu <ioe...@google.com> wrote:And the stack trace is:```1. parser at end of file [31/1788]2. Code generation 3. Running pass 'Function Pass Manager' on module 'absl/base/internal/throw_delegate.cc'. 4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN4absl13base_internal18ThrowStdLogicErrorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE' #0 0x55c42e7bce9d SignalHandler(int) (bin/clang+0x1aabe9d) #1 0x7f41b11309a0 __restore_rt (/usr/grte/v4/lib64/libpthread.so.0+0xf9a0) #2 0x55c42fe10b5b findUnwindDestinations(llvm::FunctionLoweringInfo&, llvm::BasicBlock const*, llvm::BranchProbability, llvm::SmallVectorImpl> >&) (bin/clang+0x30ffb5b) #3 0x55c42fe0b49a llvm::SelectionDAGBuilder::visitInvoke(llvm::InvokeInst const&) (bin/clang+0x30fa49a) #4 0x55c4308a8a2f llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (bin/clang+0x3b97a2f) #5 0x55c430878aa5 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator, false, true>, llvm::ilist_iterator::node_options, false, true>, bool&) (bin/clang+0x3b67aa5) #6 0x55c4308768ed llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (bin/clang+0x3b658ed) #7 0x55c43087354a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (bin/clang+0x3b6254a) #8 0x55c43086d1da (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (bin/clang+0x3b5c1da) #9 0x55c4309eb833 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (bin/clang+0x3cda833)#10 0x55c43070edbe llvm::FPPassManager::runOnFunction(llvm::Function&) (bin/clang+0x39fddbe)#11 0x55c430711521 llvm::FPPassManager::runOnModule(llvm::Module&) (bin/clang+0x3a00521)#12 0x55c42e4a6f7f llvm::legacy::PassManagerImpl::run(llvm::Module&) (bin/clang+0x1795f7f)#13 0x55c42e7d9594 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::__g::unique_ptr >) (bin/clang+0x1ac8594)#14 0x55c42e7a4d8c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (bin/clang+0x1a93d8c)#15 0x55c42e6499b6 clang::ParseAST(clang::Sema&, bool, bool) (bin/clang+0x19389b6)#16 0x55c42e7a8b37 clang::FrontendAction::Execute() (bin/clang+0x1a97b37)#17 0x55c42e7ae75f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (bin/clang+0x1a9d75f)#18 0x55c42e796cfb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (bin/clang+0x1a85cfb)#19 0x55c42e791071 cc1_main(llvm::ArrayRef, char const*, void*) (bin/clang+0x1a80071)#20 0x55c42e5c019e main (bin/clang+0x18af19e)#21 0x7f41b0e9ebbd __libc_start_main (/usr/grte/v4/lib64/libc.so.6+0x38bbd)#22 0x55c42e6d44a9 _start (bin/clang+0x19c34a9)clang: error: unable to execute command: Segmentation faultclang: error: clang frontend command failed due to signal (use -v to see invocation)```On Thu, Jan 31, 2019 at 3:11 PM Eric Liu <ioe...@google.com> wrote:I managed to get a reproducer (attached) from absl:```clang++ -std=c++17 -fsanitize=address,unreachable throw_delegate.pic.ii```You could regenerate the preprocessed code:```git clone https://github.com/abseil/abseil-cpp.gitcd abseil-cpp/abslbazel build --compilation_mode=fastbuild --save_temps --compile_one_dependency base/internal/throw_delegate.cc```I'll revert the commit to unblock our integration process. Let us know if you need more information.- EricOn Thu, Jan 31, 2019 at 9:01 AM Eric Christopher <echri...@gmail.com> wrote:Looks like this broke optimized asan builds via an assert in SCCP. I'll see what I can do about a testcase (or Eric will), however, would you mind reverting in the meantime?Thanks!-ericOn Wed, Jan 30, 2019 at 4:41 PM Julian Lettner via cf
r352829 - [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls
Author: yln Date: Thu Jan 31 18:51:00 2019 New Revision: 352829 URL: http://llvm.org/viewvc/llvm-project?rev=352829&view=rev Log: [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls Summary: UBSan wants to detect when unreachable code is actually reached, so it adds instrumentation before every unreachable instruction. However, the optimizer will remove code after calls to functions marked with noreturn. To avoid this UBSan removes noreturn from both the call instruction as well as from the function itself. Unfortunately, ASan relies on this annotation to unpoison the stack by inserting calls to _asan_handle_no_return before noreturn functions. This is important for functions that do not return but access the the stack memory, e.g., unwinder functions *like* longjmp (longjmp itself is actually "double-proofed" via its interceptor). The result is that when ASan and UBSan are combined, the noreturn attributes are missing and ASan cannot unpoison the stack, so it has false positives when stack unwinding is used. Changes: Clang-CodeGen now directly insert calls to `__asan_handle_no_return` when a call to a noreturn function is encountered and both UBsan-unreachable and ASan are enabled. This allows UBSan to continue removing the noreturn attribute from functions without any changes to the ASan pass. Previously generated code: ``` call void @longjmp call void @__asan_handle_no_return call void @__ubsan_handle_builtin_unreachable ``` Generated code (for now): ``` call void @__asan_handle_no_return call void @longjmp call void @__asan_handle_no_return call void @__ubsan_handle_builtin_unreachable ``` rdar://problem/40723397 Reviewers: delcypher, eugenis, vsk Differential Revision: https://reviews.llvm.org/D57278 llvm-svn: 352690 Added: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/test/CodeGenCXX/ubsan-unreachable.cpp Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352829&r1=352828&r2=352829&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Jan 31 18:51:00 2019 @@ -4398,10 +4398,23 @@ RValue CodeGenFunction::EmitCall(const C // Strip away the noreturn attribute to better diagnose unreachable UB. if (SanOpts.has(SanitizerKind::Unreachable)) { + // Also remove from function since CI->hasFnAttr(..) also checks attributes + // of the called function. if (auto *F = CI->getCalledFunction()) F->removeFnAttr(llvm::Attribute::NoReturn); CI->removeAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoReturn); + + // Avoid incompatibility with ASan which relies on the `noreturn` + // attribute to insert handler calls. + if (SanOpts.has(SanitizerKind::Address)) { +SanitizerScope SanScope(this); +llvm::IRBuilder<>::InsertPointGuard IPGuard(Builder); +Builder.SetInsertPoint(CI); +auto *FnType = llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false); +auto *Fn = CGM.CreateRuntimeFunction(FnType, "__asan_handle_no_return"); +EmitNounwindRuntimeCall(Fn); + } } EmitUnreachable(Loc); Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=352829&r1=352828&r2=352829&view=diff == --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original) +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Jan 31 18:51:00 2019 @@ -4084,8 +4084,8 @@ public: /// passing to a runtime sanitizer handler. llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); - /// Create a basic block that will call a handler function in a - /// sanitizer runtime with the provided arguments, and create a conditional + /// Create a basic block that will either trap or call a handler function in + /// the UBSan runtime with the provided arguments, and create a conditional /// branch to it. void EmitCheck(ArrayRef> Checked, SanitizerHandler Check, ArrayRef StaticArgs, Added: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c?rev=352829&view=auto == --- cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c (added) +++ cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Thu Jan 31 18:51:00 2019 @@ -0,0 +1,21 @@ +// Ensure compatiblity of UBSan unreachable with ASan in the presence of +// noreturn functions. +// RUN: %clang_cc1 -fsanitize=unreachable,address -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s + +void m
r352948 - [ASan] Do not instrument other runtime functions with `__asan_handle_no_return`
Author: yln Date: Fri Feb 1 18:05:16 2019 New Revision: 352948 URL: http://llvm.org/viewvc/llvm-project?rev=352948&view=rev Log: [ASan] Do not instrument other runtime functions with `__asan_handle_no_return` Summary: Currently, ASan inserts a call to `__asan_handle_no_return` before every `noreturn` function call/invoke. This is unnecessary for calls to other runtime funtions. This patch changes ASan to skip instrumentation for functions calls marked with `!nosanitize` metadata. Reviewers: TODO Differential Revision: https://reviews.llvm.org/D57489 Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=352948&r1=352947&r2=352948&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Feb 1 18:05:16 2019 @@ -4394,8 +4394,8 @@ RValue CodeGenFunction::EmitCall(const C // Strip away the noreturn attribute to better diagnose unreachable UB. if (SanOpts.has(SanitizerKind::Unreachable)) { - // Also remove from function since CI->hasFnAttr(..) also checks attributes - // of the called function. + // Also remove from function since CallBase::hasFnAttr additionally checks + // attributes of the called function. if (auto *F = CI->getCalledFunction()) F->removeFnAttr(llvm::Attribute::NoReturn); CI->removeAttribute(llvm::AttributeList::FunctionIndex, Modified: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c?rev=352948&r1=352947&r2=352948&view=diff == --- cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c (original) +++ cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Fri Feb 1 18:05:16 2019 @@ -9,8 +9,7 @@ void calls_noreturn() { my_longjmp(); // CHECK: @__asan_handle_no_return{{.*}} !nosanitize // CHECK-NEXT: @my_longjmp(){{[^#]*}} - // CHECK: @__asan_handle_no_return() - // CHECK-NEXT: @__ubsan_handle_builtin_unreachable{{.*}} !nosanitize + // CHECK: @__ubsan_handle_builtin_unreachable{{.*}} !nosanitize // CHECK-NEXT: unreachable } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r353120 - [Sanitizers] UBSan unreachable incompatible with Kernel ASan
Author: yln Date: Mon Feb 4 15:37:50 2019 New Revision: 353120 URL: http://llvm.org/viewvc/llvm-project?rev=353120&view=rev Log: [Sanitizers] UBSan unreachable incompatible with Kernel ASan Summary: This is a follow up for https://reviews.llvm.org/D57278. The previous revision should have also included Kernel ASan. rdar://problem/40723397 Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57711 Modified: cfe/trunk/lib/CodeGen/CGCall.cpp cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Modified: cfe/trunk/lib/CodeGen/CGCall.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=353120&r1=353119&r2=353120&view=diff == --- cfe/trunk/lib/CodeGen/CGCall.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Feb 4 15:37:50 2019 @@ -4403,7 +4403,8 @@ RValue CodeGenFunction::EmitCall(const C // Avoid incompatibility with ASan which relies on the `noreturn` // attribute to insert handler calls. - if (SanOpts.has(SanitizerKind::Address)) { + if (SanOpts.hasOneOf(SanitizerKind::Address | + SanitizerKind::KernelAddress)) { SanitizerScope SanScope(this); llvm::IRBuilder<>::InsertPointGuard IPGuard(Builder); Builder.SetInsertPoint(CI); Modified: cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c?rev=353120&r1=353119&r2=353120&view=diff == --- cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c (original) +++ cfe/trunk/test/CodeGen/ubsan-asan-noreturn.c Mon Feb 4 15:37:50 2019 @@ -1,6 +1,7 @@ // Ensure compatiblity of UBSan unreachable with ASan in the presence of // noreturn functions. -// RUN: %clang_cc1 -fsanitize=unreachable,address -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fsanitize=unreachable,address-triple x86_64-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fsanitize=unreachable,kernel-address -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s void my_longjmp(void) __attribute__((noreturn)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 99d6e05 - [lit] Improve naming of test result categories
Author: Julian Lettner Date: 2020-06-05T08:14:42-07:00 New Revision: 99d6e05e7144a2638c4e85ea75099e9dc6432cde URL: https://github.com/llvm/llvm-project/commit/99d6e05e7144a2638c4e85ea75099e9dc6432cde DIFF: https://github.com/llvm/llvm-project/commit/99d6e05e7144a2638c4e85ea75099e9dc6432cde.diff LOG: [lit] Improve naming of test result categories Improve consistency when printing test results: Previously we were using different labels for group names (the header for the list of, e.g., failing tests) and summary count lines. For example, "Failing Tests"/"Unexpected Failures". This commit changes lit to label things consistently. Improve wording of labels: When talking about individual test results, the first word in "Unexpected Failures", "Expected Passes", and "Individual Timeouts" is superfluous. Some labels contain the word "Tests" and some don't. Let's simplify the names. Before: ``` Failing Tests (1): ... Expected Passes: 3 Unexpected Failures: 1 ``` After: ``` Failed Tests (1): ... Passed: 3 Failed: 1 ``` Reviewed By: ldionne Differential Revision: https://reviews.llvm.org/D77708 Added: Modified: clang/www/hacking.html llvm/utils/lit/lit/main.py llvm/utils/lit/tests/allow-retries.py llvm/utils/lit/tests/custom-result-category.py llvm/utils/lit/tests/googletest-discovery-failed.py llvm/utils/lit/tests/googletest-format.py llvm/utils/lit/tests/googletest-timeout.py llvm/utils/lit/tests/googletest-upstream-format.py llvm/utils/lit/tests/lit-opts.py llvm/utils/lit/tests/max-failures.py llvm/utils/lit/tests/max-time.py llvm/utils/lit/tests/parallelism-groups.py llvm/utils/lit/tests/selecting.py llvm/utils/lit/tests/shtest-env.py llvm/utils/lit/tests/shtest-format.py llvm/utils/lit/tests/shtest-inject.py llvm/utils/lit/tests/shtest-not.py llvm/utils/lit/tests/shtest-shell.py llvm/utils/lit/tests/shtest-timeout.py mlir/test/Examples/standalone/test.toy Removed: diff --git a/clang/www/hacking.html b/clang/www/hacking.html index 3623b904119a..ad1b4ea94bf5 100755 --- a/clang/www/hacking.html +++ b/clang/www/hacking.html @@ -264,12 +264,12 @@ Testing on the Command Line -- Testing: Testing: 2534 tests, 4 threads -- Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Testing Time: 81.52s - Expected Passes: 2503 - Expected Failures : 28 - Unsupported Tests : 3 + Passed : 2503 + Expectedly Failed: 28 + Unsupported :3 - The statistic, "Unexpected Failures" (not shown if all tests pass), is the important one. + The statistic, "Failed" (not shown if all tests pass), is the important one. Creating Patch Files diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 6c423167ff4c..b8c951360322 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -265,34 +265,33 @@ def print_histogram(tests): def add_result_category(result_code, label): assert isinstance(result_code, lit.Test.ResultCode) -category = (result_code, "%s Tests" % label, label) +category = (result_code, label) result_codes.append(category) -# Status code, summary label, group label result_codes = [ # Passes -(lit.Test.EXCLUDED,'Excluded Tests', 'Excluded'), -(lit.Test.SKIPPED, 'Skipped Tests', 'Skipped'), -(lit.Test.UNSUPPORTED, 'Unsupported Tests', 'Unsupported'), -(lit.Test.PASS,'Expected Passes', ''), -(lit.Test.FLAKYPASS, 'Passes With Retry', ''), -(lit.Test.XFAIL, 'Expected Failures', 'Expected Failing'), +(lit.Test.EXCLUDED,'Excluded'), +(lit.Test.SKIPPED, 'Skipped'), +(lit.Test.UNSUPPORTED, 'Unsupported'), +(lit.Test.PASS,'Passed'), +(lit.Test.FLAKYPASS, 'Passed With Retry'), +(lit.Test.XFAIL, 'Expectedly Failed'), # Failures -(lit.Test.UNRESOLVED, 'Unresolved Tests','Unresolved'), -(lit.Test.TIMEOUT, 'Individual Timeouts', 'Timed Out'), -(lit.Test.FAIL,'Unexpected Failures', 'Failing'), -(lit.Test.XPASS, 'Unexpected Passes', 'Unexpected Passing') +(lit.Test.UNRESOLVED, 'Unresolved'), +(lit.Test.TIMEOUT, 'Timed Out'), +(lit.Test.FAIL,'Failed'), +(lit.Test.XPASS, 'Unexpectedly Passed') ] def print_results(tests, elapsed, opts): -tests_by_code = {code: [] for (code, _, _) in result_codes} +tests_by_code = {code: [] for code, _ in result_codes} for test in tests: tests_by_code[test.result.code].append(test) -for (code, _, group_label) in result_codes: -print_group(code, group_label, tests_by_code[code], opts) +for (code, label) in result_codes: +print_group(code, label, tests_by_code[code], opts) print_summary(tests_by_code, opts.quiet, elapsed) @@ -318,7 +317,7 @@ def
[clang] 2d66571 - [Driver] Fix & re-enable DriverKit test
Author: Julian Lettner Date: 2022-08-29T10:27:04-07:00 New Revision: 2d66571729a2ffcd88398a77508b0d6432ed7ba0 URL: https://github.com/llvm/llvm-project/commit/2d66571729a2ffcd88398a77508b0d6432ed7ba0 DIFF: https://github.com/llvm/llvm-project/commit/2d66571729a2ffcd88398a77508b0d6432ed7ba0.diff LOG: [Driver] Fix & re-enable DriverKit test Added: Modified: clang/test/Driver/driverkit-path.c Removed: diff --git a/clang/test/Driver/driverkit-path.c b/clang/test/Driver/driverkit-path.c index 0aa3e958b2908..c061a1b1c5ed9 100644 --- a/clang/test/Driver/driverkit-path.c +++ b/clang/test/Driver/driverkit-path.c @@ -1,7 +1,4 @@ // REQUIRES: x86-registered-target -// REQUIRES: darwin -// FIXME: Breaks on non-macOS: -//http://45.33.8.238/linux/85125/step_7.txt // RUN: %clang %s -target x86_64-apple-driverkit19.0 -mlinker-version=0 \ // RUN: -isysroot %S/Inputs/DriverKit19.0.sdk -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=LD64-OLD @@ -25,7 +22,6 @@ int main() { return 0; } // RUN: %clang %s -target x86_64-apple-driverkit19.0 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC -// RUN: %clang %s -arch x86_64 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC // // INC: -isysroot [[PATH:[^ ]*/Inputs/DriverKit19.0.sdk]] // INC-LABEL: #include <...> search starts here: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ce6989f - Revert "[Driver] Fix & re-enable DriverKit test"
Author: Julian Lettner Date: 2022-08-29T11:59:01-07:00 New Revision: ce6989fd8a9fb2608f670de023fdd4611f47b811 URL: https://github.com/llvm/llvm-project/commit/ce6989fd8a9fb2608f670de023fdd4611f47b811 DIFF: https://github.com/llvm/llvm-project/commit/ce6989fd8a9fb2608f670de023fdd4611f47b811.diff LOG: Revert "[Driver] Fix & re-enable DriverKit test" This reverts commit 2d66571729a2ffcd88398a77508b0d6432ed7ba0 due to test failure: http://45.33.8.238/win/65224/step_7.txt Added: Modified: clang/test/Driver/driverkit-path.c Removed: diff --git a/clang/test/Driver/driverkit-path.c b/clang/test/Driver/driverkit-path.c index c061a1b1c5ed9..0aa3e958b2908 100644 --- a/clang/test/Driver/driverkit-path.c +++ b/clang/test/Driver/driverkit-path.c @@ -1,4 +1,7 @@ // REQUIRES: x86-registered-target +// REQUIRES: darwin +// FIXME: Breaks on non-macOS: +//http://45.33.8.238/linux/85125/step_7.txt // RUN: %clang %s -target x86_64-apple-driverkit19.0 -mlinker-version=0 \ // RUN: -isysroot %S/Inputs/DriverKit19.0.sdk -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=LD64-OLD @@ -22,6 +25,7 @@ int main() { return 0; } // RUN: %clang %s -target x86_64-apple-driverkit19.0 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC +// RUN: %clang %s -arch x86_64 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC // // INC: -isysroot [[PATH:[^ ]*/Inputs/DriverKit19.0.sdk]] // INC-LABEL: #include <...> search starts here: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 79fe9aa - [Driver] Fix & re-enable DriverKit test
Author: Julian Lettner Date: 2022-08-29T15:05:22-07:00 New Revision: 79fe9aaf6a7b13e23492e900c7ff5b9659df5544 URL: https://github.com/llvm/llvm-project/commit/79fe9aaf6a7b13e23492e900c7ff5b9659df5544 DIFF: https://github.com/llvm/llvm-project/commit/79fe9aaf6a7b13e23492e900c7ff5b9659df5544.diff LOG: [Driver] Fix & re-enable DriverKit test This reverts commit ce6989fd8a9fb2608f670de023fdd4611f47b811. Added: Modified: clang/test/Driver/driverkit-path.c Removed: diff --git a/clang/test/Driver/driverkit-path.c b/clang/test/Driver/driverkit-path.c index 0aa3e958b2908..0b752b1fc9c41 100644 --- a/clang/test/Driver/driverkit-path.c +++ b/clang/test/Driver/driverkit-path.c @@ -1,7 +1,7 @@ // REQUIRES: x86-registered-target -// REQUIRES: darwin -// FIXME: Breaks on non-macOS: -//http://45.33.8.238/linux/85125/step_7.txt +// UNSUPPORTED: system-windows +// Windows is unsupported because we use the Unix path separator `\`. + // RUN: %clang %s -target x86_64-apple-driverkit19.0 -mlinker-version=0 \ // RUN: -isysroot %S/Inputs/DriverKit19.0.sdk -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=LD64-OLD @@ -25,7 +25,6 @@ int main() { return 0; } // RUN: %clang %s -target x86_64-apple-driverkit19.0 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC -// RUN: %clang %s -arch x86_64 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC // // INC: -isysroot [[PATH:[^ ]*/Inputs/DriverKit19.0.sdk]] // INC-LABEL: #include <...> search starts here: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)
@@ -758,9 +758,14 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, } } - // Add non-standard, platform-specific search paths, e.g., for DriverKit: - // -L/System/DriverKit/usr/lib - // -F/System/DriverKit/System/Library/Framework + // Add framework include paths and library search paths. + // There are two flavors: + // 1. The "non-standard" paths, e.g. for DriverKit: + // -L/System/DriverKit/usr/lib + // -F/System/DriverKit/System/Library/Frameworks + // 2. The "standard" paths, e.g. for macOS and iOS: + // -F/System/Library/Frameworks + // -F/Library/Frameworks { bool NonStandardSearchPath = false; yln wrote: Do you mean that `ld64-605.1` is old enough / has "aged out" by now so we can drop this special case? https://github.com/llvm/llvm-project/pull/75841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)
https://github.com/yln edited https://github.com/llvm/llvm-project/pull/75841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)
@@ -758,9 +758,14 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, } } - // Add non-standard, platform-specific search paths, e.g., for DriverKit: - // -L/System/DriverKit/usr/lib - // -F/System/DriverKit/System/Library/Framework + // Add framework include paths and library search paths. + // There are two flavors: + // 1. The "non-standard" paths, e.g. for DriverKit: + // -L/System/DriverKit/usr/lib + // -F/System/DriverKit/System/Library/Frameworks + // 2. The "standard" paths, e.g. for macOS and iOS: + // -F/System/Library/Frameworks + // -F/Library/Frameworks { bool NonStandardSearchPath = false; yln wrote: Got it, that would be another good cleanup! I recommend doing this as a separate PR. https://github.com/llvm/llvm-project/pull/75841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)
https://github.com/yln approved this pull request. https://github.com/llvm/llvm-project/pull/75841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 64902d3 - Reland "Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO"
Author: Julian Lettner Date: 2022-03-23T18:36:55-07:00 New Revision: 64902d335c2126e24a9d84b7410924148959e4a9 URL: https://github.com/llvm/llvm-project/commit/64902d335c2126e24a9d84b7410924148959e4a9 DIFF: https://github.com/llvm/llvm-project/commit/64902d335c2126e24a9d84b7410924148959e4a9.diff LOG: Reland "Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO" For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121736 Added: llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors-existing-dos_handle.ll llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/docs/Passes.rst llvm/include/llvm/CodeGen/CommandFlags.h llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h llvm/include/llvm/InitializePasses.h llvm/include/llvm/LinkAllPasses.h llvm/include/llvm/Target/TargetOptions.h llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h llvm/include/llvm/Transforms/Utils.h llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/CodeGen/TargetPassConfig.cpp llvm/lib/Passes/PassBuilder.cpp llvm/lib/Passes/PassRegistry.def llvm/lib/Target/WebAssembly/CMakeLists.txt llvm/lib/Target/WebAssembly/WebAssembly.h llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp llvm/lib/Transforms/Utils/CMakeLists.txt llvm/lib/Transforms/Utils/Utils.cpp llvm/test/CodeGen/ARM/ctors_dtors.ll llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll Removed: llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 0cffc34a02cc4..eaf34eedcb2bb 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -546,6 +546,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.BinutilsVersion = llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion); Options.UseInitArray = CodeGenOpts.UseInitArray; + Options.LowerGlobalDtorsViaCxaAtExit = + CodeGenOpts.RegisterGlobalDtorsWithAtExit; Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections(); Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; diff --git a/llvm/docs/Passes.rst b/llvm/docs/Passes.rst index 92f06496b4ef9..7c0666992e8f5 100644 --- a/llvm/docs/Passes.rst +++ b/llvm/docs/Passes.rst @@ -876,6 +876,14 @@ This pass expects :ref:`LICM ` to be run before it to hoist invariant conditions out of the loop, to make the unswitching opportunity obvious. +``-lower-global-dtors``: Lower global destructors + + +This pass lowers global module destructors (``llvm.global_dtors``) by creating +wrapper functions that are registered as global constructors in +``llvm.global_ctors`` and which contain a call to ``__cxa_atexit`` to register +their destructor functions. + ``-loweratomic``: Lower atomic intrinsics to non-atomic form diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index feb5de5415269..9281ed723854c 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -93,6 +93,8 @@ std::string getTrapFuncName(); bool getUseCtors(); +bool getLowerGlobalDtorsViaCxaAtExit(); + bool getRelaxELFRelocations(); bool getDataSections(); diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index 2a35987507446..26bda8d5d239d 100644 --- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -119,6 +119,9 @@ class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { void Initialize(MCContext &Ctx, const TargetMachine &TM) override; + MCSection *getStaticDtorSection(unsigned Priority, + const MCSymbol *KeySym) const override; + /// Emit the module flags that specify the garbage collection information. void emitModuleMetadata(MCStreamer &Streamer, Module
[clang] 46626bc - [NFC] Improve comment and rename test file
Author: Julian Lettner Date: 2022-03-11T14:47:54-08:00 New Revision: 46626bc87382cad7a0c5ba497b3454337c45faa8 URL: https://github.com/llvm/llvm-project/commit/46626bc87382cad7a0c5ba497b3454337c45faa8 DIFF: https://github.com/llvm/llvm-project/commit/46626bc87382cad7a0c5ba497b3454337c45faa8.diff LOG: [NFC] Improve comment and rename test file Added: clang/test/Driver/darwin-asan-destructor.c Modified: llvm/include/llvm/ADT/Triple.h Removed: clang/test/Driver/darwin-asan-mkernel-kext.c diff --git a/clang/test/Driver/darwin-asan-mkernel-kext.c b/clang/test/Driver/darwin-asan-destructor.c similarity index 100% rename from clang/test/Driver/darwin-asan-mkernel-kext.c rename to clang/test/Driver/darwin-asan-destructor.c diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index 14b66cbcc2129..a5f74df92209e 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -473,7 +473,7 @@ class Triple { bool isOSzOS() const { return getOS() == Triple::ZOS; } - /// Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS). + /// Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or DriverKit). bool isOSDarwin() const { return isMacOSX() || isiOS() || isWatchOS() || isDriverKit(); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9c542a5 - Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO
Author: Julian Lettner Date: 2022-03-14T17:51:18-07:00 New Revision: 9c542a5a4e1ba36c24e48185712779df52b7f7a6 URL: https://github.com/llvm/llvm-project/commit/9c542a5a4e1ba36c24e48185712779df52b7f7a6 DIFF: https://github.com/llvm/llvm-project/commit/9c542a5a4e1ba36c24e48185712779df52b7f7a6.diff LOG: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121327 Added: llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/docs/Passes.rst llvm/include/llvm/CodeGen/CommandFlags.h llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h llvm/include/llvm/InitializePasses.h llvm/include/llvm/LinkAllPasses.h llvm/include/llvm/Target/TargetOptions.h llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h llvm/include/llvm/Transforms/Utils.h llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/CodeGen/TargetPassConfig.cpp llvm/lib/Passes/PassBuilder.cpp llvm/lib/Passes/PassRegistry.def llvm/lib/Target/WebAssembly/CMakeLists.txt llvm/lib/Target/WebAssembly/WebAssembly.h llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp llvm/lib/Transforms/Utils/CMakeLists.txt llvm/test/CodeGen/ARM/ctors_dtors.ll llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll Removed: llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 490f5b3de1ff3..716a565ee7871 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -546,6 +546,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.BinutilsVersion = llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion); Options.UseInitArray = CodeGenOpts.UseInitArray; + Options.LowerGlobalDtorsViaCxaAtExit = + CodeGenOpts.RegisterGlobalDtorsWithAtExit; Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections(); Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; diff --git a/llvm/docs/Passes.rst b/llvm/docs/Passes.rst index 92f06496b4ef9..7c0666992e8f5 100644 --- a/llvm/docs/Passes.rst +++ b/llvm/docs/Passes.rst @@ -876,6 +876,14 @@ This pass expects :ref:`LICM ` to be run before it to hoist invariant conditions out of the loop, to make the unswitching opportunity obvious. +``-lower-global-dtors``: Lower global destructors + + +This pass lowers global module destructors (``llvm.global_dtors``) by creating +wrapper functions that are registered as global constructors in +``llvm.global_ctors`` and which contain a call to ``__cxa_atexit`` to register +their destructor functions. + ``-loweratomic``: Lower atomic intrinsics to non-atomic form diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index aa91367f65b80..4424db4aa2e41 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -95,6 +95,8 @@ std::string getTrapFuncName(); bool getUseCtors(); +bool getLowerGlobalDtorsViaCxaAtExit(); + bool getRelaxELFRelocations(); bool getDataSections(); diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index 2a35987507446..26bda8d5d239d 100644 --- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -119,6 +119,9 @@ class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { void Initialize(MCContext &Ctx, const TargetMachine &TM) override; + MCSection *getStaticDtorSection(unsigned Priority, + const MCSymbol *KeySym) const override; + /// Emit the module flags that specify the garbage collection information. void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override; diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 3a98bacef81d0..82aa
[clang] 22570ba - Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO
Author: Julian Lettner Date: 2022-03-17T10:47:13-07:00 New Revision: 22570bac694396514fff18dec926558951643fa6 URL: https://github.com/llvm/llvm-project/commit/22570bac694396514fff18dec926558951643fa6 DIFF: https://github.com/llvm/llvm-project/commit/22570bac694396514fff18dec926558951643fa6.diff LOG: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121736 Added: llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/docs/Passes.rst llvm/include/llvm/CodeGen/CommandFlags.h llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h llvm/include/llvm/InitializePasses.h llvm/include/llvm/LinkAllPasses.h llvm/include/llvm/Target/TargetOptions.h llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h llvm/include/llvm/Transforms/Utils.h llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/CodeGen/TargetPassConfig.cpp llvm/lib/Passes/PassBuilder.cpp llvm/lib/Passes/PassRegistry.def llvm/lib/Target/WebAssembly/CMakeLists.txt llvm/lib/Target/WebAssembly/WebAssembly.h llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp llvm/lib/Transforms/Utils/CMakeLists.txt llvm/lib/Transforms/Utils/Utils.cpp llvm/test/CodeGen/ARM/ctors_dtors.ll llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll Removed: llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 490f5b3de1ff3..716a565ee7871 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -546,6 +546,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.BinutilsVersion = llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion); Options.UseInitArray = CodeGenOpts.UseInitArray; + Options.LowerGlobalDtorsViaCxaAtExit = + CodeGenOpts.RegisterGlobalDtorsWithAtExit; Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections(); Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; diff --git a/llvm/docs/Passes.rst b/llvm/docs/Passes.rst index 92f06496b4ef9..7c0666992e8f5 100644 --- a/llvm/docs/Passes.rst +++ b/llvm/docs/Passes.rst @@ -876,6 +876,14 @@ This pass expects :ref:`LICM ` to be run before it to hoist invariant conditions out of the loop, to make the unswitching opportunity obvious. +``-lower-global-dtors``: Lower global destructors + + +This pass lowers global module destructors (``llvm.global_dtors``) by creating +wrapper functions that are registered as global constructors in +``llvm.global_ctors`` and which contain a call to ``__cxa_atexit`` to register +their destructor functions. + ``-loweratomic``: Lower atomic intrinsics to non-atomic form diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index feb5de5415269..9281ed723854c 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -93,6 +93,8 @@ std::string getTrapFuncName(); bool getUseCtors(); +bool getLowerGlobalDtorsViaCxaAtExit(); + bool getRelaxELFRelocations(); bool getDataSections(); diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index 2a35987507446..26bda8d5d239d 100644 --- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -119,6 +119,9 @@ class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { void Initialize(MCContext &Ctx, const TargetMachine &TM) override; + MCSection *getStaticDtorSection(unsigned Priority, + const MCSymbol *KeySym) const override; + /// Emit the module flags that specify the garbage collection information. void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override; diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/Init
[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)
https://github.com/yln edited https://github.com/llvm/llvm-project/pull/86220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)
@@ -346,20 +347,7 @@ endif () # Determine HOST_LINK_VERSION on Darwin. set(HOST_LINK_VERSION) if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*") - set(LD_V_OUTPUT) - execute_process( -COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1" -RESULT_VARIABLE HAD_ERROR -OUTPUT_VARIABLE LD_V_OUTPUT - ) - if (HAD_ERROR) -message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") - endif() - if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*") -string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) - elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*") -string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) - endif() + get_darwin_linker_version() yln wrote: - [ ] Would it be possible to "declare" where the value is stored, i.e., a CMAKE output parameter? So the relationship between `HOST_LINK_VERSION` and `get_darwin_linker_version()` is explicit (and other variable names can be used)? ```suggestion get_darwin_linker_version(HOST_LINK_VERSION) ``` https://github.com/llvm/llvm-project/pull/86220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)
@@ -444,6 +445,15 @@ else() set(SANITIZER_USE_SYMBOLS FALSE) endif() +# Get the linker version while configuring compiler-rt and explicitly pass it +# in cflags during testing. This fixes the compiler/linker version mismatch +# issue when running a clang built with a newer Xcode in an older Xcode +set(HOST_LINK_VERSION) yln wrote: - [ ] How about `DARWIN_LINKER_VERSION`? https://github.com/llvm/llvm-project/pull/86220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)
@@ -51,6 +51,7 @@ set_default("expensive_checks", @LLVM_ENABLE_EXPENSIVE_CHECKS_PYBOOL@) set_default("test_standalone_build_libs", @COMPILER_RT_TEST_STANDALONE_BUILD_LIBS_PYBOOL@) set_default("has_compiler_rt_libatomic", @COMPILER_RT_BUILD_STANDALONE_LIBATOMIC_PYBOOL@) set_default("aarch64_sme", @COMPILER_RT_HAS_AARCH64_SME_PYBOOL@) +set_default("host_link_version", "@HOST_LINK_VERSION@") yln wrote: - [ ] Many of the other vars here have a `COMPILER_RT` prefix. Should we do the same or does it imply some additional semantics ("user option" in CMAKE script)? - [ ] `set_default("darwin_linker_version", "@COMPILER_RT_DARWIN_LINKER_VERSION@")` https://github.com/llvm/llvm-project/pull/86220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)
@@ -15,6 +15,7 @@ endif() # Must go below project(..) include(GNUInstallDirs) +include(GetDarwinLinkerVersion) yln wrote: Thanks for extracting this into a separate file! 👍 https://github.com/llvm/llvm-project/pull/86220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)
https://github.com/yln approved this pull request. Thanks, approved with a few nits! https://github.com/llvm/llvm-project/pull/86220 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 478eb98 - [Docs] Remove outdated OS limitation
Author: Julian Lettner Date: 2020-09-01T14:44:17-07:00 New Revision: 478eb98cd25cb0ebc01fc2c3889ae94d3f1797d3 URL: https://github.com/llvm/llvm-project/commit/478eb98cd25cb0ebc01fc2c3889ae94d3f1797d3 DIFF: https://github.com/llvm/llvm-project/commit/478eb98cd25cb0ebc01fc2c3889ae94d3f1797d3.diff LOG: [Docs] Remove outdated OS limitation Thread Sanitizer is supported on macOS. rdar://68159753 Differential Revision: https://reviews.llvm.org/D86980 Added: Modified: clang/docs/UsersManual.rst Removed: diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 19009b43a9e8..1a1aea2ae538 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -3227,11 +3227,6 @@ backend. Operating System Features and Limitations - -Darwin (macOS) -^^ - -Thread Sanitizer is not supported. - Windows ^^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dc32ed8 - [Clang][Driver] Refine/refactor DriverKit support
Author: Julian Lettner Date: 2022-08-26T16:06:24-07:00 New Revision: dc32ed8a8e226db3677abb19eda62cfe80572aed URL: https://github.com/llvm/llvm-project/commit/dc32ed8a8e226db3677abb19eda62cfe80572aed DIFF: https://github.com/llvm/llvm-project/commit/dc32ed8a8e226db3677abb19eda62cfe80572aed.diff LOG: [Clang][Driver] Refine/refactor DriverKit support Add special Framework header search path for DriverKit. Added: clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/System/Library/Frameworks/.keep clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/usr/lib/.keep clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/usr/local/include/.keep clang/test/Driver/driverkit-path.c Modified: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/Darwin.h clang/lib/Lex/InitHeaderSearch.cpp Removed: diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index f444cf5cbb109..59d8dafc079f0 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -258,6 +258,10 @@ class ToolChain { return EffectiveTriple; } + bool hasEffectiveTriple() const { +return !EffectiveTriple.getTriple().empty(); + } + path_list &getLibraryPaths() { return LibraryPaths; } const path_list &getLibraryPaths() const { return LibraryPaths; } diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4482a55a05019..b060a6af6145b 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -522,6 +522,8 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, } } +static void AppendPlatformPrefix(SmallString<128> &Path, const llvm::Triple &T); + void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, @@ -719,22 +721,31 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, } } - // DriverKit's framework doesn't have the same layout as other frameworks. - // Add missing search paths if necessary. - if (getToolChain().getTriple().getOS() == llvm::Triple::DriverKit) { -if (const Arg *Root = Args.getLastArg(options::OPT_isysroot)) { + // Add non-standard, platform-specific search paths, e.g., for DriverKit: + // -L/System/DriverKit/usr/lib + // -F/System/DriverKit/System/Library/Framework + { +bool NonStandardSearchPath = false; +const auto &Triple = getToolChain().getTriple(); +if (Triple.isDriverKit()) { // ld64 fixed the implicit -F and -L paths in ld64-605.1+. - if (Version.getMajor() < 605 || - (Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1)) { - -SmallString<128> L(Root->getValue()); -llvm::sys::path::append(L, "System", "DriverKit", "usr", "lib"); -CmdArgs.push_back(Args.MakeArgString(std::string("-L") + L)); + NonStandardSearchPath = + Version.getMajor() < 605 || + (Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1); +} -SmallString<128> F(Root->getValue()); -llvm::sys::path::append(F, "System", "DriverKit"); -llvm::sys::path::append(F, "System", "Library", "Frameworks"); -CmdArgs.push_back(Args.MakeArgString(std::string("-F") + F)); +if (NonStandardSearchPath) { + if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) { +auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) { + SmallString<128> P(Sysroot->getValue()); + AppendPlatformPrefix(P, Triple); + llvm::sys::path::append(P, SearchPath); + if (getToolChain().getVFS().exists(P)) { +CmdArgs.push_back(Args.MakeArgString(Flag + P)); + } +}; +AddSearchPath("-L", "/usr/lib"); +AddSearchPath("-F", "/System/Library/Frameworks"); } } } @@ -2265,21 +2276,37 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { } } -// Returns the effective header sysroot path to use. This comes either from -// -isysroot or --sysroot. -llvm::StringRef DarwinClang::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const { - if(DriverArgs.hasArg(options::OPT_isysroot)) -return DriverArgs.getLastArgValue(options::OPT_isysroot); - if (!getDriver().SysRoot.empty()) -return getDriver().SysRoot; - return "/"; +// For certain platforms/environments almost all resources (e.g., headers) are +// located in sub-directories, e.g., for DriverKit they live in +// /System/DriverKit/usr/include (instead of /usr/include). +static void AppendPlatformPrefix(SmallString<128> &Path, + const llvm::Triple &T)
[clang] 5284cf0 - [Clang][Driver] Temporarily disable failing DriverKit test
Author: Julian Lettner Date: 2022-08-26T18:32:51-07:00 New Revision: 5284cf0098c150137983d9e6326fc1ac014428a6 URL: https://github.com/llvm/llvm-project/commit/5284cf0098c150137983d9e6326fc1ac014428a6 DIFF: https://github.com/llvm/llvm-project/commit/5284cf0098c150137983d9e6326fc1ac014428a6.diff LOG: [Clang][Driver] Temporarily disable failing DriverKit test Added: Modified: clang/test/Driver/driverkit-path.c Removed: diff --git a/clang/test/Driver/driverkit-path.c b/clang/test/Driver/driverkit-path.c index 755cb228e7ed6..0aa3e958b2908 100644 --- a/clang/test/Driver/driverkit-path.c +++ b/clang/test/Driver/driverkit-path.c @@ -1,4 +1,7 @@ // REQUIRES: x86-registered-target +// REQUIRES: darwin +// FIXME: Breaks on non-macOS: +//http://45.33.8.238/linux/85125/step_7.txt // RUN: %clang %s -target x86_64-apple-driverkit19.0 -mlinker-version=0 \ // RUN: -isysroot %S/Inputs/DriverKit19.0.sdk -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=LD64-OLD ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e6a789e - Remove -lower-global-dtors-via-cxa-atexit flag
Author: Julian Lettner Date: 2023-03-14T14:18:11-07:00 New Revision: e6a789ef9bb28222c91816a2cf00cfd6f706efd4 URL: https://github.com/llvm/llvm-project/commit/e6a789ef9bb28222c91816a2cf00cfd6f706efd4 DIFF: https://github.com/llvm/llvm-project/commit/e6a789ef9bb28222c91816a2cf00cfd6f706efd4.diff LOG: Remove -lower-global-dtors-via-cxa-atexit flag Remove the `-lower-global-dtors-via-cxa-atexit` escape hatch introduced in D121736 [1], which switched the default lowering of global destructors on MachO to use `__cxa_atexit()` to avoid emitting deprecated `__mod_term_func` sections. I added this flag as an escape hatch in case the switch causes any problems. We didn't discover any problems so now we can remove it. [1] https://reviews.llvm.org/D121736 rdar://90277838 Differential Revision: https://reviews.llvm.org/D145715 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/CodeGen/CommandFlags.h llvm/include/llvm/Target/TargetOptions.h llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/CodeGen/TargetPassConfig.cpp llvm/test/CodeGen/ARM/ctors_dtors.ll Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4a5d3f8199682..06e4cd23db7a4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -132,6 +132,9 @@ Removed Compiler Flags or higher to use standard C++ modules instead. - The deprecated flag `-fcoroutines-ts` is removed. Please use ``-std=c++20`` or higher to use standard C++ coroutines instead. +- The CodeGen flag `-lower-global-dtors-via-cxa-atexit` which affects how global + destructors are lowered for MachO is removed without replacement. The default + of `-lower-global-dtors-via-cxa-atexit=true` is now the only supported way. Attribute Changes in Clang -- diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b03d326dd0654..fffaeb8a6ff79 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -367,8 +367,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.BinutilsVersion = llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion); Options.UseInitArray = CodeGenOpts.UseInitArray; - Options.LowerGlobalDtorsViaCxaAtExit = - CodeGenOpts.RegisterGlobalDtorsWithAtExit; Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections(); Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations; diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index 7b1ef60912f1a..475d87bdd5b13 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -94,8 +94,6 @@ std::string getTrapFuncName(); bool getUseCtors(); -bool getLowerGlobalDtorsViaCxaAtExit(); - bool getRelaxELFRelocations(); bool getDataSections(); diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index d8a4159189394..22e811653c6d4 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -130,7 +130,7 @@ namespace llvm { HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false), GuaranteedTailCallOpt(false), StackSymbolOrdering(true), EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), - LowerGlobalDtorsViaCxaAtExit(false), DisableIntegratedAS(false), + DisableIntegratedAS(false), RelaxELFRelocations(true), FunctionSections(false), DataSections(false), IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true), UniqueSectionNames(true), @@ -247,10 +247,6 @@ namespace llvm { /// constructors. unsigned UseInitArray : 1; -/// Use __cxa_atexit to register global destructors; determines how -/// llvm.global_dtors is lowered. -unsigned LowerGlobalDtorsViaCxaAtExit : 1; - /// Disable the integrated assembler. unsigned DisableIntegratedAS : 1; diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp index 73521ac46df45..51d259cea41b8 100644 --- a/llvm/lib/CodeGen/CommandFlags.cpp +++ b/llvm/lib/CodeGen/CommandFlags.cpp @@ -81,7 +81,6 @@ CGOPT(bool, StackSymbolOrdering) CGOPT(bool, StackRealign) CGOPT(std::string, TrapFuncName) CGOPT(bool, UseCtors) -CGOPT(bool, LowerGlobalDtorsViaCxaAtExit) CGOPT(bool, RelaxELFRelocations) CGOPT_EXP(bool, DataSections) CGOPT_EXP(bool, FunctionSections) @@ -349,12 +348,6 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() { cl::init(false)); CGBINDOPT(UseCtors); - static cl::opt LowerGlobalDtorsViaCxaAtExit( -
[clang] c3f0153 - [MachO] Disable atexit()-based lowering when LTO'ing kernel/kext code
Author: Julian Lettner Date: 2023-04-25T12:13:40-07:00 New Revision: c3f0153ec27a5e2cff97179d319ab99651c4c539 URL: https://github.com/llvm/llvm-project/commit/c3f0153ec27a5e2cff97179d319ab99651c4c539 DIFF: https://github.com/llvm/llvm-project/commit/c3f0153ec27a5e2cff97179d319ab99651c4c539.diff LOG: [MachO] Disable atexit()-based lowering when LTO'ing kernel/kext code The kernel and kext environments do not provide the `__cxa_atexit()` function, so we can't use it for lowering global module destructors. Unfortunately, just querying for "compiling for kernel/kext?" in the LTO pipeline isn't possible (kernel/kext identifier isn't part of the triple yet) so we need to pass down a CodeGen flag. rdar://93536111 Differential Revision: https://reviews.llvm.org/D148967 Added: Modified: clang/lib/Driver/ToolChains/Darwin.cpp clang/test/Driver/darwin-ld-lto.c llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/CodeGen/TargetPassConfig.cpp llvm/test/CodeGen/ARM/ctors_dtors.ll Removed: diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 11e65358bec05..35b30e6044411 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -393,6 +393,13 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args, } } + if (Args.hasArg(options::OPT_mkernel) || + Args.hasArg(options::OPT_fapple_kext) || + Args.hasArg(options::OPT_ffreestanding)) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back("-disable-atexit-based-global-dtor-lowering"); + } + Args.AddLastArg(CmdArgs, options::OPT_prebind); Args.AddLastArg(CmdArgs, options::OPT_noprebind); Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); diff --git a/clang/test/Driver/darwin-ld-lto.c b/clang/test/Driver/darwin-ld-lto.c index efa28b6746fac..2e049769b0cd4 100644 --- a/clang/test/Driver/darwin-ld-lto.c +++ b/clang/test/Driver/darwin-ld-lto.c @@ -40,3 +40,11 @@ // GISEL: {{ld(.exe)?"}} // GISEL: "-mllvm" "-global-isel" // GISEL: "-mllvm" "-global-isel-abort=0" + + +// Check that we disable atexit()-based global destructor lowering when +// compiling/linking for kernel/kext/freestanding. +// RUN: %clang -target arm64-apple-darwin %s -flto -fapple-kext -### 2>&1 | \ +// RUN: FileCheck --check-prefix=KEXT %s +// KEXT: {{ld(.exe)?"}} +// KEXT: "-mllvm" "-disable-atexit-based-global-dtor-lowering" diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index c81b6bb623b96..db1a4369e1291 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1202,7 +1202,12 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, MCSection *TargetLoweringObjectFileMachO::getStaticDtorSection( unsigned Priority, const MCSymbol *KeySym) const { - report_fatal_error("@llvm.global_dtors should have been lowered already"); + return StaticDtorSection; + // In userspace, we lower global destructors via atexit(), but kernel/kext + // environments do not provide this function so we still need to support the + // legacy way here. + // See the -disable-atexit-based-global-dtor-lowering CodeGen flag for more + // context. } void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer, diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index 32fa6cc17d53f..86490c0d6417d 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -100,6 +100,9 @@ static cl::opt DisableCopyProp("disable-copyprop", cl::Hidden, cl::desc("Disable Copy Propagation pass")); static cl::opt DisablePartialLibcallInlining("disable-partial-libcall-inlining", cl::Hidden, cl::desc("Disable Partial Libcall Inlining")); +static cl::opt DisableAtExitBasedGlobalDtorLowering( +"disable-atexit-based-global-dtor-lowering", cl::Hidden, +cl::desc("For MachO, disable atexit()-based global destructor lowering")); static cl::opt EnableImplicitNullChecks( "enable-implicit-null-checks", cl::desc("Fold null checks into faulting memory operations"), @@ -878,7 +881,8 @@ void TargetPassConfig::addIRPasses() { // For MachO, lower @llvm.global_dtors into @llvm.global_ctors with // __cxa_atexit() calls to avoid emitting the deprecated __mod_term_func. - if (TM->getTargetTriple().isOSBinFormatMachO()) + if (TM->getTargetTriple().isOSBinFormatMachO() && + !DisableAtExitBasedGlobalDtorLowering) addPass(createLowerGlobalDtorsLegacyPass()); // Make sure that no unreachable blocks are instruction selected. diff --git a/llvm/test/CodeGen/ARM/ctors_dtors.ll b/llvm/test/CodeGen/ARM/ctors_dtors.ll index 066c250ca1448..f3d65ee982b58 100644 --- a/llvm/test/CodeGen/ARM/ctors_dtors.ll +++ b
[clang] [llvm] [SanitizerCoverage] Add an option to gate the invocation of the tracing callbacks (PR #108328)
https://github.com/yln approved this pull request. LGTM, looks harmless enough. Please ping again for review and wait a few more days before merging to give other reviewers another chance to chime in. In the follow-up PR that expands support for this to trace-cmp, does it make sense to document this option here [SanitizerCoverage](https://clang.llvm.org/docs/SanitizerCoverage.html)? https://github.com/llvm/llvm-project/pull/108328 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits