diff --git a/.github/actions/4c-test-dmd/action.yml b/.github/actions/4c-test-dmd/action.yml index cd7368dc858..22dbea1f942 100644 --- a/.github/actions/4c-test-dmd/action.yml +++ b/.github/actions/4c-test-dmd/action.yml @@ -9,20 +9,7 @@ runs: - name: 'Posix: Run DMD testsuite' if: runner.os != 'Windows' shell: bash - run: | - set -eux - repoDir=$PWD - cd ../build - if type -P apk &>/dev/null; then - # Alpine: run full dmd-testsuite-debug - ctest -V -R 'dmd-testsuite' -E '^dmd-testsuite$' - # these two tests require extra flags "-link-defaultlib-debug -frame-pointer=all": https://github.com/ldc-developers/ldc/issues/4694 - # => remove before running optimized dmd-testsuite separately - rm $repoDir/tests/dmd/runnable/{test17559.d,test19086.d} - ctest -V -R '^dmd-testsuite$' - else - ctest -V -R "dmd-testsuite" - fi + run: cd ../build && ctest -V -R "dmd-testsuite" - name: 'Windows: Run DMD testsuite' if: runner.os == 'Windows' diff --git a/CHANGELOG.md b/CHANGELOG.md index 814e607e9c8..1e81f325e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # LDC master #### Big news +- Keep frame pointers by default with `-O` for some targets, notably AArch64 (except Windows), x86_64 (except Windows and glibc Linux), Windows x86, and Android. This fixes druntime backtraces with optimized code (incl. prebuilt druntime/Phobos). (#4889) - ldc2.conf: Arrays can now be appended to via the `~=` operator. (#4848, #4856) #### Platform support diff --git a/gen/functions.cpp b/gen/functions.cpp index 379daf164f5..8890bb2ea61 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -432,8 +432,6 @@ void applyTargetMachineAttributes(llvm::Function &func, opts::setFunctionAttributes(cpu, features, func); if (opts::fFastMath) // -ffast-math[=true] overrides -enable-unsafe-fp-math func.addFnAttr("unsafe-fp-math", "true"); - if (!func.hasFnAttribute("frame-pointer")) // not explicitly set by user - func.addFnAttr("frame-pointer", isOptimizationEnabled() ? "none" : "all"); } void applyXRayAttributes(FuncDeclaration &fdecl, llvm::Function &func) { @@ -448,6 +446,23 @@ void applyXRayAttributes(FuncDeclaration &fdecl, llvm::Function &func) { } } +// Keep frame pointers by default with enabled optimizations? +// The logic is very loosely based on clang's +// `useFramePointerForTargetByDefault()`, as well as backtrace test results for +// druntime-test-exceptions-release. +bool keepFramePointersByDefault() { + const auto &triple = *global.params.targetTriple; + if (triple.isAndroid()) + return true; + if (triple.isAArch64()) + return !triple.isOSWindows(); + if (triple.getArch() == llvm::Triple::x86) + return triple.isOSWindows(); // required for druntime backtraces + if (triple.getArch() == llvm::Triple::x86_64) + return !(triple.isOSWindows() || triple.isGNUEnvironment()); + return false; +} + void onlyOneMainCheck(FuncDeclaration *fd) { if (!fd->fbody) // multiple *declarations* are fine return; @@ -1174,6 +1189,17 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) { func->addFnAttr("use-sample-profile"); } + if (fd->hasInlineAsm()) { + // disable frame-pointer-elimination for functions with DMD-style inline asm + func->addFnAttr("frame-pointer", "all"); + } else if (!func->hasFnAttribute("frame-pointer")) { + // not explicitly set by user + func->addFnAttr("frame-pointer", + isOptimizationEnabled() && !keepFramePointersByDefault() + ? "none" + : "all"); + } + llvm::BasicBlock *beginbb = llvm::BasicBlock::Create(gIR->context(), "", func); @@ -1210,12 +1236,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) { emitDMDStyleFunctionTrace(*gIR, fd, funcGen); } - // disable frame-pointer-elimination for functions with DMD-style inline asm - if (fd->hasInlineAsm()) { - func->addFnAttr( - llvm::Attribute::get(gIR->context(), "frame-pointer", "all")); - } - // give the 'this' parameter (an lvalue) storage and debug info if (irFty.arg_this) { LLValue *thisvar = irFunc->thisArg; diff --git a/tests/codegen/attr_targetoptions.d b/tests/codegen/attr_targetoptions.d index 8e6e21f2e2d..07822b753e7 100644 --- a/tests/codegen/attr_targetoptions.d +++ b/tests/codegen/attr_targetoptions.d @@ -1,9 +1,5 @@ // Tests that our TargetMachine options are added as function attributes -// RUN: %ldc -c -output-ll -of=%t.ll %s -// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll -// RUN: %ldc -c -output-ll -of=%t.ll %s -O2 -// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=NO_FP < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll %s -O2 -frame-pointer=all // RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll %s -frame-pointer=none -mattr=test diff --git a/tests/codegen/exception_stack_trace.d b/tests/codegen/exception_stack_trace.d index 71002d74e9b..94f916a80c3 100644 --- a/tests/codegen/exception_stack_trace.d +++ b/tests/codegen/exception_stack_trace.d @@ -1,4 +1,4 @@ -// RUN: %ldc -g -frame-pointer=all -link-defaultlib-debug %s -of=%t%exe +// RUN: %ldc -g %s -of=%t%exe // RUN: %t%exe | FileCheck %s void bar() diff --git a/tests/codegen/frame_pointer_x86.d b/tests/codegen/frame_pointer_x86.d index c0450591f78..17cd4f0b3b8 100644 --- a/tests/codegen/frame_pointer_x86.d +++ b/tests/codegen/frame_pointer_x86.d @@ -1,12 +1,12 @@ // REQUIRES: target_X86 -// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s +// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s // RUN: FileCheck %s --check-prefixes=COMMON,FP < %t.s -// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -O2 +// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s -O2 // RUN: FileCheck %s --check-prefixes=COMMON,NO_FP < %t.s -// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -O2 -frame-pointer=all +// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s -O2 -frame-pointer=all // RUN: FileCheck %s --check-prefixes=COMMON,FP < %t.s -// RUN: %ldc -c -mtriple=x86_64 -output-s -of=%t.s %s -frame-pointer=none +// RUN: %ldc -c -mtriple=x86_64-linux-gnu -output-s -of=%t.s %s -frame-pointer=none // RUN: FileCheck %s --check-prefixes=COMMON,NO_FP < %t.s // COMMON-LABEL: _D17frame_pointer_x8613inlineAsmLeafFZv: diff --git a/tests/codegen/vector_abi_x86.d b/tests/codegen/vector_abi_x86.d index 41fc2bcc1c4..44a92fcb2a2 100644 --- a/tests/codegen/vector_abi_x86.d +++ b/tests/codegen/vector_abi_x86.d @@ -3,10 +3,10 @@ // REQUIRES: host_X86 -// RUN: %ldc -O -output-s -m32 -of=%t_32.s %s -mattr=+sse2 +// RUN: %ldc -O -frame-pointer=none -output-s -m32 -of=%t_32.s %s -mattr=+sse2 // RUN: FileCheck --check-prefix=COMMON %s < %t_32.s -// RUN: %ldc -O -output-s -m64 -of=%t_64.s %s +// RUN: %ldc -O -frame-pointer=none -output-s -m64 -of=%t_64.s %s // RUN: FileCheck --check-prefix=COMMON --check-prefix=X64 %s < %t_64.s import core.simd; diff --git a/tests/dmd/runnable/test17559.d b/tests/dmd/runnable/test17559.d index 22e512166c2..ac9ccc4ff66 100644 --- a/tests/dmd/runnable/test17559.d +++ b/tests/dmd/runnable/test17559.d @@ -1,7 +1,5 @@ // REQUIRED_ARGS: -g // REQUIRED_ARGS(linux freebsd openbsd dragonflybsd): -L-export-dynamic -// LDC (required for Win32 and -O): REQUIRED_ARGS(windows32): -link-defaultlib-debug -// LDC (FreeBSD's libexecinfo apparently doesn't like elided frame pointers): REQUIRED_ARGS(freebsd): -link-defaultlib-debug -frame-pointer=all // PERMUTE_ARGS: // DISABLED: osx diff --git a/tests/dmd/runnable/test19086.d b/tests/dmd/runnable/test19086.d index 6ac2e657fa1..b2e58fb4a1b 100644 --- a/tests/dmd/runnable/test19086.d +++ b/tests/dmd/runnable/test19086.d @@ -1,6 +1,5 @@ // REQUIRED_ARGS: -g // REQUIRED_ARGS(linux freebsd openbsd dragonflybsd): -L-export-dynamic -// LDC (FreeBSD's libexecinfo apparently doesn't like elided frame pointers): REQUIRED_ARGS(freebsd): -link-defaultlib-debug -frame-pointer=all // DISABLED: LDC_win32 // no file/line info for the `run19086` frame (and only that frame), even without -O // PERMUTE_ARGS: // DISABLED: osx diff --git a/tests/sanitizers/fuzz_asan.d b/tests/sanitizers/fuzz_asan.d index 3a1711b1537..b8be47e4121 100644 --- a/tests/sanitizers/fuzz_asan.d +++ b/tests/sanitizers/fuzz_asan.d @@ -2,9 +2,8 @@ // REQUIRES: Fuzzer, ASan -// See https://github.com/ldc-developers/ldc/issues/2222 for -frame-pointer=all // See https://github.com/ldc-developers/ldc/pull/4328 for -fsanitize-address-use-after-return=never -// RUN: %ldc -g -fsanitize=address,fuzzer -fsanitize-address-use-after-return=never -frame-pointer=all %s -of=%t%exe +// RUN: %ldc -g -fsanitize=address,fuzzer -fsanitize-address-use-after-return=never %s -of=%t%exe // RUN: not %t%exe 2>&1 | FileCheck %s bool FuzzMe(ubyte* data, size_t dataSize)