Skip to content

[llvm-cxxfilt][macOS] Don't strip underscores on macOS by default #106233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/Demangle/Demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ std::string llvm::demangle(std::string_view MangledName) {
}

static bool isItaniumEncoding(std::string_view S) {
// Itanium encoding requires 1 or 3 leading underscores, followed by 'Z'.
return starts_with(S, "_Z") || starts_with(S, "___Z");
// Itanium demangler supports prefixes with 1-4 underscores.
const size_t Pos = S.find_first_not_of('_');
return Pos > 0 && Pos <= 4 && S[Pos] == 'Z';
}

static bool isRustEncoding(std::string_view S) { return starts_with(S, "_R"); }
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-cxxfilt/invalid.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
RUN: llvm-cxxfilt -n _Z1fi __Z1fi f ___ZSt1ff_block_invoke | FileCheck %s
RUN: llvm-cxxfilt -n _Z1fi __Z1fi _____Z1fi f ___ZSt1ff_block_invoke ____ZSt1ff_block_invoke | FileCheck %s

CHECK: f(int)
CHECK-NEXT: __Z1fi
CHECK-NEXT: f(int)
CHECK-NEXT: _____Z1fi
CHECK-NEXT: f
CHECK-NEXT: invocation function for block in std::f(float)
CHECK-NEXT: invocation function for block in std::f(float)

This file was deleted.

8 changes: 0 additions & 8 deletions llvm/test/tools/llvm-cxxfilt/strip-underscore-default.test

This file was deleted.

20 changes: 13 additions & 7 deletions llvm/test/tools/llvm-cxxfilt/strip-underscore.test
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
## Show the behaviour of --[no-]strip-underscore. This test does not test
## the platform-specific default behaviour. This is tested elsewhere.
## Show the behaviour of --[no-]strip-underscore.

RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED
RUN: llvm-cxxfilt --strip-underscore __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED
RUN: llvm-cxxfilt -n __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED
RUN: llvm-cxxfilt --no-strip-underscore __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED
RUN: llvm-cxxfilt -_ ___ZN2ns1fE _____Z1fi_block_invoke _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED
RUN: llvm-cxxfilt --strip-underscore __ZN2ns1fE _____Z1fi_block_invoke _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED
RUN: llvm-cxxfilt -n ___ZN2ns1fE _____Z1fi_block_invoke _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED
RUN: llvm-cxxfilt --no-strip-underscore ___ZN2ns1fE _____Z1fi_block_invoke _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED
RUN: llvm-cxxfilt -n -_ _ZSt1f | FileCheck %s -check-prefix OVERRIDE-STRIPPED
RUN: llvm-cxxfilt -_ -n _ZSt1f | FileCheck %s -check-prefix OVERRIDE-UNSTRIPPED

CHECK-STRIPPED: ns::f
CHECK-STRIPPED: invocation function for block in f(int)
CHECK-STRIPPED: _ZSt1f
CHECK-STRIPPED: _f
CHECK-STRIPPED: ._Z3f.0v

CHECK-UNSTRIPPED: __ZN2ns1fE
CHECK-UNSTRIPPED: ___ZN2ns1fE
CHECK-UNSTRIPPED: _____Z1fi_block_invoke
CHECK-UNSTRIPPED: std::f
CHECK-UNSTRIPPED: _f
CHECK-UNSTRIPPED: _._Z3f.0v

OVERRIDE-STRIPPED: _ZSt1f
OVERRIDE-UNSTRIPPED: std::f
9 changes: 2 additions & 7 deletions llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,8 @@ int llvm_cxxfilt_main(int argc, char **argv, const llvm::ToolContext &) {
return 0;
}

// The default value depends on the default triple. Mach-O has symbols
// prefixed with "_", so strip by default.
if (opt::Arg *A =
Args.getLastArg(OPT_strip_underscore, OPT_no_strip_underscore))
StripUnderscore = A->getOption().matches(OPT_strip_underscore);
else
StripUnderscore = Triple(sys::getProcessTriple()).isOSBinFormatMachO();
StripUnderscore =
Args.hasFlag(OPT_strip_underscore, OPT_no_strip_underscore, false);

ParseParams = !Args.hasArg(OPT_no_params);

Expand Down
Loading