mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
temporary
This commit is contained in:
parent
9effdfd9e0
commit
bd6ee5098c
64
main.cc
64
main.cc
@ -115,37 +115,39 @@ static std::vector<ArrayRef<T>> split(const std::vector<T> &input, int unit) {
|
||||
|
||||
static void bin_sections(std::vector<ObjectFile *> &files) {
|
||||
#if 1
|
||||
typedef std::vector<std::vector<InputSection *>> T;
|
||||
|
||||
auto fn = [&](const tbb::blocked_range<int> &range, const T &init) {
|
||||
T vec = init;
|
||||
for (int i = range.begin(); i < range.end(); i++) {
|
||||
ObjectFile *file = files[i];
|
||||
for (InputSection *isec : file->sections) {
|
||||
if (!isec)
|
||||
continue;
|
||||
OutputSection *osec = isec->output_section;
|
||||
vec[osec->idx].push_back(isec);
|
||||
}
|
||||
}
|
||||
return vec;
|
||||
};
|
||||
|
||||
auto reduce = [](const T &x, const T &y) {
|
||||
T ret = x;
|
||||
for (int i = 0; i < y.size(); i++)
|
||||
ret[i].insert(ret[i].end(), y[i].begin(), y[i].end());
|
||||
return ret;
|
||||
};
|
||||
|
||||
std::vector<std::vector<InputSection *>> vec =
|
||||
tbb::parallel_reduce(tbb::blocked_range<int>(0, files.size()),
|
||||
T(OutputSection::all_instances.size()),
|
||||
fn, reduce, tbb::static_partitioner());
|
||||
int unit = (files.size() + 127) / 128;
|
||||
std::vector<ArrayRef<ObjectFile *>> slices = split(files, unit);
|
||||
|
||||
std::vector<std::vector<std::vector<InputSection *>>> vec(slices.size());
|
||||
for (int i = 0; i < vec.size(); i++)
|
||||
OutputSection::all_instances[i]->sections = std::move(vec[i]);
|
||||
vec[i].resize(OutputSection::instances.size());
|
||||
|
||||
tbb::parallel_for(0, (int)slices.size(), [&](int i) {
|
||||
for (ObjectFile *file : slices[i]) {
|
||||
for (InputSection *isec : file->sections) {
|
||||
if (!isec)
|
||||
continue;
|
||||
OutputSection *osec = isec->output_section;
|
||||
vec[i][osec->idx].push_back(isec);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<int> sizes(OutputSection::instances.size());
|
||||
|
||||
for (ArrayRef<std::vector<InputSection *>> slice : vec)
|
||||
for (int i = 0; i < slice.size(); i++)
|
||||
sizes[i] += slice[i].size();
|
||||
|
||||
for (int i = 0; i < sizes.size(); i++)
|
||||
OutputSection::instances[i]->sections.reserve(sizes[i]);
|
||||
|
||||
for (ArrayRef<std::vector<InputSection *>> slice : vec) {
|
||||
for (int i = 0; i < slice.size(); i++) {
|
||||
std::vector<InputSection *> §ions = OutputSection::instances[i]->sections;
|
||||
sections.insert(sections.end(), slice[i].begin(), slice[i].end());
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (ObjectFile *file : files) {
|
||||
for (InputSection *isec : file->sections) {
|
||||
@ -160,7 +162,7 @@ static void bin_sections(std::vector<ObjectFile *> &files) {
|
||||
|
||||
static void set_isec_offsets() {
|
||||
#if 1
|
||||
for_each(OutputSection::all_instances, [&](OutputSection *osec) {
|
||||
for_each(OutputSection::instances, [&](OutputSection *osec) {
|
||||
if (osec->sections.empty())
|
||||
return;
|
||||
|
||||
@ -198,7 +200,7 @@ static void set_isec_offsets() {
|
||||
osec->shdr.sh_addralign = align;
|
||||
});
|
||||
#else
|
||||
for_each(OutputSection::all_instances, [&](OutputSection *osec) {
|
||||
for_each(OutputSection::instances, [&](OutputSection *osec) {
|
||||
if (osec->sections.empty())
|
||||
return;
|
||||
|
||||
@ -247,7 +249,7 @@ static bool is_osec_empty(OutputSection *osec) {
|
||||
|
||||
static std::vector<OutputSection *> get_output_sections() {
|
||||
std::vector<OutputSection *> vec;
|
||||
for (OutputSection *osec : OutputSection::all_instances)
|
||||
for (OutputSection *osec : OutputSection::instances)
|
||||
if (!is_osec_empty(osec))
|
||||
vec.push_back(osec);
|
||||
|
||||
|
6
mold.h
6
mold.h
@ -288,8 +288,8 @@ public:
|
||||
this->name = name;
|
||||
shdr.sh_flags = flags;
|
||||
shdr.sh_type = type;
|
||||
idx = all_instances.size();
|
||||
all_instances.push_back(this);
|
||||
idx = instances.size();
|
||||
instances.push_back(this);
|
||||
}
|
||||
|
||||
void copy_to(uint8_t *buf) override {
|
||||
@ -309,7 +309,7 @@ public:
|
||||
std::vector<InputSection *> sections;
|
||||
uint32_t idx;
|
||||
|
||||
static std::vector<OutputSection *> all_instances;
|
||||
static std::vector<OutputSection *> instances;
|
||||
};
|
||||
|
||||
class InterpSection : public OutputChunk {
|
||||
|
@ -10,7 +10,7 @@ ShstrtabSection *out::shstrtab;
|
||||
SymtabSection *out::symtab;
|
||||
StrtabSection *out::strtab;
|
||||
|
||||
std::vector<OutputSection *> OutputSection::all_instances;
|
||||
std::vector<OutputSection *> OutputSection::instances;
|
||||
|
||||
void OutputEhdr::relocate(uint8_t *buf) {
|
||||
auto *hdr = (ELF64LE::Ehdr *)buf;
|
||||
@ -143,7 +143,7 @@ OutputSection::get_instance(StringRef name, uint64_t flags, uint32_t type) {
|
||||
flags = flags & ~SHF_GROUP;
|
||||
|
||||
auto find = [&]() -> OutputSection * {
|
||||
for (OutputSection *osec : OutputSection::all_instances)
|
||||
for (OutputSection *osec : OutputSection::instances)
|
||||
if (name == osec->name && flags == (osec->shdr.sh_flags & ~SHF_GROUP) &&
|
||||
type == osec->shdr.sh_type)
|
||||
return osec;
|
||||
|
Loading…
Reference in New Issue
Block a user