diff options
author | Stephen Hines <srhines@google.com> | 2018-07-26 20:05:31 +0000 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2018-07-26 20:05:31 +0000 |
commit | 1028e2499b54c8d120e3f2088bb8db49400194ce (patch) | |
tree | 1567703a0dc649e7fe46d93d60590c88a61fe9b3 | |
parent | 3c58d5b196e9a9ff435b5cefc8d39d8fde750ba1 (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338062 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/tools/llvm-objcopy/strip-all.test | 7 | ||||
-rw-r--r-- | tools/llvm-objcopy/llvm-objcopy.cpp | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/test/tools/llvm-objcopy/strip-all.test b/test/tools/llvm-objcopy/strip-all.test index 71e024de072..bc01835a4cb 100644 --- a/test/tools/llvm-objcopy/strip-all.test +++ b/test/tools/llvm-objcopy/strip-all.test @@ -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 diff --git a/tools/llvm-objcopy/llvm-objcopy.cpp b/tools/llvm-objcopy/llvm-objcopy.cpp index 3a25e3f690b..4ccc67cc75d 100644 --- a/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/tools/llvm-objcopy/llvm-objcopy.cpp @@ -396,7 +396,8 @@ static void HandleArgs(const CopyConfig &Config, Object &Obj, // 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 &Config, Object &Obj, // (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; |