[llvm] r338062 - Handle the lack of a symbol table correctly.
Stephen Hines via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 26 13:05:32 PDT 2018
Author: srhines
Date: Thu Jul 26 13:05:31 2018
New Revision: 338062
URL: http://llvm.org/viewvc/llvm-project?rev=338062&view=rev
Log:
Handle the lack of a symbol table correctly.
Summary:
These two cases will trigger a dereference on a nullptr, since the
SymbolTable can be nonexistent for a given library, in addition to just
being empty.
Reviewers: alexshap
Reviewed By: alexshap
Subscribers: meikeb, kongyi, chh, jakehehrlich, llvm-commits, pirama
Differential Revision: https://reviews.llvm.org/D49534
Modified:
llvm/trunk/test/tools/llvm-objcopy/strip-all.test
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
Modified: llvm/trunk/test/tools/llvm-objcopy/strip-all.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/strip-all.test?rev=338062&r1=338061&r2=338062&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/strip-all.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/strip-all.test Thu Jul 26 13:05:31 2018
@@ -35,6 +35,13 @@
# RUN: llvm-strip --strip-all %t8
# RUN: cmp %t2 %t8
+# Verify that a non-existent symbol table (after first call to llvm-strip)
+# can be handled correctly.
+# RUN: cp %t %t9
+# RUN: llvm-strip --strip-all -keep=unavailable_symbol %t9
+# RUN: llvm-strip --strip-all -keep=unavailable_symbol %t9
+# RUN: cmp %t2 %t9
+
!ELF
FileHeader:
Class: ELFCLASS64
Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=338062&r1=338061&r2=338062&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Thu Jul 26 13:05:31 2018
@@ -396,7 +396,8 @@ static void HandleArgs(const CopyConfig
// Keep special sections.
if (Obj.SectionNames == &Sec)
return false;
- if (Obj.SymbolTable == &Sec || Obj.SymbolTable->getStrTab() == &Sec)
+ if (Obj.SymbolTable == &Sec ||
+ (Obj.SymbolTable && Obj.SymbolTable->getStrTab() == &Sec))
return false;
// Remove everything else.
@@ -421,7 +422,7 @@ static void HandleArgs(const CopyConfig
// (equivalently, the updated symbol table is not empty)
// the symbol table and the string table should not be removed.
if ((!Config.SymbolsToKeep.empty() || Config.KeepFileSymbols) &&
- !Obj.SymbolTable->empty()) {
+ Obj.SymbolTable && !Obj.SymbolTable->empty()) {
RemovePred = [&Obj, RemovePred](const SectionBase &Sec) {
if (&Sec == Obj.SymbolTable || &Sec == Obj.SymbolTable->getStrTab())
return false;
More information about the llvm-commits
mailing list