1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[llvm-cxxfilt] Improve strip-underscore behavior

Summary:
For platform that uses macho format, c++filt should be stripping the
leading underscore by default. Introduce the binutil compatible "-n"
option to control strip-undercore behaivor together with the existing
"-_" option and fallback to system default if none of them are set.

rdar://problem/57173514

Reviewers: compnerd, erik.pilkington, dexonsmith, mattd

Reviewed By: compnerd, erik.pilkington

Subscribers: jkorous, ributzka, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70250
This commit is contained in:
Steven Wu 2019-11-18 14:51:41 -08:00
parent 0d09270c42
commit a7bce70eed
11 changed files with 35 additions and 12 deletions

View File

@ -1,4 +1,4 @@
RUN: llvm-cxxfilt _Z14returns_stringB5cxx11v _Z6globalB5cxx11 _Z6globalB12a_longer_tag | FileCheck %s
RUN: llvm-cxxfilt -n _Z14returns_stringB5cxx11v _Z6globalB5cxx11 _Z6globalB12a_longer_tag | FileCheck %s
CHECK: returns_string[abi:cxx11]()
CHECK-NEXT: global[abi:cxx11]

View File

@ -1,5 +1,5 @@
RUN: llvm-cxxfilt -_ ___imp__ZSt6futureIvE | FileCheck %s
RUN: llvm-cxxfilt __imp__ZSt6futureIvE | FileCheck %s
RUN: llvm-cxxfilt -n __imp__ZSt6futureIvE | FileCheck %s
CHECK: import thunk for std::future<void>

View File

@ -0,0 +1,4 @@
REQUIRES: system-darwin
RUN: llvm-cxxfilt __Z1fv | FileCheck %s
CHECK: f()

View File

@ -28,7 +28,7 @@ RUN: '_Z3Foo|' \
RUN: '_Z3Foo}' \
RUN: '_Z3Foo~,,' \
RUN: '_Z3Foo,,_Z3Bar::_Z3Baz _Z3Foo,_Z3Bar:_Z3Baz' \
RUN: '_Z3Foo$ ._Z3Foo' | llvm-cxxfilt | FileCheck %s
RUN: '_Z3Foo$ ._Z3Foo' | llvm-cxxfilt -n | FileCheck %s
CHECK: ,,Foo!
CHECK: Foo"

View File

@ -2,7 +2,7 @@
RUN: echo "" > %t
RUN: echo "_Z3foov" >> %t
RUN: echo "" >> %t
RUN: llvm-cxxfilt < %t | FileCheck %s
RUN: llvm-cxxfilt -n < %t | FileCheck %s
CHECK: {{^$}}
CHECK-NEXT: foo()

View File

@ -1,4 +1,4 @@
RUN: llvm-cxxfilt _Z1fi __Z1fi f ___ZSt1ff_block_invoke | FileCheck %s
RUN: llvm-cxxfilt -n _Z1fi __Z1fi f ___ZSt1ff_block_invoke | FileCheck %s
CHECK: f(int)
CHECK-NEXT: __Z1fi

View File

@ -1,4 +1,4 @@
RUN: sed -n 's/^STDIN: //p' %s | llvm-cxxfilt | FileCheck %s
RUN: sed -n 's/^STDIN: //p' %s | llvm-cxxfilt -n | FileCheck %s
STDIN: _Znw
STDIN: _Znwj

View File

@ -1,7 +1,7 @@
RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s
RUN: echo "Mangled _Z1fi and _Z3foov in string." | llvm-cxxfilt \
RUN: llvm-cxxfilt -n _Z1fi abc | FileCheck %s
RUN: echo "Mangled _Z1fi and _Z3foov in string." | llvm-cxxfilt -n \
RUN: | FileCheck %s --check-prefix=CHECK-STRING
RUN: llvm-cxxfilt "CLI remains mangled _Z1fi" \
RUN: llvm-cxxfilt -n "CLI remains mangled _Z1fi" \
RUN: | FileCheck %s --check-prefix=CHECK-MANGLED
CHECK: f(int)

View File

@ -1,4 +1,4 @@
RUN: llvm-cxxfilt -t f i | FileCheck %s
RUN: llvm-cxxfilt -n -t f i | FileCheck %s
RUN: echo "f i" | llvm-cxxfilt -t | FileCheck %s --check-prefix="CHECK-STRING"
CHECK: float

View File

@ -1,5 +1,5 @@
RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-STRIPPED
RUN: llvm-cxxfilt __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED
RUN: llvm-cxxfilt -n __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED
CHECK-STRIPPED: ns::f
CHECK-STRIPPED: _ZSt1f

View File

@ -7,8 +7,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
@ -41,6 +43,13 @@ static cl::opt<bool> StripUnderscore("strip-underscore",
static cl::alias StripUnderscoreShort("_",
cl::desc("alias for --strip-underscore"),
cl::aliasopt(StripUnderscore));
static cl::opt<bool>
NoStripUnderscore("no-strip-underscore",
cl::desc("do not strip the leading underscore"),
cl::init(false));
static cl::alias
NoStripUnderscoreShort("n", cl::desc("alias for --no-strip-underscore"),
cl::aliasopt(NoStripUnderscore));
static cl::opt<bool>
Types("types",
@ -55,11 +64,21 @@ Decorated(cl::Positional, cl::desc("<mangled>"), cl::ZeroOrMore);
static cl::extrahelp
HelpResponse("\nPass @FILE as argument to read options from FILE.\n");
static bool shouldStripUnderscore() {
if (StripUnderscore)
return true;
if (NoStripUnderscore)
return false;
// If none of them are set, use the default value for platform.
// macho has symbols prefix with "_" so strip by default.
return Triple(sys::getProcessTriple()).isOSBinFormatMachO();
}
static std::string demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
int Status;
const char *DecoratedStr = Mangled.c_str();
if (StripUnderscore)
if (shouldStripUnderscore())
if (DecoratedStr[0] == '_')
++DecoratedStr;
size_t DecoratedLength = strlen(DecoratedStr);