1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-28 02:44:48 +03:00

Revert "Use tbb::concurrent_unordered_set"

This reverts commit e88e662854.
This commit is contained in:
Rui Ueyama 2021-01-22 16:01:54 +09:00
parent e88e662854
commit 2949c417a7
4 changed files with 23 additions and 57 deletions

View File

@ -460,7 +460,7 @@ MergeableSection::MergeableSection(InputSection *isec, std::string_view data)
std::string_view substr = data.substr(0, end + 1);
data = data.substr(end + 1);
SectionFragment *frag = parent.insert(substr);
SectionFragment *frag = parent.map.insert(substr, SectionFragment(substr));
fragments.push_back(frag);
frag_offsets.push_back(offset);
offset += substr.size();

View File

@ -217,7 +217,7 @@ static void handle_mergeable_strings() {
for (SectionFragment *frag : m->fragments) {
if (frag->isec == m && frag->output_offset == -1) {
frag->output_offset = offset;
offset += frag->data.size();
offset += frag->size;
}
}
m->size = offset;
@ -981,6 +981,10 @@ static void show_stats() {
for (ObjectFile *file : out::objs)
num_input_sections.inc(file->sections.size());
static Counter merged_strings("merged_strings");
for (MergedSection *osec : MergedSection::instances)
merged_strings.inc(osec->map.size());
Counter num_output_chunks("output_out::chunks", out::chunks.size());
Counter num_objs("num_objs", out::objs.size());
Counter num_dsos("num_dsos", out::dsos.size());

63
mold.h
View File

@ -19,7 +19,6 @@
#include <string>
#include <string_view>
#include <tbb/concurrent_hash_map.h>
#include <tbb/concurrent_unordered_set.h>
#include <tbb/spin_mutex.h>
#include <tbb/spin_rw_mutex.h>
#include <vector>
@ -158,11 +157,11 @@ std::ostream &operator<<(std::ostream &out, const InputFile &file);
namespace tbb {
template<>
struct tbb_hash_compare<std::string_view> {
static size_t hash(const std::string_view &k) {
static size_t hash(const std::string_view& k) {
return std::hash<std::string_view>()(k);
}
static bool equal(const std::string_view &k1, const std::string_view &k2) {
static bool equal(const std::string_view& k1, const std::string_view& k2) {
return k1 == k2;
}
};
@ -197,16 +196,18 @@ private:
//
struct SectionFragment {
SectionFragment(std::string_view data) : data(data) {}
SectionFragment(std::string_view view)
: data((const char *)view.data()), size(view.size()) {}
SectionFragment(const SectionFragment &other)
: isec(other.isec.load()), data(other.data),
: isec(other.isec.load()), data(other.data), size(other.size),
output_offset(other.output_offset) {}
inline u64 get_addr() const;
std::atomic<MergeableSection *> isec = nullptr;
std::string_view data;
const char *data;
u32 size;
u32 output_offset = -1;
};
@ -228,10 +229,14 @@ enum {
class Symbol {
public:
Symbol() {}
Symbol(std::string_view name) : name(name) {}
Symbol(const Symbol &other) : name(other.name) {}
static inline Symbol *intern(std::string_view name);
static Symbol *intern(std::string_view name) {
static ConcurrentMap<Symbol> map;
Symbol sym;
sym.name = name;
return map.insert(name, sym);
}
inline u64 get_addr() const;
inline u64 get_got_addr() const;
@ -277,38 +282,6 @@ public:
u8 has_copyrel : 1 = false;
};
namespace tbb {
template<> struct tbb_hash<SectionFragment> {
size_t operator()(const SectionFragment &frag) const {
return std::hash<std::string_view>()(frag.data);
}
};
template<> struct tbb_hash<Symbol> {
size_t operator()(const Symbol &sym) const {
return std::hash<std::string_view>()(sym.name);
}
};
}
template<> struct std::equal_to<SectionFragment> {
bool operator()(const SectionFragment &lhs, const SectionFragment &rhs) const {
return lhs.data == rhs.data;
}
};
template<> struct std::equal_to<Symbol> {
bool operator()(const Symbol &lhs, const Symbol &rhs) const {
return lhs.name == rhs.name;
}
};
inline Symbol *Symbol::intern(std::string_view name) {
static tbb::concurrent_unordered_set<Symbol> set;
auto [it, inserted] = set.emplace(name);
return &*it;
}
//
// input_sections.cc
//
@ -662,8 +635,7 @@ public:
static MergedSection *get_instance(std::string_view name, u32 type, u64 flags);
static inline std::vector<MergedSection *> instances;
inline SectionFragment *insert(std::string_view data);
ConcurrentMap<SectionFragment> map;
void copy_buf() override;
@ -675,8 +647,6 @@ private:
shdr.sh_type = type;
shdr.sh_addralign = 1;
}
tbb::concurrent_unordered_set<SectionFragment> set;
};
struct EhReloc {
@ -1248,8 +1218,3 @@ template <typename T, typename U>
inline void sort(T &vec, U less) {
std::stable_sort(vec.begin(), vec.end(), less);
}
inline SectionFragment *MergedSection::insert(std::string_view data) {
auto [it, inserted] = set.emplace(data);
return &*it;
}

View File

@ -700,13 +700,10 @@ MergedSection::get_instance(std::string_view name, u32 type, u64 flags) {
void MergedSection::copy_buf() {
u8 *base = out::buf + shdr.sh_offset;
for (const SectionFragment &frag : set)
map.for_each_value([&](const SectionFragment &frag) {
if (MergeableSection *m = frag.isec)
memcpy(base + m->offset + frag.output_offset,
frag.data.data(), frag.data.size());
static Counter merged_strings("merged_strings");
merged_strings.inc(set.size());
memcpy(base + m->offset + frag.output_offset, frag.data, frag.size);
});
}
void EhFrameSection::construct() {