[compiler-rt] [clang] [hwasan] Separate sections in report (PR #76130)
fmayer wrote: LGTM. Could you explain in the description why we are doing this? https://github.com/llvm/llvm-project/pull/76130 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [hwasan] Separate sections in report (PR #76130)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/76130 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [lldb] [mlir] [libc] [compiler-rt] [flang] [clang] [openmp] [hwasan] Respect strip_path_prefix printing locals (PR #76132)
https://github.com/fmayer approved this pull request. Lgtm thanks https://github.com/llvm/llvm-project/pull/76132 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [libcxx] [lldb] [flang] [openmp] [mlir] [libc] [compiler-rt] [hwasan] Classify stack overflow, and use after scope (PR #76133)
@@ -221,29 +221,55 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa, for (LocalInfo &local : frame.locals) { if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset) continue; +if (!(local.name && internal_strlen(local.name)) && +!(local.function_name && internal_strlen(local.name)) && +!(local.decl_file && internal_strlen(local.decl_file))) + continue; tag_t obj_tag = base_tag ^ local.tag_offset; if (obj_tag != addr_tag) continue; -// Calculate the offset from the object address to the faulting -// address. Because we only store bits 4-19 of FP (bits 0-3 are -// guaranteed to be zero), the calculation is performed mod 2^20 and may -// harmlessly underflow if the address mod 2^20 is below the object -// address. -uptr obj_offset = -(untagged_addr - fp - local.frame_offset) & (kRecordFPModulus - 1); -if (obj_offset >= local.size) - continue; +uptr local_beg = (fp + local.frame_offset) | + (untagged_addr & ~(uptr(kRecordFPModulus) - 1)); +uptr local_end = local_beg + local.size; + if (!found_local) { Printf("\nPotentially referenced stack objects:\n"); found_local = true; } + +uptr offset; +const char *whence; +const char *cause; +if (local_beg <= untagged_addr && untagged_addr < local_end) { + offset = untagged_addr - local_beg; + whence = "inside"; + cause = "use-after-scope"; +} else if (untagged_addr >= local_end) { + offset = untagged_addr - local_end; + whence = "after"; + cause = "stack-buffer-overflow"; +} else { + offset = local_beg - untagged_addr; + whence = "before"; + cause = "stack-buffer-overflow"; +} +Decorator d; +Printf("%s", d.Error()); +Printf("Cause: %s\n", cause); +Printf("%s", d.Default()); +Printf("%s", d.Location()); +Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n", + untagged_addr, offset, whence, local_end - local_beg, local_beg, + local_end); +Printf("%s", d.Allocation()); StackTracePrinter::GetOrInit()->RenderSourceLocation( fmayer wrote: FYI the offline symbolizer has this output format ``` self.print('') self.print('Potentially referenced stack object:') self.print(' %d bytes inside a variable "%s" in stack frame of function "%s"' % (obj_offset, local[2], local[0])) self.print(' at %s' % (local[1],)) ``` https://github.com/llvm/llvm-project/pull/76133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [openmp] [libc] [compiler-rt] [lldb] [mlir] [flang] [libcxx] [clang] [hwasan] Classify stack overflow, and use after scope (PR #76133)
@@ -221,29 +221,55 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa, for (LocalInfo &local : frame.locals) { if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset) continue; +if (!(local.name && internal_strlen(local.name)) && +!(local.function_name && internal_strlen(local.name)) && +!(local.decl_file && internal_strlen(local.decl_file))) + continue; tag_t obj_tag = base_tag ^ local.tag_offset; if (obj_tag != addr_tag) continue; -// Calculate the offset from the object address to the faulting -// address. Because we only store bits 4-19 of FP (bits 0-3 are -// guaranteed to be zero), the calculation is performed mod 2^20 and may -// harmlessly underflow if the address mod 2^20 is below the object -// address. -uptr obj_offset = -(untagged_addr - fp - local.frame_offset) & (kRecordFPModulus - 1); -if (obj_offset >= local.size) - continue; +uptr local_beg = (fp + local.frame_offset) | fmayer wrote: I am confused by this. Could you add a comment as on the LHS? Why isn't the `local_beg` not just `fp + local.frame_offset`? https://github.com/llvm/llvm-project/pull/76133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [openmp] [libc] [compiler-rt] [lldb] [mlir] [flang] [libcxx] [clang] [hwasan] Classify stack overflow, and use after scope (PR #76133)
https://github.com/fmayer commented: Remove this comment? Line 780 ``` // TODO(fmayer): figure out how to distinguish use-after-return and // stack-buffer-overflow. ``` https://github.com/llvm/llvm-project/pull/76133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libc] [clang] [openmp] [flang] [libcxx] [llvm] [compiler-rt] [lldb] [mlir] [hwasan] Classify stack overflow, and use after scope (PR #76133)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/76133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [libcxx] [lld] [flang] [compiler-rt] [libc] [clang-tools-extra] [clang] [hwasan] Workaround unsupported AssignmentTrackingPass (PR #76547)
https://github.com/fmayer approved this pull request. LGTM, but maybe be more explicit in the commit message how we work around this. https://github.com/llvm/llvm-project/pull/76547 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] fc6a6ee - [libunwind] undef NDEBUG for assert.h in tests.
Author: Florian Mayer Date: 2022-08-04T19:55:40-07:00 New Revision: fc6a6ee507ec2df0df7d34ba19feccb776297e4c URL: https://github.com/llvm/llvm-project/commit/fc6a6ee507ec2df0df7d34ba19feccb776297e4c DIFF: https://github.com/llvm/llvm-project/commit/fc6a6ee507ec2df0df7d34ba19feccb776297e4c.diff LOG: [libunwind] undef NDEBUG for assert.h in tests. This makes sure the assertions also get verified in optimized builds. This matches what is already done in bad_unwind_info.pass.cpp. Reviewed By: #libunwind, MaskRay Differential Revision: https://reviews.llvm.org/D131210 Added: Modified: libunwind/test/forceunwind.pass.cpp libunwind/test/libunwind_02.pass.cpp libunwind/test/signal_frame.pass.cpp libunwind/test/signal_unwind.pass.cpp libunwind/test/unw_getcontext.pass.cpp libunwind/test/unwind_leaffunction.pass.cpp Removed: diff --git a/libunwind/test/forceunwind.pass.cpp b/libunwind/test/forceunwind.pass.cpp index af5f234b8da68..8c26551b6d0b6 100644 --- a/libunwind/test/forceunwind.pass.cpp +++ b/libunwind/test/forceunwind.pass.cpp @@ -15,6 +15,7 @@ // Basic test for _Unwind_ForcedUnwind. // See libcxxabi/test/forced_unwind* tests too. +#undef NDEBUG #include #include #include diff --git a/libunwind/test/libunwind_02.pass.cpp b/libunwind/test/libunwind_02.pass.cpp index c0d6b05c2a729..fc034378781a2 100644 --- a/libunwind/test/libunwind_02.pass.cpp +++ b/libunwind/test/libunwind_02.pass.cpp @@ -10,6 +10,7 @@ // TODO: Figure out why this fails with Memory Sanitizer. // XFAIL: msan +#undef NDEBUG #include #include #include diff --git a/libunwind/test/signal_frame.pass.cpp b/libunwind/test/signal_frame.pass.cpp index b17804efa08c8..482481d9d96ba 100644 --- a/libunwind/test/signal_frame.pass.cpp +++ b/libunwind/test/signal_frame.pass.cpp @@ -21,6 +21,7 @@ // are necessary to run this test. // UNSUPPORTED: target=powerpc{{(64)?}}-ibm-aix +#undef NDEBUG #include #include #include diff --git a/libunwind/test/signal_unwind.pass.cpp b/libunwind/test/signal_unwind.pass.cpp index 2ff50abbebb67..e6a53ab9ff952 100644 --- a/libunwind/test/signal_unwind.pass.cpp +++ b/libunwind/test/signal_unwind.pass.cpp @@ -13,6 +13,7 @@ // TODO: Figure out why this fails with Memory Sanitizer. // XFAIL: msan +#undef NDEBUG #include #include #include diff --git a/libunwind/test/unw_getcontext.pass.cpp b/libunwind/test/unw_getcontext.pass.cpp index 7e2735e418be7..95ffcf123267f 100644 --- a/libunwind/test/unw_getcontext.pass.cpp +++ b/libunwind/test/unw_getcontext.pass.cpp @@ -7,6 +7,7 @@ // //===--===// +#undef NDEBUG #include #include diff --git a/libunwind/test/unwind_leaffunction.pass.cpp b/libunwind/test/unwind_leaffunction.pass.cpp index f363dfe4a29d5..31c2254bcc7ee 100644 --- a/libunwind/test/unwind_leaffunction.pass.cpp +++ b/libunwind/test/unwind_leaffunction.pass.cpp @@ -13,6 +13,7 @@ // TODO: Figure out why this fails with Memory Sanitizer. // XFAIL: msan +#undef NDEBUG #include #include #include ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 12268fe - [hwasan] Use stack safety analysis.
Author: Florian Mayer Date: 2021-07-19T11:54:44+01:00 New Revision: 12268fe14a1a65d4b62f0b6e5beab46ba8501ae7 URL: https://github.com/llvm/llvm-project/commit/12268fe14a1a65d4b62f0b6e5beab46ba8501ae7 DIFF: https://github.com/llvm/llvm-project/commit/12268fe14a1a65d4b62f0b6e5beab46ba8501ae7.diff LOG: [hwasan] Use stack safety analysis. This avoids unnecessary instrumentation. Reviewed By: eugenis, vitalybuka Differential Revision: https://reviews.llvm.org/D105703 Added: clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c clang/test/CodeGen/hwasan-stack-safety-analysis.c llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp Removed: diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 9aa67ed2a67ba..481f5347d978b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -314,14 +314,19 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PM.add( - createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover)); + PM.add(createHWAddressSanitizerLegacyPassPass( + /*CompileKernel*/ false, Recover, + /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); } static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, -legacy::PassManagerBase &PM) { + legacy::PassManagerBase &PM) { + const PassManagerBuilderWrapper &BuilderWrapper = + static_cast(Builder); + const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ true, /*Recover*/ true)); + /*CompileKernel*/ true, /*Recover*/ true, + /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); } static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, @@ -1164,7 +1169,9 @@ static void addSanitizers(const Triple &TargetTriple, auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); -MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover)); +MPM.addPass(HWAddressSanitizerPass( +CompileKernel, Recover, +/*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0)); } }; HWASanPass(SanitizerKind::HWAddress, false); diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c b/clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c new file mode 100644 index 0..f323a968bcf8e --- /dev/null +++ b/clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c @@ -0,0 +1,15 @@ +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +// Default when optimizing, but not with O0. +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-generate-tags-with-calls -O0 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +int main(int argc, char **argv) { + char buf[10]; + volatile char *x = buf; + *x = 0; + return buf[0]; + // NOSAFETY: __hwasan_generate_tag + // SAFETY-NOT: __hwasan_generate_tag +} diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c new file mode 100644 index 0..5c4f34027bacd --- /dev/null +++ b/clang/test/CodeGen/hwasan-stack-safety-analysis.c @@ -0,0 +1,15 @@ +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +// Default when optimizing, but not with O0. +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix
[clang] 807d501 - Revert "[hwasan] Use stack safety analysis."
Author: Florian Mayer Date: 2021-07-19T12:08:32+01:00 New Revision: 807d50100c3c6cd5e6ec89d6ac1afddd0c3f7133 URL: https://github.com/llvm/llvm-project/commit/807d50100c3c6cd5e6ec89d6ac1afddd0c3f7133 DIFF: https://github.com/llvm/llvm-project/commit/807d50100c3c6cd5e6ec89d6ac1afddd0c3f7133.diff LOG: Revert "[hwasan] Use stack safety analysis." This reverts commit 12268fe14a1a65d4b62f0b6e5beab46ba8501ae7. Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp Removed: clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c clang/test/CodeGen/hwasan-stack-safety-analysis.c llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 481f5347d978b..9aa67ed2a67ba 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -314,19 +314,14 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ false, Recover, - /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); + PM.add( + createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover)); } static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, - legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); - const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); +legacy::PassManagerBase &PM) { PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ true, /*Recover*/ true, - /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); + /*CompileKernel*/ true, /*Recover*/ true)); } static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, @@ -1169,9 +1164,7 @@ static void addSanitizers(const Triple &TargetTriple, auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); -MPM.addPass(HWAddressSanitizerPass( -CompileKernel, Recover, -/*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0)); +MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover)); } }; HWASanPass(SanitizerKind::HWAddress, false); diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c b/clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c deleted file mode 100644 index f323a968bcf8e..0 --- a/clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -// Default when optimizing, but not with O0. -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -mllvm -hwasan-generate-tags-with-calls -O0 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -int main(int argc, char **argv) { - char buf[10]; - volatile char *x = buf; - *x = 0; - return buf[0]; - // NOSAFETY: __hwasan_generate_tag - // SAFETY-NOT: __hwasan_generate_tag -} diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c deleted file mode 100644 index 5c4f34027bacd..0 --- a/clang/test/CodeGen/hwasan-stack-safety-analysis.c +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -// Default when optimizing, but not with O0. -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target
[clang] e9c63ed - [hwasan] Use stack safety analysis.
Author: Florian Mayer Date: 2021-07-20T10:06:35+01:00 New Revision: e9c63ed10b3bdf6eb3fa76d1a3eb403d6fc6a118 URL: https://github.com/llvm/llvm-project/commit/e9c63ed10b3bdf6eb3fa76d1a3eb403d6fc6a118 DIFF: https://github.com/llvm/llvm-project/commit/e9c63ed10b3bdf6eb3fa76d1a3eb403d6fc6a118.diff LOG: [hwasan] Use stack safety analysis. This avoids unnecessary instrumentation. Reviewed By: eugenis, vitalybuka Differential Revision: https://reviews.llvm.org/D105703 Added: clang/test/CodeGen/hwasan-stack-safety-analysis.c llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp Removed: diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 9aa67ed2a67ba..481f5347d978b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -314,14 +314,19 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PM.add( - createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover)); + PM.add(createHWAddressSanitizerLegacyPassPass( + /*CompileKernel*/ false, Recover, + /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); } static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, -legacy::PassManagerBase &PM) { + legacy::PassManagerBase &PM) { + const PassManagerBuilderWrapper &BuilderWrapper = + static_cast(Builder); + const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ true, /*Recover*/ true)); + /*CompileKernel*/ true, /*Recover*/ true, + /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); } static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, @@ -1164,7 +1169,9 @@ static void addSanitizers(const Triple &TargetTriple, auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); -MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover)); +MPM.addPass(HWAddressSanitizerPass( +CompileKernel, Recover, +/*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0)); } }; HWASanPass(SanitizerKind::HWAddress, false); diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c new file mode 100644 index 0..5c4f34027bacd --- /dev/null +++ b/clang/test/CodeGen/hwasan-stack-safety-analysis.c @@ -0,0 +1,15 @@ +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +// Default when optimizing, but not with O0. +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O0 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +int main(int argc, char **argv) { + char buf[10]; + volatile char *x = buf; + *x = 0; + return buf[0]; + // NOSAFETY: __hwasan_generate_tag + // SAFETY-NOT: __hwasan_generate_tag +} diff --git a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h index 76e02f06435c3..2e4f3338030a4 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h @@ -25,17 +25,21 @@ namespace llvm { class HWAddressSanitizerPass : public PassInfoMixin { public: explicit HWAddressSanitizerPass(bool CompileKernel = false, - bool Recover = false); + bool Recover = false, + bool DisableOptimization = false); PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); static bool isRequired() { return true; } private: bool CompileKernel; bool Recover; + bool DisableOptimization; }; -FunctionPass *createHWAdd
[clang] 5f08219 - Revert "[hwasan] Use stack safety analysis."
Author: Florian Mayer Date: 2021-07-20T10:36:46+01:00 New Revision: 5f08219322456b867605e4a19003f58ee418758f URL: https://github.com/llvm/llvm-project/commit/5f08219322456b867605e4a19003f58ee418758f DIFF: https://github.com/llvm/llvm-project/commit/5f08219322456b867605e4a19003f58ee418758f.diff LOG: Revert "[hwasan] Use stack safety analysis." This reverts commit e9c63ed10b3bdf6eb3fa76d1a3eb403d6fc6a118. Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp Removed: clang/test/CodeGen/hwasan-stack-safety-analysis.c llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 481f5347d978b..9aa67ed2a67ba 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -314,19 +314,14 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ false, Recover, - /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); + PM.add( + createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover)); } static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, - legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); - const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); +legacy::PassManagerBase &PM) { PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ true, /*Recover*/ true, - /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); + /*CompileKernel*/ true, /*Recover*/ true)); } static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, @@ -1169,9 +1164,7 @@ static void addSanitizers(const Triple &TargetTriple, auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); -MPM.addPass(HWAddressSanitizerPass( -CompileKernel, Recover, -/*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0)); +MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover)); } }; HWASanPass(SanitizerKind::HWAddress, false); diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c deleted file mode 100644 index 5c4f34027bacd..0 --- a/clang/test/CodeGen/hwasan-stack-safety-analysis.c +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -// Default when optimizing, but not with O0. -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O0 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -int main(int argc, char **argv) { - char buf[10]; - volatile char *x = buf; - *x = 0; - return buf[0]; - // NOSAFETY: __hwasan_generate_tag - // SAFETY-NOT: __hwasan_generate_tag -} diff --git a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h index 2e4f3338030a4..76e02f06435c3 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h @@ -25,21 +25,17 @@ namespace llvm { class HWAddressSanitizerPass : public PassInfoMixin { public: explicit HWAddressSanitizerPass(bool CompileKernel = false, - bool Recover = false, - bool DisableOptimization = false); + bool Recover = false); PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); static bool isRequired() { return true; } private: bool CompileKernel; bool Recover; - bool DisableOptimization; }; -FunctionPass * -createHWAddressSanitizerLegacyPassPass(bool CompileKernel = false,
[clang] bde9415 - [hwasan] Use stack safety analysis.
Author: Florian Mayer Date: 2021-07-22T12:04:54+01:00 New Revision: bde9415fef25e9ff6e10595a2f4f5004dd62f10a URL: https://github.com/llvm/llvm-project/commit/bde9415fef25e9ff6e10595a2f4f5004dd62f10a DIFF: https://github.com/llvm/llvm-project/commit/bde9415fef25e9ff6e10595a2f4f5004dd62f10a.diff LOG: [hwasan] Use stack safety analysis. This avoids unnecessary instrumentation. Reviewed By: eugenis, vitalybuka Differential Revision: https://reviews.llvm.org/D105703 Added: clang/test/CodeGen/hwasan-stack-safety-analysis.c llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp Removed: diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 9aa67ed2a67ba..481f5347d978b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -314,14 +314,19 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PM.add( - createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover)); + PM.add(createHWAddressSanitizerLegacyPassPass( + /*CompileKernel*/ false, Recover, + /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); } static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, -legacy::PassManagerBase &PM) { + legacy::PassManagerBase &PM) { + const PassManagerBuilderWrapper &BuilderWrapper = + static_cast(Builder); + const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ true, /*Recover*/ true)); + /*CompileKernel*/ true, /*Recover*/ true, + /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); } static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, @@ -1164,7 +1169,9 @@ static void addSanitizers(const Triple &TargetTriple, auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); -MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover)); +MPM.addPass(HWAddressSanitizerPass( +CompileKernel, Recover, +/*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0)); } }; HWASanPass(SanitizerKind::HWAddress, false); diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c new file mode 100644 index 0..5c4f34027bacd --- /dev/null +++ b/clang/test/CodeGen/hwasan-stack-safety-analysis.c @@ -0,0 +1,15 @@ +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +// Default when optimizing, but not with O0. +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O0 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +int main(int argc, char **argv) { + char buf[10]; + volatile char *x = buf; + *x = 0; + return buf[0]; + // NOSAFETY: __hwasan_generate_tag + // SAFETY-NOT: __hwasan_generate_tag +} diff --git a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h index 76e02f06435c3..2e4f3338030a4 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h @@ -25,17 +25,21 @@ namespace llvm { class HWAddressSanitizerPass : public PassInfoMixin { public: explicit HWAddressSanitizerPass(bool CompileKernel = false, - bool Recover = false); + bool Recover = false, + bool DisableOptimization = false); PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); static bool isRequired() { return true; } private: bool CompileKernel; bool Recover; + bool DisableOptimization; }; -FunctionPass *createHWAdd
[clang] 789a4a2 - Revert "[hwasan] Use stack safety analysis."
Author: Florian Mayer Date: 2021-07-22T12:16:16+01:00 New Revision: 789a4a2e5c30b3eee632446d5b99bba808587836 URL: https://github.com/llvm/llvm-project/commit/789a4a2e5c30b3eee632446d5b99bba808587836 DIFF: https://github.com/llvm/llvm-project/commit/789a4a2e5c30b3eee632446d5b99bba808587836.diff LOG: Revert "[hwasan] Use stack safety analysis." This reverts commit bde9415fef25e9ff6e10595a2f4f5004dd62f10a. Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp Removed: clang/test/CodeGen/hwasan-stack-safety-analysis.c llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 481f5347d978b..9aa67ed2a67ba 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -314,19 +314,14 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ false, Recover, - /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); + PM.add( + createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover)); } static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, - legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); - const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); +legacy::PassManagerBase &PM) { PM.add(createHWAddressSanitizerLegacyPassPass( - /*CompileKernel*/ true, /*Recover*/ true, - /*DisableOptimization*/ CGOpts.OptimizationLevel == 0)); + /*CompileKernel*/ true, /*Recover*/ true)); } static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, @@ -1169,9 +1164,7 @@ static void addSanitizers(const Triple &TargetTriple, auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) { if (LangOpts.Sanitize.has(Mask)) { bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); -MPM.addPass(HWAddressSanitizerPass( -CompileKernel, Recover, -/*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0)); +MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover)); } }; HWASanPass(SanitizerKind::HWAddress, false); diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c deleted file mode 100644 index 5c4f34027bacd..0 --- a/clang/test/CodeGen/hwasan-stack-safety-analysis.c +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -// Default when optimizing, but not with O0. -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O0 %s -o - | FileCheck %s --check-prefix=NOSAFETY - -int main(int argc, char **argv) { - char buf[10]; - volatile char *x = buf; - *x = 0; - return buf[0]; - // NOSAFETY: __hwasan_generate_tag - // SAFETY-NOT: __hwasan_generate_tag -} diff --git a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h index 2e4f3338030a4..76e02f06435c3 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h @@ -25,21 +25,17 @@ namespace llvm { class HWAddressSanitizerPass : public PassInfoMixin { public: explicit HWAddressSanitizerPass(bool CompileKernel = false, - bool Recover = false, - bool DisableOptimization = false); + bool Recover = false); PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); static bool isRequired() { return true; } private: bool CompileKernel; bool Recover; - bool DisableOptimization; }; -FunctionPass * -createHWAddressSanitizerLegacyPassPass(bool CompileKernel = false,
[clang] 835ef6f - [hwasan] Fix stack safety test for old PM.
Author: Florian Mayer Date: 2021-07-27T20:50:46+01:00 New Revision: 835ef6f93d5789d3d7d905462e7574a38b30577d URL: https://github.com/llvm/llvm-project/commit/835ef6f93d5789d3d7d905462e7574a38b30577d DIFF: https://github.com/llvm/llvm-project/commit/835ef6f93d5789d3d7d905462e7574a38b30577d.diff LOG: [hwasan] Fix stack safety test for old PM. With the old PM, the stub for __hwasan_generate_tag is still generated in the IR, but never called. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D106858 Added: Modified: clang/test/CodeGen/hwasan-stack-safety-analysis.c Removed: diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis.c b/clang/test/CodeGen/hwasan-stack-safety-analysis.c index 5c4f34027bac..ba50274de282 100644 --- a/clang/test/CodeGen/hwasan-stack-safety-analysis.c +++ b/clang/test/CodeGen/hwasan-stack-safety-analysis.c @@ -1,5 +1,8 @@ -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY -// RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY +// RUN: %clang -fno-legacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -fno-legacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY + +// RUN: %clang -flegacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY +// RUN: %clang -flegacy-pass-manager -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=NOSAFETY // Default when optimizing, but not with O0. // RUN: %clang -fsanitize=hwaddress -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefix=SAFETY @@ -10,6 +13,6 @@ int main(int argc, char **argv) { volatile char *x = buf; *x = 0; return buf[0]; - // NOSAFETY: __hwasan_generate_tag - // SAFETY-NOT: __hwasan_generate_tag + // NOSAFETY: call i8 @__hwasan_generate_tag + // SAFETY-NOT: call i8 @__hwasan_generate_tag } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)
fmayer wrote: I don't have a strong opinion, but fundamentally I would prefer if the source control system stored exactly the files I have in my checkout, not mess with them in any way. I understand there are practical concerns, but a linter for unexpected CRLF would maybe be an option? https://github.com/llvm/llvm-project/pull/86318 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)
fmayer wrote: > That wish is fine until you start working with others. Do we actually have that little faith in developers that we think they will check in a 50k line diff? https://github.com/llvm/llvm-project/pull/86318 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)
fmayer wrote: > . The point of this patch is not to lambast developers or interfere with > their local setups; it's to get the line-ending issues out of the way for > good so they can focus on what they do best. Fair enough. I don't think it will fully make them go away for good, as you mentioned "[...] except for specific cases like .bat files or tests for parsers that need to accept such sequences." Something somewhere is bound to work before the transformation, and no longer after. It's possible that that will be more rare, though I would say 100 reverts in all of LLVM history isn't really that much either, all things considered. > And, given what I quoted above, it's not about faith - it's about historical > evidence that this is a problem. I am not saying this isn't a problem at all, but how often has anyone done a one line change and caused a 50k diff, and submitted it without noticing? https://github.com/llvm/llvm-project/pull/86318 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] Fix SyntaxWarning messages from python 3.12 (PR #86806)
fmayer wrote: LGTM, verified the two strings are the same ``` >>> r"^(.*) \(in (.*)\) \((.*:\d*)\)$" == "^(.*) \(in (.*)\) \((.*:\d*)\)$" True >>> "^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)" == >>> r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)" ``` https://github.com/llvm/llvm-project/pull/86806 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Pass triple to IncrementalCompilerBuilder as explicit argument (PR #84174)
fmayer wrote: This triggers the leak detector in our HWASan build bot ``` Note: This is test shard 1 of 23. [==] Running 1 test from 1 test suite. [--] Global test environment set-up. [--] 1 test from IncrementalCompilerBuilder [ RUN ] IncrementalCompilerBuilder.SetCompilerArgs [ OK ] IncrementalCompilerBuilder.SetCompilerArgs (12 ms) [--] 1 test from IncrementalCompilerBuilder (12 ms total) [--] Global test environment tear-down [==] 1 test from 1 test suite ran. (12 ms total) [ PASSED ] 1 test. = ==2996657==ERROR: LeakSanitizer: detected memory leaks Direct leak of 33 byte(s) in 1 object(s) allocated from: #0 0xc1507a9c in operator new(unsigned long) /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/compiler-rt/lib/hwasan/hwasan_new_delete.cpp:64:3 #1 0xc2593884 in operator new(unsigned long, (anonymous namespace)::NamedBufferAlloc const&) /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:82:35 #2 0xc2593550 in llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, llvm::StringRef, bool) /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/Support/MemoryBuffer.cpp:124:15 #3 0xc39509d4 in CreateCI /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:111:28 #4 0xc39509d4 in clang::IncrementalCompilerBuilder::create(std::__1::basic_string, std::__1::allocator>, std::__1::vector>&) /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:178:10 #5 0xc3953298 in clang::IncrementalCompilerBuilder::CreateCpp() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/lib/Interpreter/Interpreter.cpp:189:10 #6 0xc1509c10 in (anonymous namespace)::IncrementalCompilerBuilder_SetCompilerArgs_Test::TestBody() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp:24:25 #7 0xc273ec98 in HandleExceptionsInMethodIfSupported /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc #8 0xc273ec98 in testing::Test::Run() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:2687:5 #9 0xc2742074 in testing::TestInfo::Run() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:2836:11 #10 0xc2744284 in testing::TestSuite::Run() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:3015:30 #11 0xc276ac1c in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:5920:44 #12 0xc27695e8 in HandleExceptionsInMethodIfSupported /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc #13 0xc27695e8 in testing::UnitTest::Run() /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/src/gtest.cc:5484:10 #14 0xc2700288 in RUN_ALL_TESTS /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:2317:73 #15 0xc2700288 in main /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/third-party/unittest/UnitTestMain/TestMain.cpp:55:10 #16 0x98856dbc (/lib/aarch64-linux-gnu/libc.so.6+0x26dbc) (BuildId: b3e2fd825ee86277a10a2c20b9fc836b101a2b7f) #17 0x98856e94 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x26e94) (BuildId: b3e2fd825ee86277a10a2c20b9fc836b101a2b7f) #18 0xc14cf22c in _start (/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/unittests/Interpreter/ClangReplInterpreterTests+0x3fdf22c) SUMMARY: HWAddressSanitizer: 33 byte(s) leaked in 1 allocation(s). libc++abi: Pure virtual function called! -- exit: -6 -- Testing: 0.. 10.. 20 FAIL: Clang-Unit :: Interpreter/./ClangReplInterpreterTests/1/23 (19683 of 78329) TEST 'Clang-Unit :: Interpreter/./ClangReplInterpreterTests/1/23' FAILED Script(shard): -- GTEST_OUTPUT=json:/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests-Clang-Unit-2413105-1-23.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=23 GTEST_SHARD_INDEX=1 /b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/unittests/Interpreter/./ClangReplInterpreterTests -- Note: This is test shard 2 of 23. [==] Running 1 test from 1 test suite. [--] Global test environment set-up. [--] 1 test from IncrementalCompile
[libcxx] [llvm] [lld] [flang] [clang] [lldb] [libc] [libcxxabi] [msan] Unpoison indirect outputs for userspace using llvm.memset.* (PR #79924)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/79924 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [NFC] Size and element numbers are often swapped when calling calloc (PR #79081)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/79081 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang] [AMDGPU] Reapply 'Sign extend simm16 in setreg intrinsic' (PR #78492)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/78492 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Hurd: Add x86_64 support (PR #78065)
fmayer wrote: This broke Sanitizer bots: ``` [5/25] Building CXX object tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o FAILED: tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /b/sanitizer-aarch64-linux/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/sanitizer-aarch64-linux/build/build_symbolizer/tools/clang/lib/Driver -I/b/sanitizer-aarch64-linux/build/llvm-project/clang/lib/Driver -I/b/sanitizer-aarch64-linux/build/llvm-project/clang/include -I/b/sanitizer-aarch64-linux/build/build_symbolizer/tools/clang/include -I/b/sanitizer-aarch64-linux/build/build_symbolizer/include -I/b/sanitizer-aarch64-linux/build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o -MF tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o.d -o tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Hurd.cpp.o -c /b/sanitizer-aarch64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Hurd.cpp /b/sanitizer-aarch64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Hurd.cpp:137:11: error: 60 enumeration values not handled in switch: 'UnknownArch', 'arm', 'armeb'... [-Werror,-Wswitch] 137 | switch (getArch()) { | ^ 1 error generated. ``` https://github.com/llvm/llvm-project/pull/78065 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] hurd: Fix build with -Werror,-Wswitch (PR #78520)
fmayer wrote: Drive-by: is the `llvm_unreachable` actually unreachable? I.e. we never call this function with this case? Otherwise we are introducing UB in `NDEBUG` builds ``` /// In NDEBUG builds, if the platform does not support a builtin unreachable /// then we call an internal LLVM runtime function. Otherwise the behavior is /// controlled by the CMake flag /// -DLLVM_UNREACHABLE_OPTIMIZE /// * When "ON" (default) llvm_unreachable() becomes an optimizer hint /// that the current location is not supposed to be reachable: the hint /// turns such code path into undefined behavior. On compilers that don't /// support such hints, prints a reduced message instead and aborts the /// program. ``` https://github.com/llvm/llvm-project/pull/78520 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] hurd: Fix build with -Werror,-Wswitch (PR #78520)
https://github.com/fmayer approved this pull request. Is there a reason you put this first? Otherwise IMO it is slightly neater to put it last. https://github.com/llvm/llvm-project/pull/78520 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [clang] [NFC] Size and element numbers are often swapped when calling calloc (PR #79081)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/79081 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 45abbaf - Revert "[clangd] Support `#pragma mark` in the outline"
Author: Florian Mayer Date: 2021-08-10T14:25:52+01:00 New Revision: 45abbaf2e5fbdf27c9f8ba01b34018b0be45b7c9 URL: https://github.com/llvm/llvm-project/commit/45abbaf2e5fbdf27c9f8ba01b34018b0be45b7c9 DIFF: https://github.com/llvm/llvm-project/commit/45abbaf2e5fbdf27c9f8ba01b34018b0be45b7c9.diff LOG: Revert "[clangd] Support `#pragma mark` in the outline" This reverts commit ba06ac8b45ca2ad047131fb9cc9af922cb913ea1. Added: Modified: clang-tools-extra/clangd/CollectMacros.cpp clang-tools-extra/clangd/CollectMacros.h clang-tools-extra/clangd/FindSymbols.cpp clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/ParsedAST.h clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/Preamble.h clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp clang-tools-extra/clangd/unittests/ParsedASTTests.cpp clang/include/clang/Lex/PPCallbacks.h Removed: diff --git a/clang-tools-extra/clangd/CollectMacros.cpp b/clang-tools-extra/clangd/CollectMacros.cpp index 9bcc3c1995415..0e89b35d9d56d 100644 --- a/clang-tools-extra/clangd/CollectMacros.cpp +++ b/clang-tools-extra/clangd/CollectMacros.cpp @@ -30,33 +30,5 @@ void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI, else Out.UnknownMacros.push_back({Range, IsDefinition}); } - -class CollectPragmaMarks : public PPCallbacks { -public: - explicit CollectPragmaMarks(const SourceManager &SM, - std::vector &Out) - : SM(SM), Out(Out) {} - - void PragmaMark(SourceLocation Loc, StringRef Trivia) override { -if (isInsideMainFile(Loc, SM)) { - // FIXME: This range should just cover `XX` in `#pragma mark XX` and - // `- XX` in `#pragma mark - XX`. - Position Start = sourceLocToPosition(SM, Loc); - Position End = {Start.line + 1, 0}; - Out.emplace_back(clangd::PragmaMark{{Start, End}, Trivia.str()}); -} - } - -private: - const SourceManager &SM; - std::vector &Out; -}; - -std::unique_ptr -collectPragmaMarksCallback(const SourceManager &SM, - std::vector &Out) { - return std::make_unique(SM, Out); -} - } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/CollectMacros.h b/clang-tools-extra/clangd/CollectMacros.h index 2167ebe2e3560..3240111e5a33d 100644 --- a/clang-tools-extra/clangd/CollectMacros.h +++ b/clang-tools-extra/clangd/CollectMacros.h @@ -99,18 +99,6 @@ class CollectMainFileMacros : public PPCallbacks { MainFileMacros &Out; }; -/// Represents a `#pragma mark` in the main file. -/// -/// There can be at most one pragma mark per line. -struct PragmaMark { - Range Rng; - std::string Trivia; -}; - -/// Collect all pragma marks from the main file. -std::unique_ptr -collectPragmaMarksCallback(const SourceManager &, std::vector &Out); - } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp index edbeeed9e2ca6..e4846ac7a59d3 100644 --- a/clang-tools-extra/clangd/FindSymbols.cpp +++ b/clang-tools-extra/clangd/FindSymbols.cpp @@ -523,135 +523,9 @@ class DocumentOutline { ParsedAST &AST; }; -struct PragmaMarkSymbol { - DocumentSymbol DocSym; - bool IsGroup; -}; - -/// Merge in `PragmaMarkSymbols`, sorted ascending by range, into the given -/// `DocumentSymbol` tree. -void mergePragmas(DocumentSymbol &Root, ArrayRef Pragmas) { - while (!Pragmas.empty()) { -// We'll figure out where the Pragmas.front() should go. -PragmaMarkSymbol P = std::move(Pragmas.front()); -Pragmas = Pragmas.drop_front(); -DocumentSymbol *Cur = &Root; -while (Cur->range.contains(P.DocSym.range)) { - bool Swapped = false; - for (auto &C : Cur->children) { -// We assume at most 1 child can contain the pragma (as pragmas are on -// a single line, and children have disjoint ranges). -if (C.range.contains(P.DocSym.range)) { - Cur = &C; - Swapped = true; - break; -} - } - // Cur is the parent of P since none of the children contain P. - if (!Swapped) -break; -} -// Pragma isn't a group so we can just insert it and we are done. -if (!P.IsGroup) { - Cur->children.emplace_back(std::move(P.DocSym)); - continue; -} -// Pragma is a group, so we need to figure out where it terminates: -// - If the next Pragma is not contained in Cur, P owns all of its -// parent's children which occur after P. -// - If the next pragma is contained in Cur but actually belongs to one -// of the parent's children, we temporarily skip over it and look at -// the next pragma to decide where we end. -// - Otherwise nest all of its parent's children which occur after P
[libunwind] a315338 - [libunwind] Handle G in personality string
Author: Florian Mayer Date: 2022-09-21T14:13:32-07:00 New Revision: a3153381af48b2e704750255a704748a13c4c4de URL: https://github.com/llvm/llvm-project/commit/a3153381af48b2e704750255a704748a13c4c4de DIFF: https://github.com/llvm/llvm-project/commit/a3153381af48b2e704750255a704748a13c4c4de.diff LOG: [libunwind] Handle G in personality string Tested with the following program: ``` static volatile int* x = nullptr; void throws() __attribute__((noinline)) { if (getpid() == 0) return; throw "error"; } void maybe_throws() __attribute__((noinline)) { volatile int y = 1; x = &y; throws(); y = 2; } int main(int argc, char** argv) { int y; try { maybe_throws(); } catch (const char* e) { //printf("Caught\n"); } y = *x; printf("%d\n", y); // should be MTE failure. return 0; } ``` Built using `clang++ -c -O2 -target aarch64-linux -fexceptions -march=armv8-a+memtag -fsanitize=memtag-heap,memtag-stack` Currently only Android implements runtime support for MTE stack tagging. Without this change, we crash on `__cxa_get_globals` when trying to catch the exception (because the stack frame __cxa_get_globals frame will fail due to tags left behind on the stack). With this change, we crash on the `y = *x;` as expected, because the stack frame has been untagged, but the pointer hasn't. Reviewed By: #libunwind, compnerd, MaskRay Differential Revision: https://reviews.llvm.org/D128998 Added: Modified: libunwind/src/DwarfInstructions.hpp libunwind/src/DwarfParser.hpp libunwind/src/UnwindCursor.hpp libunwind/src/UnwindLevel1.c libunwind/src/libunwind.cpp Removed: diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index f81f96ce5a36d..1901c8a8aee7d 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -35,7 +35,7 @@ class DwarfInstructions { typedef typename A::sint_t sint_t; static int stepWithDwarf(A &addressSpace, pint_t pc, pint_t fdeStart, - R ®isters, bool &isSignalFrame); + R ®isters, bool &isSignalFrame, bool stage2); private: @@ -190,7 +190,7 @@ bool DwarfInstructions::getRA_SIGN_STATE(A &addressSpace, R registers, template int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc, pint_t fdeStart, R ®isters, - bool &isSignalFrame) { + bool &isSignalFrame, bool stage2) { FDE_Info fdeInfo; CIE_Info cieInfo; if (CFI_Parser::decodeFDE(addressSpace, fdeStart, &fdeInfo, @@ -201,7 +201,35 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc, // get pointer to cfa (architecture specific) pint_t cfa = getCFA(addressSpace, prolog, registers); - // restore registers that DWARF says were saved + (void)stage2; +#if defined(_LIBUNWIND_TARGET_AARCH64) + if (stage2 && cieInfo.mteTaggedFrame) { +pint_t sp = registers.getSP(); +pint_t p = sp; +// AArch64 doesn't require the value of SP to be 16-byte aligned at +// all times, only at memory accesses and public interfaces [1]. Thus, +// a signal could arrive at a point where SP is not aligned properly. +// In that case, the kernel fixes up [2] the signal frame, but we +// still have a misaligned SP in the previous frame. If that signal +// handler caused stack unwinding, we would have an unaligned SP. +// We do not need to fix up the CFA, as that is the SP at a "public +// interface". +// [1]: +// https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#622the-stack +// [2]: +// https://github.com/torvalds/linux/blob/1930a6e739c4b4a654a69164dbe39e554d228915/arch/arm64/kernel/signal.c#L718 +p &= ~0xfULL; +// CFA is the bottom of the current stack frame. +for (; p < cfa; p += 16) { + __asm__ __volatile__(".arch_extension memtag\n" + "stg %[Ptr], [%[Ptr]]\n" + : + : [Ptr] "r"(p) + : "memory"); +} + } +#endif + // restore registers that DWARF says were saved R newRegisters = registers; // Typically, the CFA is the stack pointer at the call site in diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp index 0240334eaa73f..0682942ce1379 100644 --- a/libunwind/src/DwarfParser.hpp +++ b/libunwind/src/DwarfParser.hpp @@ -51,6 +51,7 @@ class CFI_Parser { uint8_t returnAddressRegister; #if defined(_LIBUNWIND_TARGET_AARCH64) bool addressesSignedWithBKey; +bool mteTaggedFrame; #endif }; @@ -325,6 +326,7 @@ const char *CFI_Parser::parseCIE(A &
[libunwind] f5c9931 - [libunwind] Fix compile error with CROSS_UNWINDING
Author: Florian Mayer Date: 2022-09-30T12:04:19-07:00 New Revision: f5c9931fefcab8de07a6c08c39b582fa58859dc9 URL: https://github.com/llvm/llvm-project/commit/f5c9931fefcab8de07a6c08c39b582fa58859dc9 DIFF: https://github.com/llvm/llvm-project/commit/f5c9931fefcab8de07a6c08c39b582fa58859dc9.diff LOG: [libunwind] Fix compile error with CROSS_UNWINDING Reviewed By: #libunwind, MaskRay, mgorny Differential Revision: https://reviews.llvm.org/D134969 Added: Modified: libunwind/src/DwarfInstructions.hpp Removed: diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index 1901c8a8aee7d..27432be56133b 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -202,7 +202,10 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc, pint_t cfa = getCFA(addressSpace, prolog, registers); (void)stage2; -#if defined(_LIBUNWIND_TARGET_AARCH64) + // __unw_step_stage2 is not used for cross unwinding, so we use + // __aarch64__ rather than LIBUNWIND_TARGET_AARCH64 to make sure we are + // building for AArch64 natively. +#if defined(__aarch64__) if (stage2 && cieInfo.mteTaggedFrame) { pint_t sp = registers.getSP(); pint_t p = sp; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 13b8bfc - [libunwind] Add more information to eh_frame_hdr version error
Author: Florian Mayer Date: 2022-06-01T19:48:19-07:00 New Revision: 13b8bfc51451fcfc00f3e3480abaf64b337a43d4 URL: https://github.com/llvm/llvm-project/commit/13b8bfc51451fcfc00f3e3480abaf64b337a43d4 DIFF: https://github.com/llvm/llvm-project/commit/13b8bfc51451fcfc00f3e3480abaf64b337a43d4.diff LOG: [libunwind] Add more information to eh_frame_hdr version error This makes it easier to find the offending ELF file. Reviewed By: #libunwind, MaskRay Differential Revision: https://reviews.llvm.org/D126841 Added: Modified: libunwind/src/EHHeaderParser.hpp Removed: diff --git a/libunwind/src/EHHeaderParser.hpp b/libunwind/src/EHHeaderParser.hpp index 9a38070faba9b..ed4317c89055c 100644 --- a/libunwind/src/EHHeaderParser.hpp +++ b/libunwind/src/EHHeaderParser.hpp @@ -57,7 +57,8 @@ bool EHHeaderParser::decodeEHHdr(A &addressSpace, pint_t ehHdrStart, pint_t p = ehHdrStart; uint8_t version = addressSpace.get8(p++); if (version != 1) { -_LIBUNWIND_LOG0("Unsupported .eh_frame_hdr version"); +_LIBUNWIND_LOG("unsupported .eh_frame_hdr version: %" PRIu8 " at %" PRIx64, + version, static_cast(ehHdrStart)); return false; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] 53c1584 - [NFC] [libunwind] turn assert into static_assert
Author: Florian Mayer Date: 2022-06-03T16:32:42-07:00 New Revision: 53c1584063e8f3225bfe71724cc7de79576ea61a URL: https://github.com/llvm/llvm-project/commit/53c1584063e8f3225bfe71724cc7de79576ea61a DIFF: https://github.com/llvm/llvm-project/commit/53c1584063e8f3225bfe71724cc7de79576ea61a.diff LOG: [NFC] [libunwind] turn assert into static_assert Reviewed By: #libunwind, MaskRay Differential Revision: https://reviews.llvm.org/D126987 Added: Modified: libunwind/src/DwarfInstructions.hpp libunwind/src/Registers.hpp Removed: diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp index a4fac5afa9b82..cee4ea53dab7a 100644 --- a/libunwind/src/DwarfInstructions.hpp +++ b/libunwind/src/DwarfInstructions.hpp @@ -213,9 +213,10 @@ int DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc, newRegisters.setSP(cfa); pint_t returnAddress = 0; - const int lastReg = R::lastDwarfRegNum(); - assert(static_cast(CFI_Parser::kMaxRegisterNumber) >= lastReg && - "register range too large"); + constexpr int lastReg = R::lastDwarfRegNum(); + static_assert(static_cast(CFI_Parser::kMaxRegisterNumber) >= +lastReg, +"register range too large"); assert(lastReg >= (int)cieInfo.returnAddressRegister && "register range does not contain return address register"); for (int i = 0; i <= lastReg; ++i) { diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp index 28c617f34999b..98adb78940f2a 100644 --- a/libunwind/src/Registers.hpp +++ b/libunwind/src/Registers.hpp @@ -70,7 +70,9 @@ class _LIBUNWIND_HIDDEN Registers_x86 { voidsetVectorRegister(int num, v128 value); static const char *getRegisterName(int num); voidjumpto() { __libunwind_Registers_x86_jumpto(this); } - static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86; } + static constexpr int lastDwarfRegNum() { +return _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86; + } static int getArch() { return REGISTERS_X86; } uint32_t getSP() const { return _registers.__esp; } @@ -286,7 +288,9 @@ class _LIBUNWIND_HIDDEN Registers_x86_64 { voidsetVectorRegister(int num, v128 value); static const char *getRegisterName(int num); voidjumpto() { __libunwind_Registers_x86_64_jumpto(this); } - static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86_64; } + static constexpr int lastDwarfRegNum() { +return _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86_64; + } static int getArch() { return REGISTERS_X86_64; } uint64_t getSP() const { return _registers.__rsp; } @@ -603,7 +607,9 @@ class _LIBUNWIND_HIDDEN Registers_ppc { voidsetVectorRegister(int num, v128 value); static const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC; } + static constexpr int lastDwarfRegNum() { +return _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC; + } static int getArch() { return REGISTERS_PPC; } uint64_t getSP() const { return _registers.__r1; } @@ -1171,7 +1177,9 @@ class _LIBUNWIND_HIDDEN Registers_ppc64 { voidsetVectorRegister(int num, v128 value); static const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64; } + static constexpr int lastDwarfRegNum() { +return _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64; + } static int getArch() { return REGISTERS_PPC64; } uint64_t getSP() const { return _registers.__r1; } @@ -1818,7 +1826,9 @@ class _LIBUNWIND_HIDDEN Registers_arm64 { voidsetVectorRegister(int num, v128 value); static const char *getRegisterName(int num); voidjumpto() { __libunwind_Registers_arm64_jumpto(this); } - static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64; } + static constexpr int lastDwarfRegNum() { +return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64; + } static int getArch() { return REGISTERS_ARM64; } uint64_t getSP() const { return _registers.__sp; } @@ -2108,7 +2118,9 @@ class _LIBUNWIND_HIDDEN Registers_arm { restoreSavedFloatRegisters(); restoreCoreAndJumpTo(); } - static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM; } + static constexpr int lastDwarfRegNum() { +return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM; + } static int getArch() { return REGISTERS_ARM; } uint32_t getSP() const { return _registers.__sp; } @@ -2608,7 +2620,9 @@ class _LIBUNWIND_HIDDEN Registers_or1k { voidsetVectorRegister(int num, v128 value); static const char *getRegisterName(int num); voidjumpto(); - static int lastDwarfR
[clang] 043d03d - Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code""
Author: Florian Mayer Date: 2023-08-04T14:24:26-07:00 New Revision: 043d03d25bd7eadef66685de298342b35fe6b466 URL: https://github.com/llvm/llvm-project/commit/043d03d25bd7eadef66685de298342b35fe6b466 DIFF: https://github.com/llvm/llvm-project/commit/043d03d25bd7eadef66685de298342b35fe6b466.diff LOG: Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"" Broke sanitizer build bots This reverts commit b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9. Added: Modified: clang/lib/CodeGen/CGExpr.cpp clang/test/CodeGen/cfi-check-fail.c Removed: diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 07e204387804c8..0aadaeaba69f3d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3431,12 +3431,14 @@ void CodeGenFunction::EmitCfiCheckStub() { 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); - // 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); + // 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); llvm::ReturnInst::Create(Ctx, nullptr, BB); } @@ -3530,6 +3532,9 @@ void CodeGenFunction::EmitCfiCheckFail() { } 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) { diff --git a/clang/test/CodeGen/cfi-check-fail.c b/clang/test/CodeGen/cfi-check-fail.c index 2f12cee9dec602..a4d940641090e5 100644 --- a/clang/test/CodeGen/cfi-check-fail.c +++ b/clang/test/CodeGen/cfi-check-fail.c @@ -72,7 +72,7 @@ void caller(void (*f)(void)) { // CHECK: [[CONT5]]: // CHECK: ret void -// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], ptr %[[DATA:.*]]) align 4096 +// CHECK: define weak void @__cfi_check(i64 %0, ptr %1, ptr %2) // CHECK-NOT: } -// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]]) +// CHECK: call void @llvm.trap() // CHECK-NEXT: ret void ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a2684ac - [HWASan] use hwasan linker for Android 14+
Author: Florian Mayer Date: 2023-05-26T14:25:46-07:00 New Revision: a2684acfb61d40f441e240035d7f1ba50da637c8 URL: https://github.com/llvm/llvm-project/commit/a2684acfb61d40f441e240035d7f1ba50da637c8 DIFF: https://github.com/llvm/llvm-project/commit/a2684acfb61d40f441e240035d7f1ba50da637c8.diff LOG: [HWASan] use hwasan linker for Android 14+ This will allow to compile binaries that use hwasan to run on a non-HWASan system image. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D151388 Added: Modified: clang/lib/Driver/ToolChains/Linux.cpp clang/test/Driver/linux-ld.c Removed: diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 853ff99d9fe59..920da6e4bfd49 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -426,9 +426,17 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { const Distro Distro(getDriver().getVFS(), Triple); - if (Triple.isAndroid()) + if (Triple.isAndroid()) { +if (getSanitizerArgs(Args).needsHwasanRt() && +!Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) { + // On Android 14 and newer, there is a special linker_hwasan64 that + // allows to run HWASan binaries on non-HWASan system images. This + // is also available on HWASan system images, so we can just always + // use that instead. + return "/system/bin/linker_hwasan64"; +} return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker"; - + } if (Triple.isMusl()) { std::string ArchName; bool IsArm = false; diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 287750ac20469..d4e3bf95d6813 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1259,6 +1259,22 @@ // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker" // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64" // +// Test that Android 14 and newer use linker_hwasan64 for hwasan builds +// RUN: %clang -### %s -no-pie 2>&1 \ +// RUN: -fsanitize=hwaddress \ +// RUN: --target=x86_64-linux-android33 \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-OLD %s +// RUN: %clang -### %s -no-pie 2>&1 \ +// RUN: -fsanitize=hwaddress \ +// RUN: --target=x86_64-linux-android34 \ +// RUN: --gcc-toolchain="" \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-NEW %s +// CHECK-ANDROID-OLD: "-dynamic-linker" "/system/bin/linker64" +// CHECK-ANDROID-NEW: "-dynamic-linker" "/system/bin/linker_hwasan64" +// // Test that -pthread does not add -lpthread on Android. // RUN: %clang -### %s -no-pie 2>&1 \ // RUN: --target=arm-linux-androideabi -pthread \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Delay sanitizer args parsing. (PR #107280)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/107280 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Delay sanitizer args parsing. (PR #107280)
fmayer wrote: super-nit: add `[sanitizers]` and remove `.` from commit message? https://github.com/llvm/llvm-project/pull/107280 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)
fmayer wrote: LGTM, but would like @vitalybuka to also take a quick look. https://github.com/llvm/llvm-project/pull/104741 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
fmayer wrote: > ⚠️ We detected that you are using a GitHub private e-mail address to > contribute to the repo. Please turn off [Keep my email addresses > private](https://github.com/settings/emails) setting in your account. See > [LLVM > Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) > for more information. @bigb4ng please do this. Thank you https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
@@ -313,6 +313,14 @@ Limitations usually expected. * Static linking of executables is not supported. +Security Considerations +=== + +AddressSanitizer is a bug detection tool and is not meant to be linked fmayer wrote: nit: maybe "its runtime is not meant to be linked?" https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy)" (PR #95299)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/95299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Bump the DWARF version number to 5 on Darwin. (PR #95164)
fmayer wrote: This broke our buildbot: https://lab.llvm.org/buildbot/#/builders/37/builds/35987 ``` FAILED: tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /b/sanitizer-x86_64-linux/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/sanitizer-x86_64-linux/build/build_symbolizer/tools/clang/lib/Driver -I/b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver -I/b/sanitizer-x86_64-linux/build/llvm-project/clang/include -I/b/sanitizer-x86_64-linux/build/build_symbolizer/tools/clang/include -I/b/sanitizer-x86_64-linux/build/build_symbolizer/include -I/b/sanitizer-x86_64-linux/build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o -MF tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o.d -o tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/ToolChains/Darwin.cpp.o -c /b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp /b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp:1268:23: error: comparison of different enumeration types ('DarwinPlatformKind' and 'llvm::Triple::OSType') [-Werror,-Wenum-compare] 1268 | (TargetPlatform == llvm::Triple::BridgeOS)) |~~ ^ ~~ /b/sanitizer-x86_64-linux/build/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp:1268:23: error: result of comparison of constant 'BridgeOS' (28) with expression of type 'DarwinPlatformKind' is always false [-Werror,-Wtautological-constant-out-of-range-compare] 1268 | (TargetPlatform == llvm::Triple::BridgeOS)) |~~ ^ ~~ 2 errors generated. ninja: build stopped: subcommand failed. ``` https://github.com/llvm/llvm-project/pull/95164 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "Bump the DWARF version number to 5 on Darwin." (PR #95325)
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/95325 Reverts llvm/llvm-project#95164 This broke a buildbot: https://lab.llvm.org/buildbot/#/builders/37/builds/35987 >From fc671bbb1ceb94f8aac63bc0e4963e5894bc660e Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 12 Jun 2024 15:50:03 -0700 Subject: [PATCH] Revert "Bump the DWARF version number to 5 on Darwin. (#95164)" This reverts commit 8f6acd973a38da6dce45faa676cbb51da37f72e5. --- clang/lib/Driver/ToolChains/Darwin.cpp | 12 +--- clang/test/Driver/debug-options.c | 27 +- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index ca75a622b061e..ed5737915aa96 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1257,17 +1257,7 @@ unsigned DarwinClang::GetDefaultDwarfVersion() const { if ((isTargetMacOSBased() && isMacosxVersionLT(10, 11)) || (isTargetIOSBased() && isIPhoneOSVersionLT(9))) return 2; - // Default to use DWARF 4 on OS X 10.11 - macOS 14 / iOS 9 - iOS 17. - if ((isTargetMacOSBased() && isMacosxVersionLT(15)) || - (isTargetIOSBased() && isIPhoneOSVersionLT(18)) || - (isTargetWatchOSBased() && TargetVersion < llvm::VersionTuple(11)) || - (isTargetXROS() && TargetVersion < llvm::VersionTuple(2)) || - (isTargetDriverKit() && TargetVersion < llvm::VersionTuple(24)) || - (isTargetMacOSBased() && - TargetVersion.empty()) || // apple-darwin, no version. - (TargetPlatform == llvm::Triple::BridgeOS)) -return 4; - return 5; + return 4; } void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c index 0a665f7017d63..07f6ca9e3902f 100644 --- a/clang/test/Driver/debug-options.c +++ b/clang/test/Driver/debug-options.c @@ -68,32 +68,7 @@ // RUN: %clang -### -c -g %s -target x86_64-apple-driverkit19.0 2>&1 \ // RUN: | FileCheck -check-prefix=G_STANDALONE \ // RUN: -check-prefix=G_DWARF4 %s -// RUN: %clang -### -c -g %s -target x86_64-apple-macosx15 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF5 %s -// RUN: %clang -### -c -g %s -target arm64-apple-ios17.0 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF4 %s -// RUN: %clang -### -c -g %s -target arm64-apple-ios18.0 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF5 %s -// RUN: %clang -### -c -g %s -target arm64_32-apple-watchos11 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF5 %s -// RUN: %clang -### -c -g %s -target arm64-apple-tvos18.0 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF5 %s -// RUN: %clang -### -c -g %s -target x86_64-apple-driverkit24.0 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF5 %s -// RUN: %clang -### -c -g %s -target arm64-apple-xros1 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF4 %s -// RUN: %clang -### -c -g %s -target arm64-apple-xros2 2>&1 \ -// RUN: | FileCheck -check-prefix=G_STANDALONE \ -// RUN: -check-prefix=G_DWARF5 %s -// -// RUN: %clang -### -c -fsave-optimization-record %s\ +// RUN: %clang -### -c -fsave-optimization-record %s \ // RUN:-target x86_64-apple-darwin 2>&1 \ // RUN: | FileCheck -check-prefix=GLTO_ONLY %s // RUN: %clang -### -c -g -fsave-optimization-record %s \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "Bump the DWARF version number to 5 on Darwin." (PR #95325)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/95325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #93612)
fmayer wrote: Breakage looks related: https://lab.llvm.org/buildbot/#/builders/72/builds/265 ``` FAIL: UBSan-MemorySanitizer-powerpc64le :: TestCases/Integer/bit-int.c (4716 of 4745) TEST 'UBSan-MemorySanitizer-powerpc64le :: TestCases/Integer/bit-int.c' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/./bin/clang -fsanitize=memory -m64 -fno-function-sections -Wno-constant-conversion -Wno-array-bounds -Wno-division-by-zero -Wno-shift-negative-value -Wno-shift-count-negative -Wno-int-to-pointer-cast -O0 -fsanitize=alignment,array-bounds,bool,float-cast-overflow,implicit-integer-sign-change,implicit-signed-integer-truncation,implicit-unsigned-integer-truncation,integer-divide-by-zero,nonnull-attribute,null,nullability-arg,nullability-assign,nullability-return,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,unsigned-integer-overflow,unsigned-shift-base,vla-bound /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_g cc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1 && /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1 2>&1 | FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c --check-prefix=RUNTIME + /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/./bin/clang -fsanitize=memory -m64 -fno-function-sections -Wno-constant-conversion -Wno-array-bounds -Wno-division-by-zero -Wno-shift-negative-value -Wno-shift-count-negative -Wno-int-to-pointer-cast -O0 -fsanitize=alignment,array-bounds,bool,float-cast-overflow,implicit-integer-sign-change,implicit-signed-integer-truncation,implicit-unsigned-integer-truncation,integer-divide-by-zero,nonnull-attribute,null,nullability-arg,nullability-assign,nullability-return,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,unsigned-integer-overflow,unsigned-shift-base,vla-bound /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runti mes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1 + /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1 + FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c --check-prefix=RUNTIME /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c:93:14: error: RUNTIME: expected string not found in input // RUNTIME: {{.*}}bit-int.c:[[@LINE-1]]:24: runtime error: left shift of negative value -1 ^ :25:206: note: scanning from here /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c:86:21: runtime error: shift exponent -1 is negative ^ :25:206: note: with "@LINE-1" equal to "92" /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/compiler-rt/test/ubsan/TestCases/Integer/bit-int.c:86:21: runtime error: shift exponent -1 is negative ^ :33:252: note: possible intended match here SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/ubsan/MemorySanitizer-powerpc64le/TestCases/Integer/Output/bit-int.c.tmp1+0xe6d64) in shift_exponent
[clang] [clang-tools-extra] [clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference (PR #87954)
fmayer wrote: This broke the sanitizer bots, e.g. https://lab.llvm.org/buildbot/#/builders/239/builds/6587/steps/10/logs/stdio ``` [==] Running 2 tests from 1 test suite. [--] Global test environment set-up. [--] 2 tests from ExprMutationAnalyzerTest [ RUN ] ExprMutationAnalyzerTest.UnresolvedOperator [ OK ] ExprMutationAnalyzerTest.UnresolvedOperator (59 ms) [ RUN ] ExprMutationAnalyzerTest.ReproduceFailureMinimal input.cc:1:166: warning: unqualified call to 'std::forward' [-Wunqualified-std-cast-call] 1 | namespace std {template T &forward(T &A) { return static_cast(A); }template struct __bind { T f; template __bind(T v, V &&) : f(forward(v)) {}};}void f() { int x = 42; auto Lambda = [] {}; std::__bind(Lambda, x);} | ^ | std:: input.cc:1:230: note: in instantiation of function template specialization 'std::__bind<(lambda at input.cc:1:222)>::__bind' requested here 1 | namespace std {template T &forward(T &A) { return static_cast(A); }template struct __bind { T f; template __bind(T v, V &&) : f(forward(v)) {}};}void f() { int x = 42; auto Lambda = [] {}; std::__bind(Lambda, x);} | ^ [ OK ] ExprMutationAnalyzerTest.ReproduceFailureMinimal (46 ms) [--] 2 tests from ExprMutationAnalyzerTest (106 ms total) [--] Global test environment tear-down [==] 2 tests from 1 test suite ran. (107 ms total) [ PASSED ] 2 tests. = ==946027==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 1024 byte(s) in 1 object(s) allocated from: #0 0xc90ddce4 in operator new(unsigned long, std::align_val_t) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:98:3 #1 0xca15f590 in allocateBuckets /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:899:9 #2 0xca15f590 in llvm::DenseMap, llvm::detail::DenseMapPair>::grow(unsigned int) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:833:5 #3 0xca15f428 in grow /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:564:36 #4 0xca15f428 in InsertIntoBucketImpl /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h #5 0xca15f428 in llvm::detail::DenseMapPair* llvm::DenseMapBase, llvm::detail::DenseMapPair>, clang::ParmVarDecl const*, clang::Stmt const*, llvm::DenseMapInfo, llvm::detail::DenseMapPair>::InsertIntoBucket(llvm::detail::DenseMapPair*, clang::ParmVarDecl const* const&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:574:17 #6 0xca104ee8 in FindAndConstruct /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:353:13 #7 0xca104ee8 in operator[] /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/DenseMap.h:357:12 #8 0xca104ee8 in clang::FunctionParmMutationAnalyzer::findMutation(clang::ParmVarDecl const*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:685:3 #9 0xca0f64d4 in clang::ExprMutationAnalyzer::findFunctionArgMutation(clang::Expr const*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:645:23 #10 0xca0d5b30 in clang::ExprMutationAnalyzer::findMutationMemoized(clang::Expr const*, llvm::ArrayRef, llvm::DenseMap, llvm::detail::DenseMapPair>&) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:237:25 #11 0xca0d5864 in clang::ExprMutationAnalyzer::findMutation(clang::Expr const*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/lib/Analysis/ExprMutationAnalyzer.cpp:203:10 #12 0xc9176f08 in isMutated /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h:34:44 #13 0xc9176f08 in clang::(anonymous namespace)::isMutated(llvm::SmallVectorImpl const&, clang::ASTUnit*) /b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp:57:57 #14 0xc91c2980 in clang::ExprMuta
[clang] [clang-tools-extra] Revert "[clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference" (PR #88765)
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/88765 Reverts llvm/llvm-project#87954 Broke sanitizer bots, e.g. https://lab.llvm.org/buildbot/#/builders/239/builds/6587/steps/10/logs/stdio >From 82b9a06f73df5301ffd950775055304124f63e02 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Mon, 15 Apr 2024 10:46:21 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"[clang=20analysis]=20ExprMutationAnal?= =?UTF-8?q?yzer=20avoid=20infinite=20recursion=20for=20re=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8095b9ce6bf5831a14c72028920708f38d13d0c3. --- clang-tools-extra/docs/ReleaseNotes.rst | 4 --- .../misc/const-correctness-templates.cpp | 15 -- .../Analysis/Analyses/ExprMutationAnalyzer.h | 28 + clang/lib/Analysis/ExprMutationAnalyzer.cpp | 22 +- .../Analysis/ExprMutationAnalyzerTest.cpp | 30 --- 5 files changed, 15 insertions(+), 84 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 7095c56fe6..4dfbd8ca49ab9b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -221,10 +221,6 @@ Changes in existing checks ` check by replacing the local option `HeaderFileExtensions` by the global option of the same name. -- Improved :doc:`misc-const-correctness - ` check by avoiding infinite recursion - for recursive forwarding reference. - - Improved :doc:`misc-definitions-in-headers ` check by replacing the local option `HeaderFileExtensions` by the global option of the same name. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp index 248374a71dd40b..9da468128743e9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp @@ -58,18 +58,3 @@ void concatenate3(Args... args) (..., (stream << args)); } } // namespace gh70323 - -namespace gh60895 { - -template void f1(T &&a); -template void f2(T &&a); -template void f1(T &&a) { f2(a); } -template void f2(T &&a) { f1(a); } -void f() { - int x = 0; - // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'x' of type 'int' can be declared 'const' - // CHECK-FIXES: int const x = 0; - f1(x); -} - -} // namespace gh60895 diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h index c4e5d0badb8e58..1ceef944fbc34e 100644 --- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h +++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h @@ -8,10 +8,11 @@ #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H #define LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H +#include + #include "clang/AST/AST.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "llvm/ADT/DenseMap.h" -#include namespace clang { @@ -21,15 +22,8 @@ class FunctionParmMutationAnalyzer; /// a given statement. class ExprMutationAnalyzer { public: - friend class FunctionParmMutationAnalyzer; - struct Cache { -llvm::SmallDenseMap> -FuncParmAnalyzer; - }; - ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context) - : ExprMutationAnalyzer(Stm, Context, std::make_shared()) {} + : Stm(Stm), Context(Context) {} bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; } bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; } @@ -51,11 +45,6 @@ class ExprMutationAnalyzer { using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *); using ResultMap = llvm::DenseMap; - ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context, - std::shared_ptr CrossAnalysisCache) - : Stm(Stm), Context(Context), -CrossAnalysisCache(std::move(CrossAnalysisCache)) {} - const Stmt *findMutationMemoized(const Expr *Exp, llvm::ArrayRef Finders, ResultMap &MemoizedResults); @@ -80,7 +69,9 @@ class ExprMutationAnalyzer { const Stmt &Stm; ASTContext &Context; - std::shared_ptr CrossAnalysisCache; + llvm::DenseMap> + FuncParmAnalyzer; ResultMap Results; ResultMap PointeeResults; }; @@ -89,12 +80,7 @@ class ExprMutationAnalyzer { // params. class FunctionParmMutationAnalyzer { public: - FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context) - : FunctionParmMutationAnalyzer( -Func, Context, std::make_shared()) {} - FunctionParmMutationAnalyzer( - const FunctionDecl &Func, ASTContext &Context, - std::shared_ptr CrossAnalysisCache); + FunctionParmMutationAnalyzer(const FunctionDecl &Func, AS
[clang] [clang-tools-extra] Revert "[clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference" (PR #88765)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/88765 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] Revert "[clang] Enable sized deallocation by default in C++14 onwards (#83774)" (PR #90299)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/90299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Reapply "[HWASan] remove incorrectly inferred attributes" (#106622) (PR #106624)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/106624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Revert "Reapply "[HWASan] remove incorrectly inferred attributes" (#106622)" (PR #106758)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/106758 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1d730d8 - [HWASAN] erase lifetime intrinsics if tag is outside.
Author: Florian Mayer Date: 2022-03-01T14:47:33-08:00 New Revision: 1d730d80ce592fde66b1ba6153f08f72778f94ce URL: https://github.com/llvm/llvm-project/commit/1d730d80ce592fde66b1ba6153f08f72778f94ce DIFF: https://github.com/llvm/llvm-project/commit/1d730d80ce592fde66b1ba6153f08f72778f94ce.diff LOG: [HWASAN] erase lifetime intrinsics if tag is outside. Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D120437 Added: Modified: clang/test/CodeGen/lifetime-sanitizer.c clang/test/CodeGenCXX/lifetime-sanitizer.cpp llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll Removed: diff --git a/clang/test/CodeGen/lifetime-sanitizer.c b/clang/test/CodeGen/lifetime-sanitizer.c index 95fa970c72bc8..32adc36f01455 100644 --- a/clang/test/CodeGen/lifetime-sanitizer.c +++ b/clang/test/CodeGen/lifetime-sanitizer.c @@ -1,12 +1,13 @@ -// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=CHECK-O0 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \ -// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \ -// RUN: FileCheck %s -check-prefix=LIFETIME +// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefix=CHECK-O0 +// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \ +// RUN: -fsanitize=address -fsanitize-address-use-after-scope \ +// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefix=LIFETIME // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \ -// RUN: -fsanitize=memory %s | \ +// RUN: -fsanitize=memory -Xclang -disable-llvm-passes %s | \ // RUN: FileCheck %s -check-prefix=LIFETIME // RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o - -O0 \ -// RUN: -fsanitize=hwaddress %s | \ +// RUN: -fsanitize=hwaddress -Xclang -disable-llvm-passes %s | \ // RUN: FileCheck %s -check-prefix=LIFETIME extern int bar(char *A, int n); diff --git a/clang/test/CodeGenCXX/lifetime-sanitizer.cpp b/clang/test/CodeGenCXX/lifetime-sanitizer.cpp index 3cce664689598..8c7900294ef40 100644 --- a/clang/test/CodeGenCXX/lifetime-sanitizer.cpp +++ b/clang/test/CodeGenCXX/lifetime-sanitizer.cpp @@ -1,13 +1,14 @@ -// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 %s | \ -// RUN: FileCheck %s -check-prefixes=CHECK --implicit-check-not=llvm.lifetime // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \ -// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \ -// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME +// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK \ +// RUN: --implicit-check-not=llvm.lifetime +// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \ +// RUN: -fsanitize=address -fsanitize-address-use-after-scope \ +// RUN: -Xclang -disable-llvm-passes %s | FileCheck %s -check-prefixes=CHECK,LIFETIME // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \ -// RUN: -fsanitize=memory %s | \ +// RUN: -fsanitize=memory -Xclang -disable-llvm-passes %s | \ // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME // RUN: %clang -w -target aarch64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \ -// RUN: -fsanitize=hwaddress %s | \ +// RUN: -fsanitize=hwaddress -Xclang -disable-llvm-passes %s | \ // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME extern int bar(char *A, int n); diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 350f9701d48d4..2b9e8655e4c93 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1371,12 +1371,12 @@ bool HWAddressSanitizer::instrumentStack( tagAlloca(IRB, AI, Tag, Size); for (auto *RI : SInfo.RetVec) TagEnd(RI); - if (!StandardLifetime) { -for (auto &II : Info.LifetimeStart) - II->eraseFromParent(); -for (auto &II : Info.LifetimeEnd) - II->eraseFromParent(); - } + // We inserted tagging outside of the lifetimes, so we have to remove + // them. + for (auto &II : Info.LifetimeStart) +II->eraseFromParent(); + for (auto &II : Info.LifetimeEnd) +II->eraseFromParent(); } memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment())); } diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll index 907fe026682c2..85309819a2eb9 100644 --- a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll +++ b/llvm/test/Instrumentation/HWAddressSanitiz
[clang] [compiler-rt] [clang][compiler-rt][test] Removed dirname command substitutions from tests (PR #105754)
@@ -1,8 +1,9 @@ -// RUN: %clang_hwasan -Wl,--build-id -g %s -o %t -// RUN: echo '[{"prefix": "'"$(realpath $(dirname %s))"'/", "link": "http://test.invalid/{file}:{line}"}]' > %t.linkify -// RUN: %env_hwasan_opts=symbolize=0 not %run %t 2>&1 | hwasan_symbolize --html --symbols $(dirname %t) --index | FileCheck %s -// RUN: %env_hwasan_opts=symbolize=0 not %run %t 2>&1 | hwasan_symbolize --html --linkify %t.linkify --symbols $(dirname %t) --index | FileCheck --check-prefixes=CHECK,LINKIFY %s -// RUN: %env_hwasan_opts=symbolize=0 not %run %t 2>&1 | hwasan_symbolize --symbols $(dirname %t) --index | FileCheck %s +// RUN: rm -rf %t && mkdir -p %t +// RUN: %clang_hwasan -Wl,--build-id -g %s -o %t/symbolize.exe fmayer wrote: `symbolize.exe` is a bit of a confusing name. `hwasan_symbolize_test`? https://github.com/llvm/llvm-project/pull/105754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [clang][compiler-rt][test] Removed dirname command substitutions from tests (PR #105754)
https://github.com/fmayer approved this pull request. LGTM for the hwasan test. https://github.com/llvm/llvm-project/pull/105754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [flang] Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (PR #108453)
fmayer wrote: This caused a UBSan violation: ``` [--] 1 test from ConfigCompileTests [ RUN ] ConfigCompileTests.DiagnosticSuppression Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false) /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33: runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33 -- exit: 1 -- ``` https://github.com/llvm/llvm-project/pull/108453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[clang] Silence GCC warnings about control reaching end of non void function" (PR #108646)
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/108646 This reverts commit 90a2e0bb423629b7e70f4b91adb44851199dd5ea. Reverting parent CL >From 6bc1ea84e078d01546286e6443d761e2a685902d Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 13 Sep 2024 14:02:14 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/include/clang/Basic/DiagnosticIDs.h | 2 -- clang/lib/Sema/SemaOverload.cpp | 1 - 2 files changed, 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticIDs.h b/clang/include/clang/Basic/DiagnosticIDs.h index daad66f499538f..2402996ece5c94 100644 --- a/clang/include/clang/Basic/DiagnosticIDs.h +++ b/clang/include/clang/Basic/DiagnosticIDs.h @@ -18,7 +18,6 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/ErrorHandling.h" #include #include @@ -311,7 +310,6 @@ class DiagnosticIDs : public RefCountedBase { return {diag::Severity::Fatal, std::string(Message), CLASS_ERROR, /*ShowInSystemHeader*/ true}; } - llvm_unreachable("Fully covered switch above!"); }()); } diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 382630ed674107..d3e009a658f0e8 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7331,7 +7331,6 @@ static bool diagnoseDiagnoseIfAttrsWith(Sema &S, const NamedDecl *ND, case DiagnoseIfAttr::DS_error: return diag::Severity::Error; } -llvm_unreachable("Fully covered switch above!"); }; for (const auto *DIA : llvm::make_range(WarningBegin, Attrs.end())) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f885e02 - Revert "[clang] Silence GCC warnings about control reaching end of non void function"
Author: Florian Mayer Date: 2024-09-13T15:01:27-07:00 New Revision: f885e02cf7cac1b08cab4cd526773420076029dd URL: https://github.com/llvm/llvm-project/commit/f885e02cf7cac1b08cab4cd526773420076029dd DIFF: https://github.com/llvm/llvm-project/commit/f885e02cf7cac1b08cab4cd526773420076029dd.diff LOG: Revert "[clang] Silence GCC warnings about control reaching end of non void function" This reverts commit 90a2e0bb423629b7e70f4b91adb44851199dd5ea. Reverting parent CL Pull Request: https://github.com/llvm/llvm-project/pull/108646 Added: Modified: clang/include/clang/Basic/DiagnosticIDs.h clang/lib/Sema/SemaOverload.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticIDs.h b/clang/include/clang/Basic/DiagnosticIDs.h index daad66f499538f..2402996ece5c94 100644 --- a/clang/include/clang/Basic/DiagnosticIDs.h +++ b/clang/include/clang/Basic/DiagnosticIDs.h @@ -18,7 +18,6 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/ErrorHandling.h" #include #include @@ -311,7 +310,6 @@ class DiagnosticIDs : public RefCountedBase { return {diag::Severity::Fatal, std::string(Message), CLASS_ERROR, /*ShowInSystemHeader*/ true}; } - llvm_unreachable("Fully covered switch above!"); }()); } diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 382630ed674107..d3e009a658f0e8 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7331,7 +7331,6 @@ static bool diagnoseDiagnoseIfAttrsWith(Sema &S, const NamedDecl *ND, case DiagnoseIfAttr::DS_error: return diag::Severity::Error; } -llvm_unreachable("Fully covered switch above!"); }; for (const auto *DIA : llvm::make_range(WarningBegin, Attrs.end())) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e1bd974 - Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)"
Author: Florian Mayer Date: 2024-09-13T15:01:33-07:00 New Revision: e1bd9740faa62c11cc785a7b70ec1ad17e286bd1 URL: https://github.com/llvm/llvm-project/commit/e1bd9740faa62c11cc785a7b70ec1ad17e286bd1 DIFF: https://github.com/llvm/llvm-project/commit/e1bd9740faa62c11cc785a7b70ec1ad17e286bd1.diff LOG: Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22. This had UBSan failures: [--] 1 test from ConfigCompileTests [ RUN ] ConfigCompileTests.DiagnosticSuppression Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false) /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33: runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs' UndefinedBehaviorSanitizer: undefined-behavior /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33 Pull Request: https://github.com/llvm/llvm-project/pull/108645 Added: Modified: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/Diagnostics.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp clang/include/clang/Basic/Attr.td clang/include/clang/Basic/Diagnostic.h clang/include/clang/Basic/DiagnosticCategories.h clang/include/clang/Basic/DiagnosticIDs.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/Diagnostic.cpp clang/lib/Basic/DiagnosticIDs.cpp clang/lib/Frontend/LogDiagnosticPrinter.cpp clang/lib/Frontend/SerializedDiagnosticPrinter.cpp clang/lib/Frontend/TextDiagnosticPrinter.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaCUDA.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp clang/test/Sema/diagnose_if.c clang/tools/diagtool/ListWarnings.cpp clang/tools/diagtool/ShowEnabledWarnings.cpp clang/tools/libclang/CXStoredDiagnostic.cpp flang/lib/Frontend/TextDiagnosticPrinter.cpp Removed: clang/test/SemaCXX/diagnose_if-warning-group.cpp diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index 552dd36b6900bf..d5eca083eb6512 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -579,17 +579,7 @@ std::vector StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) { for (auto &Diag : Output) { if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) { // Warnings controlled by -Wfoo are better recognized by that name. - const StringRef Warning = [&] { -if (OrigSrcMgr) { - return OrigSrcMgr->getDiagnostics() - .getDiagnosticIDs() - ->getWarningOptionForDiag(Diag.ID); -} -if (!DiagnosticIDs::IsCustomDiag(Diag.ID)) - return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID); -return StringRef{}; - }(); - + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID); if (!Warning.empty()) { Diag.Name = ("-W" + Warning).str(); } else { @@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() { Output.push_back(std::move(*LastDiag)); } -bool isDiagnosticSuppressed(const clang::Diagnostic &Diag, -const llvm::StringSet<> &Suppress, -const LangOptions &LangOpts) { +bool isBuiltinDiagnosticSuppressed(unsigned ID, + const llvm::StringSet<> &Suppress, + const LangOptions &LangOpts) { // Don't complain about header-only stuff in mainfiles if it's a header. // FIXME: would be cleaner to suppress in clang, once we decide whether the //behavior should be to silently-ignore or respect the pragma. - if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file && - LangOpts.IsHeaderFile) + if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile) return true; - if (const char *CodePtr = getDiagnosticCode(Diag.getID())) { + if (const char *CodePtr = getDiagnosticCode(ID)) { if (Suppress.contains(normalizeSuppressedCode(CodePtr))) return true; } - StringRef Warning = - Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag( - Diag.getID()); + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID); if (!Warning.empty() && Suppress.contains(Warning)) return true; return false; diff --git a/clang-tools-extra/clangd/Diagnostics.h b/clang-tools-extra/clangd/Diagnostics.h index c45
[clang-tools-extra] e1bd974 - Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)"
Author: Florian Mayer Date: 2024-09-13T15:01:33-07:00 New Revision: e1bd9740faa62c11cc785a7b70ec1ad17e286bd1 URL: https://github.com/llvm/llvm-project/commit/e1bd9740faa62c11cc785a7b70ec1ad17e286bd1 DIFF: https://github.com/llvm/llvm-project/commit/e1bd9740faa62c11cc785a7b70ec1ad17e286bd1.diff LOG: Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22. This had UBSan failures: [--] 1 test from ConfigCompileTests [ RUN ] ConfigCompileTests.DiagnosticSuppression Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false) /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33: runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs' UndefinedBehaviorSanitizer: undefined-behavior /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33 Pull Request: https://github.com/llvm/llvm-project/pull/108645 Added: Modified: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/Diagnostics.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp clang/include/clang/Basic/Attr.td clang/include/clang/Basic/Diagnostic.h clang/include/clang/Basic/DiagnosticCategories.h clang/include/clang/Basic/DiagnosticIDs.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/Diagnostic.cpp clang/lib/Basic/DiagnosticIDs.cpp clang/lib/Frontend/LogDiagnosticPrinter.cpp clang/lib/Frontend/SerializedDiagnosticPrinter.cpp clang/lib/Frontend/TextDiagnosticPrinter.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaCUDA.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp clang/test/Sema/diagnose_if.c clang/tools/diagtool/ListWarnings.cpp clang/tools/diagtool/ShowEnabledWarnings.cpp clang/tools/libclang/CXStoredDiagnostic.cpp flang/lib/Frontend/TextDiagnosticPrinter.cpp Removed: clang/test/SemaCXX/diagnose_if-warning-group.cpp diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index 552dd36b6900bf..d5eca083eb6512 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -579,17 +579,7 @@ std::vector StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) { for (auto &Diag : Output) { if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) { // Warnings controlled by -Wfoo are better recognized by that name. - const StringRef Warning = [&] { -if (OrigSrcMgr) { - return OrigSrcMgr->getDiagnostics() - .getDiagnosticIDs() - ->getWarningOptionForDiag(Diag.ID); -} -if (!DiagnosticIDs::IsCustomDiag(Diag.ID)) - return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID); -return StringRef{}; - }(); - + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID); if (!Warning.empty()) { Diag.Name = ("-W" + Warning).str(); } else { @@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() { Output.push_back(std::move(*LastDiag)); } -bool isDiagnosticSuppressed(const clang::Diagnostic &Diag, -const llvm::StringSet<> &Suppress, -const LangOptions &LangOpts) { +bool isBuiltinDiagnosticSuppressed(unsigned ID, + const llvm::StringSet<> &Suppress, + const LangOptions &LangOpts) { // Don't complain about header-only stuff in mainfiles if it's a header. // FIXME: would be cleaner to suppress in clang, once we decide whether the //behavior should be to silently-ignore or respect the pragma. - if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file && - LangOpts.IsHeaderFile) + if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile) return true; - if (const char *CodePtr = getDiagnosticCode(Diag.getID())) { + if (const char *CodePtr = getDiagnosticCode(ID)) { if (Suppress.contains(normalizeSuppressedCode(CodePtr))) return true; } - StringRef Warning = - Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag( - Diag.getID()); + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID); if (!Warning.empty() && Suppress.contains(Warning)) return true; return false; diff --git a/clang-tools-extra/clangd/Diagnostics.h b/clang-tools-extra/clangd/Diagnostics.h index c45
[clang] Revert "[clang] Silence GCC warnings about control reaching end of non void function" (PR #108646)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/108646 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/112050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer ready_for_review https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -764,11 +764,17 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) +Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { +assert(!GV->hasSection()); fmayer wrote: It is in `shouldTagGlobal` https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Apply alignment / size in linker rather than IR (PR #111918)
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/111918 This greatly simplifies the code, and makes sure no optimizations are applied that assume the bigger alignment or size, which could be incorrect if we link together with non-instrumented code. >From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 10 Oct 2024 16:05:50 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/SanitizerMetadata.cpp | 45 - llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 7 +- llvm/lib/Target/AArch64/AArch64.h | 2 - .../Target/AArch64/AArch64GlobalsTagging.cpp | 155 -- .../Target/AArch64/AArch64TargetMachine.cpp | 2 - llvm/lib/Target/AArch64/CMakeLists.txt| 1 - .../llvm/lib/Target/AArch64/BUILD.gn | 1 - 7 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 5b212a163611dc..784d9061647f5c 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -34,6 +34,37 @@ static SanitizerMask expandKernelSanitizerMasks(SanitizerMask Mask) { return Mask; } +static bool shouldTagGlobal(const llvm::GlobalVariable &G) { + // For now, don't instrument constant data, as it'll be in .rodata anyway. It + // may be worth instrumenting these in future to stop them from being used as + // gadgets. + if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant()) +return false; + + // Globals can be placed implicitly or explicitly in sections. There's two + // different types of globals that meet this criteria that cause problems: + // 1. Function pointers that are going into various init arrays (either + // explicitly through `__attribute__((section()))` or implicitly + // through `__attribute__((constructor)))`, such as ".(pre)init(_array)", + // ".fini(_array)", ".ctors", and ".dtors". These function pointers end up + // overaligned and overpadded, making iterating over them problematic, and + // each function pointer is individually tagged (so the iteration over + // them causes SIGSEGV/MTE[AS]ERR). + // 2. Global variables put into an explicit section, where the section's name + // is a valid C-style identifier. The linker emits a `__start_` and + // `__stop_` symbol for the section, so that you can iterate over + // globals within this section. Unfortunately, again, these globals would + // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR. + // + // To mitigate both these cases, and because specifying a section is rare + // outside of these two cases, disable MTE protection for globals in any + // section. + if (G.hasSection()) +return false; + + return true; +} + void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, StringRef Name, QualType Ty, @@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.Memtag |= - static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); - Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.Memtag &= !CGM.isInNoSanitizeList( - FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + if (shouldTagGlobal(*GV)) { +Meta.Memtag |= +static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); +Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); +Meta.Memtag &= !CGM.isInNoSanitizeList( +FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + } else { +Meta.Memtag = false; + } Meta.IsDynInit = IsDynInit && !Meta.NoAddress && FsanitizeArgument.has(SanitizerKind::Address) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc0..6a2817f417d30d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata).
[clang] [llvm] Apply alignment / size in linker rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 >From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 10 Oct 2024 16:05:50 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/SanitizerMetadata.cpp | 45 - llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 7 +- llvm/lib/Target/AArch64/AArch64.h | 2 - .../Target/AArch64/AArch64GlobalsTagging.cpp | 155 -- .../Target/AArch64/AArch64TargetMachine.cpp | 2 - llvm/lib/Target/AArch64/CMakeLists.txt| 1 - .../llvm/lib/Target/AArch64/BUILD.gn | 1 - 7 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 5b212a163611dc..784d9061647f5c 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -34,6 +34,37 @@ static SanitizerMask expandKernelSanitizerMasks(SanitizerMask Mask) { return Mask; } +static bool shouldTagGlobal(const llvm::GlobalVariable &G) { + // For now, don't instrument constant data, as it'll be in .rodata anyway. It + // may be worth instrumenting these in future to stop them from being used as + // gadgets. + if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant()) +return false; + + // Globals can be placed implicitly or explicitly in sections. There's two + // different types of globals that meet this criteria that cause problems: + // 1. Function pointers that are going into various init arrays (either + // explicitly through `__attribute__((section()))` or implicitly + // through `__attribute__((constructor)))`, such as ".(pre)init(_array)", + // ".fini(_array)", ".ctors", and ".dtors". These function pointers end up + // overaligned and overpadded, making iterating over them problematic, and + // each function pointer is individually tagged (so the iteration over + // them causes SIGSEGV/MTE[AS]ERR). + // 2. Global variables put into an explicit section, where the section's name + // is a valid C-style identifier. The linker emits a `__start_` and + // `__stop_` symbol for the section, so that you can iterate over + // globals within this section. Unfortunately, again, these globals would + // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR. + // + // To mitigate both these cases, and because specifying a section is rare + // outside of these two cases, disable MTE protection for globals in any + // section. + if (G.hasSection()) +return false; + + return true; +} + void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, StringRef Name, QualType Ty, @@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.Memtag |= - static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); - Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.Memtag &= !CGM.isInNoSanitizeList( - FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + if (shouldTagGlobal(*GV)) { +Meta.Memtag |= +static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); +Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); +Meta.Memtag &= !CGM.isInNoSanitizeList( +FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + } else { +Meta.Memtag = false; + } Meta.IsDynInit = IsDynInit && !Meta.NoAddress && FsanitizeArgument.has(SanitizerKind::Address) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc0..6a2817f417d30d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { +assert(!GV->hasSection()); +Alignment = Al
[clang] [llvm] [MTE] Apply alignment / size in linker rather than IR (PR #111918)
https://github.com/fmayer edited https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer edited https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 >From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 10 Oct 2024 16:05:50 -0700 Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/SanitizerMetadata.cpp | 45 - llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 7 +- llvm/lib/Target/AArch64/AArch64.h | 2 - .../Target/AArch64/AArch64GlobalsTagging.cpp | 155 -- .../Target/AArch64/AArch64TargetMachine.cpp | 2 - llvm/lib/Target/AArch64/CMakeLists.txt| 1 - .../llvm/lib/Target/AArch64/BUILD.gn | 1 - 7 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 5b212a163611dc..784d9061647f5c 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -34,6 +34,37 @@ static SanitizerMask expandKernelSanitizerMasks(SanitizerMask Mask) { return Mask; } +static bool shouldTagGlobal(const llvm::GlobalVariable &G) { + // For now, don't instrument constant data, as it'll be in .rodata anyway. It + // may be worth instrumenting these in future to stop them from being used as + // gadgets. + if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant()) +return false; + + // Globals can be placed implicitly or explicitly in sections. There's two + // different types of globals that meet this criteria that cause problems: + // 1. Function pointers that are going into various init arrays (either + // explicitly through `__attribute__((section()))` or implicitly + // through `__attribute__((constructor)))`, such as ".(pre)init(_array)", + // ".fini(_array)", ".ctors", and ".dtors". These function pointers end up + // overaligned and overpadded, making iterating over them problematic, and + // each function pointer is individually tagged (so the iteration over + // them causes SIGSEGV/MTE[AS]ERR). + // 2. Global variables put into an explicit section, where the section's name + // is a valid C-style identifier. The linker emits a `__start_` and + // `__stop_` symbol for the section, so that you can iterate over + // globals within this section. Unfortunately, again, these globals would + // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR. + // + // To mitigate both these cases, and because specifying a section is rare + // outside of these two cases, disable MTE protection for globals in any + // section. + if (G.hasSection()) +return false; + + return true; +} + void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, StringRef Name, QualType Ty, @@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.Memtag |= - static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); - Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.Memtag &= !CGM.isInNoSanitizeList( - FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + if (shouldTagGlobal(*GV)) { +Meta.Memtag |= +static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); +Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); +Meta.Memtag &= !CGM.isInNoSanitizeList( +FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + } else { +Meta.Memtag = false; + } Meta.IsDynInit = IsDynInit && !Meta.NoAddress && FsanitizeArgument.has(SanitizerKind::Address) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc0..6a2817f417d30d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { +assert(!GV->hasSection()); +Alignment = Al
[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/112050 >From 78e91cb54bed6ee8deda61a054776bbd3102d79d Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 11 Oct 2024 14:28:59 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/test/CodeGen/memtag-globals.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/memtag-globals.cpp b/clang/test/CodeGen/memtag-globals.cpp index b4f5dc0d7dcf04..d1252cdcd67a15 100644 --- a/clang/test/CodeGen/memtag-globals.cpp +++ b/clang/test/CodeGen/memtag-globals.cpp @@ -1,12 +1,15 @@ -// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ +// RUN: %clang_cc1 -triple aarch64-linux-android34 \ +// RUN: -include %S/Inputs/sanitizer-extra-source.cpp \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ +// RUN: %clang_cc1 -triple aarch64-linux-android34 \ +// RUN:-include %S/Inputs/sanitizer-extra-source.cpp \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=IGNORELIST + int global; int __attribute__((no_sanitize("memtag"))) attributed_global; int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global; >From b04074e4f05cb7ea89d3701f277af9262dfeb522 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 11 Oct 2024 14:31:31 -0700 Subject: [PATCH 2/2] fmt Created using spr 1.3.4 --- clang/test/CodeGen/memtag-globals.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/test/CodeGen/memtag-globals.cpp b/clang/test/CodeGen/memtag-globals.cpp index d1252cdcd67a15..ae2d32ae8a56d9 100644 --- a/clang/test/CodeGen/memtag-globals.cpp +++ b/clang/test/CodeGen/memtag-globals.cpp @@ -9,7 +9,6 @@ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=IGNORELIST - int global; int __attribute__((no_sanitize("memtag"))) attributed_global; int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/112050 It doesn't make a difference currently, but MTE globals are only supported on Android, so that's the more natural target to use. >From 78e91cb54bed6ee8deda61a054776bbd3102d79d Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 11 Oct 2024 14:28:59 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/test/CodeGen/memtag-globals.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/memtag-globals.cpp b/clang/test/CodeGen/memtag-globals.cpp index b4f5dc0d7dcf04..d1252cdcd67a15 100644 --- a/clang/test/CodeGen/memtag-globals.cpp +++ b/clang/test/CodeGen/memtag-globals.cpp @@ -1,12 +1,15 @@ -// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ +// RUN: %clang_cc1 -triple aarch64-linux-android34 \ +// RUN: -include %S/Inputs/sanitizer-extra-source.cpp \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ +// RUN: %clang_cc1 -triple aarch64-linux-android34 \ +// RUN:-include %S/Inputs/sanitizer-extra-source.cpp \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=IGNORELIST + int global; int __attribute__((no_sanitize("memtag"))) attributed_global; int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 >From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 10 Oct 2024 16:05:50 -0700 Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/SanitizerMetadata.cpp | 45 - llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 7 +- llvm/lib/Target/AArch64/AArch64.h | 2 - .../Target/AArch64/AArch64GlobalsTagging.cpp | 155 -- .../Target/AArch64/AArch64TargetMachine.cpp | 2 - llvm/lib/Target/AArch64/CMakeLists.txt| 1 - .../llvm/lib/Target/AArch64/BUILD.gn | 1 - 7 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 5b212a163611dc..784d9061647f5c 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -34,6 +34,37 @@ static SanitizerMask expandKernelSanitizerMasks(SanitizerMask Mask) { return Mask; } +static bool shouldTagGlobal(const llvm::GlobalVariable &G) { + // For now, don't instrument constant data, as it'll be in .rodata anyway. It + // may be worth instrumenting these in future to stop them from being used as + // gadgets. + if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant()) +return false; + + // Globals can be placed implicitly or explicitly in sections. There's two + // different types of globals that meet this criteria that cause problems: + // 1. Function pointers that are going into various init arrays (either + // explicitly through `__attribute__((section()))` or implicitly + // through `__attribute__((constructor)))`, such as ".(pre)init(_array)", + // ".fini(_array)", ".ctors", and ".dtors". These function pointers end up + // overaligned and overpadded, making iterating over them problematic, and + // each function pointer is individually tagged (so the iteration over + // them causes SIGSEGV/MTE[AS]ERR). + // 2. Global variables put into an explicit section, where the section's name + // is a valid C-style identifier. The linker emits a `__start_` and + // `__stop_` symbol for the section, so that you can iterate over + // globals within this section. Unfortunately, again, these globals would + // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR. + // + // To mitigate both these cases, and because specifying a section is rare + // outside of these two cases, disable MTE protection for globals in any + // section. + if (G.hasSection()) +return false; + + return true; +} + void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, StringRef Name, QualType Ty, @@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.Memtag |= - static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); - Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.Memtag &= !CGM.isInNoSanitizeList( - FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + if (shouldTagGlobal(*GV)) { +Meta.Memtag |= +static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); +Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); +Meta.Memtag &= !CGM.isInNoSanitizeList( +FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + } else { +Meta.Memtag = false; + } Meta.IsDynInit = IsDynInit && !Meta.NoAddress && FsanitizeArgument.has(SanitizerKind::Address) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc0..6a2817f417d30d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { +assert(!GV->hasSection()); +Alignment = Al
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -764,11 +764,18 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) +Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { fmayer wrote: Yes, but I think it's nicer for this and the Size change to be in the same place. https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
@@ -764,11 +764,18 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) +Size = alignTo(Size, 16); fmayer wrote: We don't need the padding to be initialized to anything in particular, the code shouldn't use it (other than its tag memory) https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)
@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the ``verbosity=$NUM`` flag: misspelled_flag ... -Disabling -- +Disabling and suppressing +- -In some circumstances, you may want to suppress error reporting in a specific scope. +There are multiple ways to suppress error reporting when using RealtimeSanitizer. -In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively. +In general, ``ScopedDisabler`` should be preferred, as it is the most performant. + +.. list-table:: Suppression methods + :widths: 30 15 15 10 70 + :header-rows: 1 + + * - Suppression method + - Specified at? + - Scope + - Run-time cost + - Description + * - ``ScopedDisabler`` + - Compile-time + - Stack + - Very low + - Suppresses all sanitizer error reports in the current scope and all invoked functions. fmayer wrote: > sanitizer error reports should this specify that this is about RTSan specifically? https://github.com/llvm/llvm-project/pull/112727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)
@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the ``verbosity=$NUM`` flag: misspelled_flag ... -Disabling -- +Disabling and suppressing +- -In some circumstances, you may want to suppress error reporting in a specific scope. +There are multiple ways to suppress error reporting when using RealtimeSanitizer. -In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively. +In general, ``ScopedDisabler`` should be preferred, as it is the most performant. + +.. list-table:: Suppression methods + :widths: 30 15 15 10 70 + :header-rows: 1 + + * - Suppression method + - Specified at? + - Scope + - Run-time cost + - Description + * - ``ScopedDisabler`` + - Compile-time + - Stack + - Very low + - Suppresses all sanitizer error reports in the current scope and all invoked functions. + * - ``function-name-matches`` suppression + - Run-time + - Single function + - Medium + - Suppresses intercepted and ``[[clang::blocking]]`` function calls by name. + * - ``call-stack-contains`` suppression + - Run-time + - Stack + - High + - Suppresses any stack trace contaning the specified pattern. + + +``ScopedDisabler`` +## + +At compile time, RealtimeSanitizer may be disabled for a scope using ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively. fmayer wrote: for explicit completeness, specify that this is thread-local (which I guess it is)? https://github.com/llvm/llvm-project/pull/112727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR (PR #111055)
fmayer wrote: > With the function effects warnings (as errors) activated, blocking functions > cannot be called from non-blocking functions, and this is enforced at compile > time. The purpose of this series of PRs is to introduce similar functionality > into RealtimeSanitizer, so that it can make the equivalent check at run time. What is the reason we need to check something again at runtime that was already checked at compile-time? In case people didn't `-Werror` the warning? https://github.com/llvm/llvm-project/pull/111055 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR (PR #111055)
fmayer wrote: > > > With the function effects warnings (as errors) activated, blocking > > > functions cannot be called from non-blocking functions, and this is > > > enforced at compile time. The purpose of this series of PRs is to > > > introduce similar functionality into RealtimeSanitizer, so that it can > > > make the equivalent check at run time. > > > > > > What is the reason we need to check something again at runtime that was > > already checked at compile-time? In case people didn't `-Werror` the > > warning? > > Yes indeed - that's one of a few scenarios where we believe this is needed: > > * the user didn't compile with `-Werror`, > * the user didn't compile with `-Wfunction-effects` (i.e. no checking at > compile time happens), > * the `[[clang::blocking]]` function is called deep within the call stack of > a higher-level `[[clang::nonblocking]]` function, or maybe even > * the `[[clang::blocking]]` function is pre-compiled in a different library > to what the user is compiling. > > RTSan differs from the performance constraints attributes in that it only > flags violations that happen at run time, in contrast to flagging those that > _could_ happen at compile time. In this scenario, if a `[[clang::blocking]]` > call exists somewhere in the code within a `[[clang::nonblocking]]` function, > rtsan does not consider it a violation until it's called. Depending on the > user's needs they may consider this either good or bad - there are pros and > cons to it, of course. RTSan takes an "innocent until proven guilty" > approach, whereas performance constraints are more pessimistically "guilty > until proven innocent" - and we think both are very useful. > > One of the design goals of the works was that these systems should be able to > be used easily together, or separately, and that they should have analogous > functionalities where possible. Hope that makes some sense! Thanks for confirming. Optionally mention this somewhere in a comment in the code for future reference. https://github.com/llvm/llvm-project/pull/111055 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR (PR #111055)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/111055 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)
fmayer wrote: > I would suggest a brief comment explaining the choice not to filter. I'm not sure I understand. There wasn't a choice to filter before, there was just the (incorrect) assumption that we don't have nested `RecordStorageLocation`, leading to a crash. https://github.com/llvm/llvm-project/pull/112457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [MTE] Use aarch64-linux-android34 for globals test (PR #112050)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/112050 >From 78e91cb54bed6ee8deda61a054776bbd3102d79d Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 11 Oct 2024 14:28:59 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/test/CodeGen/memtag-globals.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/test/CodeGen/memtag-globals.cpp b/clang/test/CodeGen/memtag-globals.cpp index b4f5dc0d7dcf04..d1252cdcd67a15 100644 --- a/clang/test/CodeGen/memtag-globals.cpp +++ b/clang/test/CodeGen/memtag-globals.cpp @@ -1,12 +1,15 @@ -// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ +// RUN: %clang_cc1 -triple aarch64-linux-android34 \ +// RUN: -include %S/Inputs/sanitizer-extra-source.cpp \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ +// RUN: %clang_cc1 -triple aarch64-linux-android34 \ +// RUN:-include %S/Inputs/sanitizer-extra-source.cpp \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=IGNORELIST + int global; int __attribute__((no_sanitize("memtag"))) attributed_global; int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global; >From b04074e4f05cb7ea89d3701f277af9262dfeb522 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 11 Oct 2024 14:31:31 -0700 Subject: [PATCH 2/2] fmt Created using spr 1.3.4 --- clang/test/CodeGen/memtag-globals.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/test/CodeGen/memtag-globals.cpp b/clang/test/CodeGen/memtag-globals.cpp index d1252cdcd67a15..ae2d32ae8a56d9 100644 --- a/clang/test/CodeGen/memtag-globals.cpp +++ b/clang/test/CodeGen/memtag-globals.cpp @@ -9,7 +9,6 @@ // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | \ // RUN: FileCheck %s --check-prefix=IGNORELIST - int global; int __attribute__((no_sanitize("memtag"))) attributed_global; int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan][NFC] Add documentation link to Function Effects (PR #113979)
@@ -11,11 +11,16 @@ RealtimeSanitizer (a.k.a. RTSan) is a real-time safety testing tool for C and C+ projects. RTSan can be used to detect real-time violations, i.e. calls to methods that are not safe for use in functions with deterministic run time requirements. RTSan considers any function marked with the ``[[clang::nonblocking]]`` attribute -to be a real-time function. If RTSan detects a call to ``malloc``, ``free``, -``pthread_mutex_lock``, or anything else that could have a non-deterministic -execution time in a function marked ``[[clang::nonblocking]]`` +to be a real-time function. At run-time, if RTSan detects a call to ``malloc``, +``free``, ``pthread_mutex_lock``, or anything else that could have a +non-deterministic execution time in a function marked ``[[clang::nonblocking]]`` fmayer wrote: > or anything else that could have a non-deterministic execution time that sounds like a guarantee. Isn't it more things that we _know_ to have a non-deterministic runtime https://github.com/llvm/llvm-project/pull/113979 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan][NFC] Add documentation link to Function Effects (PR #113979)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/113979 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan][asan] NFC Fix hyperlink to CMake doc (PR #113931)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/113931 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)
fmayer wrote: > I think this is the right change. > > What I don't understand, though, is why you were getting an assert failure > before. (Which line is the assertion on that failed?) I would have thought if > you don't dump the nested record, you just get less information. Apparently > not so? Because the first line of `Env.getValue` is assert(!isa(Loc)); ``` https://github.com/llvm/llvm-project/pull/112457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/112727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)
https://github.com/fmayer closed https://github.com/llvm/llvm-project/pull/112457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer edited https://github.com/llvm/llvm-project/pull/111918 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 >From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 10 Oct 2024 16:05:50 -0700 Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/SanitizerMetadata.cpp | 45 - llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 7 +- llvm/lib/Target/AArch64/AArch64.h | 2 - .../Target/AArch64/AArch64GlobalsTagging.cpp | 155 -- .../Target/AArch64/AArch64TargetMachine.cpp | 2 - llvm/lib/Target/AArch64/CMakeLists.txt| 1 - .../llvm/lib/Target/AArch64/BUILD.gn | 1 - 7 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 5b212a163611dc..784d9061647f5c 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -34,6 +34,37 @@ static SanitizerMask expandKernelSanitizerMasks(SanitizerMask Mask) { return Mask; } +static bool shouldTagGlobal(const llvm::GlobalVariable &G) { + // For now, don't instrument constant data, as it'll be in .rodata anyway. It + // may be worth instrumenting these in future to stop them from being used as + // gadgets. + if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant()) +return false; + + // Globals can be placed implicitly or explicitly in sections. There's two + // different types of globals that meet this criteria that cause problems: + // 1. Function pointers that are going into various init arrays (either + // explicitly through `__attribute__((section()))` or implicitly + // through `__attribute__((constructor)))`, such as ".(pre)init(_array)", + // ".fini(_array)", ".ctors", and ".dtors". These function pointers end up + // overaligned and overpadded, making iterating over them problematic, and + // each function pointer is individually tagged (so the iteration over + // them causes SIGSEGV/MTE[AS]ERR). + // 2. Global variables put into an explicit section, where the section's name + // is a valid C-style identifier. The linker emits a `__start_` and + // `__stop_` symbol for the section, so that you can iterate over + // globals within this section. Unfortunately, again, these globals would + // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR. + // + // To mitigate both these cases, and because specifying a section is rare + // outside of these two cases, disable MTE protection for globals in any + // section. + if (G.hasSection()) +return false; + + return true; +} + void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, StringRef Name, QualType Ty, @@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.Memtag |= - static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); - Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.Memtag &= !CGM.isInNoSanitizeList( - FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + if (shouldTagGlobal(*GV)) { +Meta.Memtag |= +static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); +Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); +Meta.Memtag &= !CGM.isInNoSanitizeList( +FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + } else { +Meta.Memtag = false; + } Meta.IsDynInit = IsDynInit && !Meta.NoAddress && FsanitizeArgument.has(SanitizerKind::Address) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc0..6a2817f417d30d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { +assert(!GV->hasSection()); +Alignment = Al
[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/111918 >From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 10 Oct 2024 16:05:50 -0700 Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/SanitizerMetadata.cpp | 45 - llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 7 +- llvm/lib/Target/AArch64/AArch64.h | 2 - .../Target/AArch64/AArch64GlobalsTagging.cpp | 155 -- .../Target/AArch64/AArch64TargetMachine.cpp | 2 - llvm/lib/Target/AArch64/CMakeLists.txt| 1 - .../llvm/lib/Target/AArch64/BUILD.gn | 1 - 7 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 5b212a163611dc..784d9061647f5c 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -34,6 +34,37 @@ static SanitizerMask expandKernelSanitizerMasks(SanitizerMask Mask) { return Mask; } +static bool shouldTagGlobal(const llvm::GlobalVariable &G) { + // For now, don't instrument constant data, as it'll be in .rodata anyway. It + // may be worth instrumenting these in future to stop them from being used as + // gadgets. + if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant()) +return false; + + // Globals can be placed implicitly or explicitly in sections. There's two + // different types of globals that meet this criteria that cause problems: + // 1. Function pointers that are going into various init arrays (either + // explicitly through `__attribute__((section()))` or implicitly + // through `__attribute__((constructor)))`, such as ".(pre)init(_array)", + // ".fini(_array)", ".ctors", and ".dtors". These function pointers end up + // overaligned and overpadded, making iterating over them problematic, and + // each function pointer is individually tagged (so the iteration over + // them causes SIGSEGV/MTE[AS]ERR). + // 2. Global variables put into an explicit section, where the section's name + // is a valid C-style identifier. The linker emits a `__start_` and + // `__stop_` symbol for the section, so that you can iterate over + // globals within this section. Unfortunately, again, these globals would + // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR. + // + // To mitigate both these cases, and because specifying a section is rare + // outside of these two cases, disable MTE protection for globals in any + // section. + if (G.hasSection()) +return false; + + return true; +} + void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc, StringRef Name, QualType Ty, @@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.Memtag |= - static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); - Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.Memtag &= !CGM.isInNoSanitizeList( - FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + if (shouldTagGlobal(*GV)) { +Meta.Memtag |= +static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); +Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); +Meta.Memtag &= !CGM.isInNoSanitizeList( +FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); + } else { +Meta.Memtag = false; + } Meta.IsDynInit = IsDynInit && !Meta.NoAddress && FsanitizeArgument.has(SanitizerKind::Address) && diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc0..6a2817f417d30d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { const DataLayout &DL = GV->getDataLayout(); uint64_t Size = DL.getTypeAllocSize(GV->getValueType()); + if (GV->isTagged()) Size = alignTo(Size, 16); // If the alignment is specified, we *must* obey it. Overaligning a global // with a specified alignment is a prompt way to break globals emitted to // sections and expected to be contiguous (e.g. ObjC metadata). - const Align Alignment = getGVAlignment(GV, DL); + Align Alignment = getGVAlignment(GV, DL); + if (GV->isTagged() && Alignment < 16) { +assert(!GV->hasSection()); +Alignment = Al
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
@@ -84,6 +84,14 @@ void test_macro_expansion4() { #undef MY_NULL } +template struct pear { + T x; +}; +void test_templated() { + pear p = { NULL }; fmayer wrote: Doesn't this need some `CHECK` or `CHECK-NOT`? https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)
@@ -489,13 +485,7 @@ static DiagnosticIDs::Level toLevel(diag::Severity SV) { DiagnosticIDs::Level DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, const DiagnosticsEngine &Diag) const { - // Handle custom diagnostics, which cannot be mapped. fmayer wrote: I agree, let's revert if this is causing problems. https://github.com/llvm/llvm-project/pull/70976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
@@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compile-time by overloading the symbol ``__rtsan_default_options``: fmayer wrote: should we just add `__attribute__((__visibility__("default")))` for good measure? because i think if someone adds `-fvisibility=hidden` it won't work without this? https://github.com/llvm/llvm-project/pull/110296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
@@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compile-time by overloading the symbol ``__rtsan_default_options``: fmayer wrote: Do users care that this is overriding a weak symbol? https://github.com/llvm/llvm-project/pull/110296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
@@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compiler time by overloading the symbol ``__rtsan_default_options``: fmayer wrote: compile-time? https://github.com/llvm/llvm-project/pull/110296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
@@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compile-time by overloading the symbol ``__rtsan_default_options``: fmayer wrote: I don't think "overload" is technically the correct term. "provide"? Should we talk about visibility? https://github.com/llvm/llvm-project/pull/110296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/110296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits