[PATCH] D61117: Fix Bug 41353 - unique symbols printed as D instead of u
Mike Pozulp via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 13:10:56 PDT 2019
mmpozulp updated this revision to Diff 196713.
mmpozulp added a comment.
Protect dyn_cast with isELF() check
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61117/new/
https://reviews.llvm.org/D61117
Files:
llvm/include/llvm/Object/ELFTypes.h
llvm/test/tools/llvm-nm/X86/Inputs/unique.s
llvm/test/tools/llvm-nm/X86/unique.test
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -923,6 +923,26 @@
SymbolList.clear();
}
+template <class ELFT>
+static bool isUniqueGlobalSymbol(const ELFObjectFile<ELFT> *Obj,
+ const BasicSymbolRef &Sym) {
+ return Obj->getSymbol(Sym.getRawDataRefImpl())->isUniqueGlobal();
+}
+
+static bool isELFUniqueGlobalSymbol(const BasicSymbolRef &Sym) {
+ const SymbolicFile *Obj = Sym.getObject();
+ if (!Obj->isELF())
+ return false;
+ if (auto *ELF32LE = dyn_cast<ELF32LEObjectFile>(Obj))
+ return isUniqueGlobalSymbol(ELF32LE, Sym);
+ if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
+ return isUniqueGlobalSymbol(ELF64LE, Sym);
+ if (auto *ELF32BE = dyn_cast<ELF32BEObjectFile>(Obj))
+ return isUniqueGlobalSymbol(ELF32BE, Sym);
+ auto *ELF64BE = cast<ELF64BEObjectFile>(Obj);
+ return isUniqueGlobalSymbol(ELF64BE, Sym);
+}
+
static char getSymbolNMTypeChar(ELFObjectFileBase &Obj,
basic_symbol_iterator I) {
// OK, this is ELF
@@ -944,7 +964,7 @@
return 't';
case (ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE):
case (ELF::SHF_ALLOC | ELF::SHF_WRITE):
- return 'd';
+ return isELFUniqueGlobalSymbol(*SymI) ? 'u' : 'd';
case ELF::SHF_ALLOC:
case (ELF::SHF_ALLOC | ELF::SHF_MERGE):
case (ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS):
@@ -1172,7 +1192,7 @@
else
Ret = getSymbolNMTypeChar(cast<ELFObjectFileBase>(Obj), I);
- if (Symflags & object::SymbolRef::SF_Global)
+ if ((Symflags & object::SymbolRef::SF_Global) && !isELFUniqueGlobalSymbol(*I))
Ret = toupper(Ret);
return Ret;
Index: llvm/test/tools/llvm-nm/X86/unique.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/X86/unique.test
@@ -0,0 +1,5 @@
+# RUN: clang -c %p/Inputs/unique.s -o %t
+# RUN: llvm-nm %t | FileCheck %s
+# Fixes https://bugs.llvm.org/show_bug.cgi?id=41353
+
+CHECK: 0000000000000000 u foo
Index: llvm/test/tools/llvm-nm/X86/Inputs/unique.s
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/X86/Inputs/unique.s
@@ -0,0 +1,4 @@
+ .data
+ .type foo,%gnu_unique_object
+foo:
+ .byte 0
Index: llvm/include/llvm/Object/ELFTypes.h
===================================================================
--- llvm/include/llvm/Object/ELFTypes.h
+++ llvm/include/llvm/Object/ELFTypes.h
@@ -241,6 +241,8 @@
return getBinding() != ELF::STB_LOCAL;
}
+ bool isUniqueGlobal() const { return getBinding() == ELF::STB_GNU_UNIQUE; }
+
Expected<StringRef> getName(StringRef StrTab) const;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61117.196713.patch
Type: text/x-patch
Size: 2828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190425/083a8ca7/attachment.bin>
More information about the llvm-commits
mailing list