diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2020-08-17 18:11:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 18:11:01 -0700 |
commit | e2d598668bb09e1fb83e9342c37174e37f6b5024 (patch) | |
tree | 1b083020268d93d5cd7dff8278ac403106be46c1 | |
parent | 3cf5c3feca15ab88730d6526b2f06302597926b5 (diff) | |
parent | 9ef3de389f827ea0044dc53e41b58ffe513fbdae (diff) | |
download | bloaty-e2d598668bb09e1fb83e9342c37174e37f6b5024.tar.gz |
Merge pull request #211 from tengyifei/patch-1
[dwarf] Handle tombstone address values
-rw-r--r-- | src/dwarf.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/dwarf.cc b/src/dwarf.cc index 74d159c..ae01de0 100644 --- a/src/dwarf.cc +++ b/src/dwarf.cc @@ -18,6 +18,7 @@ #include <algorithm> #include <initializer_list> #include <iostream> +#include <limits> #include <memory> #include <stack> #include <unordered_map> @@ -60,6 +61,20 @@ int DivRoundUp(int n, int d) { return (n + (d - 1)) / d; } +namespace { + +// uint64/32 max is a tombstone value added by https://reviews.llvm.org/D81784. +bool IsValidDwarfAddress(uint64_t addr, uint8_t address_size) { + if (addr == 0) + return false; + if (address_size == 4 && addr == std::numeric_limits<uint32_t>::max()) + return false; + if (address_size == 8 && addr == std::numeric_limits<uint64_t>::max()) + return false; + return true; +} + +} // namespace // Low-level Parsing Routines ////////////////////////////////////////////////// @@ -405,6 +420,8 @@ class AddressRanges { // debug_info_offset(). Must call this once before reading the first unit. bool NextUnit(); + bool address_size() const { return sizes_.address_size(); } + private: CompilationUnitSizes sizes_; string_view section_; @@ -1387,7 +1404,7 @@ static bool ReadDWARFAddressRanges(const dwarf::File& file, RangeSink* sink) { std::string filename = map.GetFilename(ranges.debug_info_offset()); while (ranges.NextRange()) { - if (ranges.address() != 0) { + if (dwarf::IsValidDwarfAddress(ranges.address(), ranges.address_size())) { sink->AddVMRangeIgnoreDuplicate("dwarf_aranges", ranges.address(), ranges.length(), filename); } @@ -1534,7 +1551,8 @@ void AddDIE(const dwarf::File& file, const std::string& name, RangeSink* sink) { // Some DIEs mark address ranges with high_pc/low_pc pairs (especially // functions). - if (die.has_low_pc() && die.has_high_pc() && die.low_pc() != 0) { + if (die.has_low_pc() && die.has_high_pc() && + dwarf::IsValidDwarfAddress(die.low_pc(), sizes.address_size())) { uint64_t high_pc = die.high_pc(); // It appears that some compilers make high_pc a size, and others make it an |