2017-11-01 22:16:06 +01:00
|
|
|
//===- NonRelocatableStringpool.h - A simple stringpool --------*- C++ -*-===//
|
2015-08-26 07:09:52 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-08-26 07:09:52 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-11-01 22:16:06 +01:00
|
|
|
|
2015-08-26 07:09:52 +02:00
|
|
|
#ifndef LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
|
|
|
|
#define LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
|
|
|
|
|
2019-01-08 00:27:25 +01:00
|
|
|
#include "SymbolMap.h"
|
|
|
|
|
2016-01-27 20:29:56 +01:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2017-11-01 22:16:06 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-01-24 17:16:43 +01:00
|
|
|
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
|
2017-11-01 22:16:06 +01:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include <cstdint>
|
2018-03-01 11:05:54 +01:00
|
|
|
#include <vector>
|
2016-01-27 20:29:56 +01:00
|
|
|
|
2015-08-26 07:09:52 +02:00
|
|
|
namespace llvm {
|
|
|
|
namespace dsymutil {
|
|
|
|
|
2018-01-24 17:16:43 +01:00
|
|
|
/// A string table that doesn't need relocations.
|
2015-08-26 07:09:52 +02:00
|
|
|
///
|
2018-01-24 17:16:43 +01:00
|
|
|
/// We are doing a final link, no need for a string table that has relocation
|
2018-02-22 12:32:51 +01:00
|
|
|
/// entries for every reference to it. This class provides this ability by just
|
|
|
|
/// associating offsets with strings.
|
2015-08-26 07:09:52 +02:00
|
|
|
class NonRelocatableStringpool {
|
|
|
|
public:
|
2018-01-24 17:16:43 +01:00
|
|
|
/// Entries are stored into the StringMap and simply linked together through
|
|
|
|
/// the second element of this pair in order to keep track of insertion
|
|
|
|
/// order.
|
|
|
|
using MapTy = StringMap<DwarfStringPoolEntry, BumpPtrAllocator>;
|
2015-08-26 07:09:52 +02:00
|
|
|
|
2019-01-08 00:27:25 +01:00
|
|
|
NonRelocatableStringpool(
|
|
|
|
SymbolMapTranslator Translator = SymbolMapTranslator())
|
|
|
|
: Translator(Translator) {
|
2018-02-22 12:32:51 +01:00
|
|
|
// Legacy dsymutil puts an empty string at the start of the line table.
|
2018-01-24 17:16:43 +01:00
|
|
|
EmptyString = getEntry("");
|
2015-08-26 07:09:52 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 17:16:43 +01:00
|
|
|
DwarfStringPoolEntryRef getEntry(StringRef S);
|
|
|
|
|
|
|
|
/// Get the offset of string \p S in the string table. This can insert a new
|
2018-02-22 12:32:51 +01:00
|
|
|
/// element or return the offset of a pre-existing one.
|
2018-03-01 11:05:54 +01:00
|
|
|
uint32_t getStringOffset(StringRef S) { return getEntry(S).getOffset(); }
|
2015-08-26 07:09:52 +02:00
|
|
|
|
2018-01-24 17:16:43 +01:00
|
|
|
/// Get permanent storage for \p S (but do not necessarily emit \p S in the
|
2018-03-01 11:05:54 +01:00
|
|
|
/// output section). A latter call to getStringOffset() with the same string
|
|
|
|
/// will chain it though.
|
|
|
|
///
|
2015-08-26 07:09:52 +02:00
|
|
|
/// \returns The StringRef that points to permanent storage to use
|
|
|
|
/// in place of \p S.
|
|
|
|
StringRef internString(StringRef S);
|
|
|
|
|
|
|
|
uint64_t getSize() { return CurrentEndOffset; }
|
|
|
|
|
[DebugInfo] Reduce debug_str_offsets section size
Summary:
The accelerator tables use the debug_str section to store their strings.
However, they do not support the indirect method of access that is
available for the debug_info section (DW_FORM_strx et al.).
Currently our code is assuming that all strings can/will be referenced
indirectly, and puts all of them into the debug_str_offsets section.
This is generally true for regular (unsplit) dwarf, but in the DWO case,
most of the strings in the debug_str section will only be used from the
accelerator tables. Therefore the contents of the debug_str_offsets
section will be largely unused and bloating the main executable.
This patch rectifies this by teaching the DwarfStringPool to
differentiate between strings accessed directly and indirectly. When a
user inserts a string into the pool it has to declare whether that
string will be referenced directly or not. If at least one user requsts
indirect access, that string will be assigned an index ID and put into
debug_str_offsets table. Otherwise, the offset table is skipped.
This approach reduces the overall binary size (when compiled with
-gdwarf-5 -gsplit-dwarf) in my tests by about 2% (debug_str_offsets is
shrunk by 99%).
Reviewers: probinson, dblaikie, JDevlieghere
Subscribers: aprantl, mgrang, llvm-commits
Differential Revision: https://reviews.llvm.org/D49493
llvm-svn: 339122
2018-08-07 11:54:52 +02:00
|
|
|
/// Return the list of strings to be emitted. This does not contain the
|
|
|
|
/// strings which were added via internString only.
|
|
|
|
std::vector<DwarfStringPoolEntryRef> getEntriesForEmission() const;
|
2018-01-24 17:16:43 +01:00
|
|
|
|
2015-08-26 07:09:52 +02:00
|
|
|
private:
|
|
|
|
MapTy Strings;
|
2017-11-01 22:16:06 +01:00
|
|
|
uint32_t CurrentEndOffset = 0;
|
2018-01-24 17:16:43 +01:00
|
|
|
unsigned NumEntries = 0;
|
|
|
|
DwarfStringPoolEntryRef EmptyString;
|
2019-01-08 00:27:25 +01:00
|
|
|
SymbolMapTranslator Translator;
|
2015-08-26 07:09:52 +02:00
|
|
|
};
|
|
|
|
|
2018-06-27 18:13:40 +02:00
|
|
|
/// Helper for making strong types.
|
|
|
|
template <typename T, typename S> class StrongType : public T {
|
|
|
|
public:
|
|
|
|
template <typename... Args>
|
|
|
|
explicit StrongType(Args... A) : T(std::forward<Args>(A)...) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// It's very easy to introduce bugs by passing the wrong string pool in the
|
|
|
|
/// dwarf linker. By using strong types the interface enforces that the right
|
|
|
|
/// kind of pool is used.
|
|
|
|
struct UniqueTag {};
|
|
|
|
struct OffsetsTag {};
|
|
|
|
using UniquingStringPool = StrongType<NonRelocatableStringpool, UniqueTag>;
|
|
|
|
using OffsetsStringPool = StrongType<NonRelocatableStringpool, OffsetsTag>;
|
|
|
|
|
2017-11-01 22:16:06 +01:00
|
|
|
} // end namespace dsymutil
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
|