diff options
author | David Blaikie <dblaikie@gmail.com> | 2015-12-01 19:17:58 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2015-12-01 19:17:58 +0000 |
commit | bb94e440d50f92f589134e19f9876bd59f2666de (patch) | |
tree | 2a957d8232738dcd73ca5cb052693c310783746f /llvm/tools/llvm-dwp/llvm-dwp.cpp | |
parent | 56ab51870c42b4b3591070d5cf3155af9bcfcd10 (diff) | |
download | bcm5719-llvm-bb94e440d50f92f589134e19f9876bd59f2666de.tar.gz bcm5719-llvm-bb94e440d50f92f589134e19f9876bd59f2666de.zip |
[llvm-dwp] Deduplicate strings in the debug_str.dwo section
Also, ensure that references to those strings in debug_str_offsets.dwo
correctly refer to the deduplicated strings.
llvm-svn: 254441
Diffstat (limited to 'llvm/tools/llvm-dwp/llvm-dwp.cpp')
-rw-r--r-- | llvm/tools/llvm-dwp/llvm-dwp.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index c89be222e6c..9ce37ec2cee 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -40,8 +40,9 @@ static int error(const Twine &Error, const Twine &Context) { static std::error_code writeStringsAndOffsets(MCStreamer &Out, StringMap<uint32_t> &Strings, - uint32_t &StringOffset, MCSection *StrOffsetSection, - StringRef CurStrSection, StringRef CurStrOffsetSection) { + uint32_t &StringOffset, MCSection *StrSection, + MCSection *StrOffsetSection, StringRef CurStrSection, + StringRef CurStrOffsetSection) { // Could possibly produce an error or warning if one of these was non-null but // the other was null. if (CurStrSection.empty() || CurStrOffsetSection.empty()) @@ -54,9 +55,14 @@ writeStringsAndOffsets(MCStreamer &Out, StringMap<uint32_t> &Strings, uint32_t PrevOffset = 0; while (const char *s = Data.getCStr(&LocalOffset)) { StringRef Str(s, LocalOffset - PrevOffset - 1); - OffsetRemapping[PrevOffset] = StringOffset; - // insert, if successful, write new string to the str.dwo section - StringOffset += Str.size() + 1; + auto Pair = Strings.insert(std::make_pair(Str, StringOffset)); + if (Pair.second) { + Out.SwitchSection(StrSection); + Out.EmitBytes( + StringRef(Pair.first->getKeyData(), Pair.first->getKeyLength() + 1)); + StringOffset += Str.size() + 1; + } + OffsetRemapping[PrevOffset] = Pair.first->second; PrevOffset = LocalOffset; } @@ -106,19 +112,19 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) { StringRef Contents; if (auto Err = Section.getContents(Contents)) return Err; - if (OutSection == StrOffsetSection) { + if (OutSection == StrOffsetSection) CurStrOffsetSection = Contents; - continue; - } - if (OutSection == StrSection) + else if (OutSection == StrSection) CurStrSection = Contents; - Out.SwitchSection(OutSection); - Out.EmitBytes(Contents); + else { + Out.SwitchSection(OutSection); + Out.EmitBytes(Contents); + } } } - if (auto Err = - writeStringsAndOffsets(Out, Strings, StringOffset, StrOffsetSection, - CurStrSection, CurStrOffsetSection)) + if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset, + StrSection, StrOffsetSection, + CurStrSection, CurStrOffsetSection)) return Err; } return std::error_code(); |