Skip to content

[llvm-nm][MachO] Don't call getFlags on redacted symbols #2192

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 1 commit into from
Dec 5, 2020
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
Binary file not shown.
16 changes: 16 additions & 0 deletions llvm/test/tools/llvm-nm/AArch64/macho-redacted-function.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
RUN: llvm-nm %p/Inputs/redacted-function.macho-aarch64 | FileCheck %s

CHECK: <redacted function 1>

# Generated with:
# $ cat /tmp/a.c
# static int i(void) {
# return 0;
# }
#
# int main(void) {
# return i();
# }
#
# $ xcrun -sdk watchos clang -arch arm64_32 /tmp/a.c -o /tmp/redacted-function.macho-aarch64
# $ xcrun -sdk watchos strip -N /tmp/redacted-function.macho-aarch64
14 changes: 8 additions & 6 deletions llvm/tools/llvm-nm/llvm-nm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,20 @@ struct NMSymbol {
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
bool ADefined;
// Symbol flags have been checked in the caller.
uint32_t AFlags = cantFail(A.Sym.getFlags());
if (A.Sym.getRawDataRefImpl().p)
if (A.Sym.getRawDataRefImpl().p) {
uint32_t AFlags = cantFail(A.Sym.getFlags());
ADefined = !(AFlags & SymbolRef::SF_Undefined);
else
} else {
ADefined = A.TypeChar != 'U';
}
bool BDefined;
// Symbol flags have been checked in the caller.
uint32_t BFlags = cantFail(B.Sym.getFlags());
if (B.Sym.getRawDataRefImpl().p)
if (B.Sym.getRawDataRefImpl().p) {
uint32_t BFlags = cantFail(B.Sym.getFlags());
BDefined = !(BFlags & SymbolRef::SF_Undefined);
else
} else {
BDefined = B.TypeChar != 'U';
}
return std::make_tuple(ADefined, A.Address, A.Name, A.Size) <
std::make_tuple(BDefined, B.Address, B.Name, B.Size);
}
Expand Down