Prevent a crash in folly::Symbolizer
authorMark Williams <mwilliams@fb.com>
Mon, 20 Feb 2017 22:53:22 +0000 (14:53 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 20 Feb 2017 23:04:32 +0000 (15:04 -0800)
Summary:
dbg and dbgo builds of hhvm with gcc-5 crash when generating
backtraces using folly::Symbolizer, because the .debug_aranges for
libc-2.23.so are SHF_COMPRESSED, and folly::Symbolizer doesn't
recognize that.

Just pretend that the section doesn't exist if it has SHF_COMPRESSED
set.

We might eventually want to support decompressing such sections under
an option - but folly::Symbolizer's goal is to just mmap and walk the
debug info without allocating memory (so that it can run while
handling signals etc).

Reviewed By: pixelb

Differential Revision: D4586762

fbshipit-source-id: bef61ed670d1a80caa4f7aac1f80fd2a92cc4ba9

folly/experimental/symbolizer/Dwarf.cpp

index 7fc1516b47ec00cb3e4164d1d778a2aeb7aaaa15..c34b89ba99ce979c6693dd6305e6963c6e42ae0e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-
 #include <folly/experimental/symbolizer/Dwarf.h>
 
 #include <type_traits>
@@ -304,7 +303,11 @@ bool Dwarf::getSection(const char* name, folly::StringPiece* section) const {
   if (!elfSection) {
     return false;
   }
-
+#ifdef SHF_COMPRESSED
+  if (elfSection->sh_flags & SHF_COMPRESSED) {
+    return false;
+  }
+#endif
   *section = elf_->getSectionBody(*elfSection);
   return true;
 }
@@ -318,7 +321,6 @@ void Dwarf::init() {
     elf_ = nullptr;
     return;
   }
-  getSection(".debug_str", &strings_);
 
   // Optional: fast address range lookup. If missing .debug_info can
   // be used - but it's much slower (linear scan).