mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
temporary
This commit is contained in:
parent
86781e9b64
commit
a0c224fc9d
@ -91,6 +91,11 @@ class ObjectFile;
|
|||||||
|
|
||||||
std::string toString(ObjectFile *);
|
std::string toString(ObjectFile *);
|
||||||
|
|
||||||
|
template<typename T, typename Callable>
|
||||||
|
static void for_each(T &arr, Callable callback) {
|
||||||
|
tbb::parallel_for_each(arr.begin(), arr.end(), callback);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Interned string
|
// Interned string
|
||||||
//
|
//
|
||||||
@ -267,8 +272,7 @@ public:
|
|||||||
OutputSection(StringRef name) : name(name) {}
|
OutputSection(StringRef name) : name(name) {}
|
||||||
|
|
||||||
void copy_to(uint8_t *buf) override {
|
void copy_to(uint8_t *buf) override {
|
||||||
for (InputSection *sec : sections)
|
for_each(sections, [&](InputSection *isec) { isec->copy_to(buf); });
|
||||||
sec->copy_to(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void relocate(uint8_t *buf) override {}
|
void relocate(uint8_t *buf) override {}
|
||||||
|
61
main.cc
61
main.cc
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
using llvm::FileOutputBuffer;
|
||||||
using llvm::file_magic;
|
using llvm::file_magic;
|
||||||
using llvm::object::Archive;
|
using llvm::object::Archive;
|
||||||
using llvm::opt::InputArgList;
|
using llvm::opt::InputArgList;
|
||||||
@ -99,11 +100,6 @@ static std::vector<ObjectFile *> read_file(StringRef path) {
|
|||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename Callable>
|
|
||||||
static void for_each(T &arr, Callable callback) {
|
|
||||||
tbb::parallel_for_each(arr.begin(), arr.end(), callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// Parse command line options
|
// Parse command line options
|
||||||
MyOptTable opt_table;
|
MyOptTable opt_table;
|
||||||
@ -122,6 +118,7 @@ int main(int argc, char **argv) {
|
|||||||
llvm::Timer comdat_timer("comdat", "comdat");
|
llvm::Timer comdat_timer("comdat", "comdat");
|
||||||
llvm::Timer output_section_timer("output_section", "output_section");
|
llvm::Timer output_section_timer("output_section", "output_section");
|
||||||
llvm::Timer file_offset_timer("file_offset", "file_offset");
|
llvm::Timer file_offset_timer("file_offset", "file_offset");
|
||||||
|
llvm::Timer copy_timer("copy", "copy");
|
||||||
|
|
||||||
// Open input files
|
// Open input files
|
||||||
open_timer.startTimer();
|
open_timer.startTimer();
|
||||||
@ -159,7 +156,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Bin input sections into output sections
|
// Bin input sections into output sections
|
||||||
std::vector<OutputSection *> output_sections;
|
std::vector<OutputSection *> output_sections;
|
||||||
|
|
||||||
output_section_timer.startTimer();
|
output_section_timer.startTimer();
|
||||||
for (ObjectFile *file : files) {
|
for (ObjectFile *file : files) {
|
||||||
for (InputSection *isec : file->sections) {
|
for (InputSection *isec : file->sections) {
|
||||||
@ -174,45 +170,46 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
output_section_timer.stopTimer();
|
output_section_timer.stopTimer();
|
||||||
|
|
||||||
|
// Assign offsets to input sections
|
||||||
file_offset_timer.startTimer();
|
file_offset_timer.startTimer();
|
||||||
uint64_t off = 0;
|
uint64_t filesize = 0;
|
||||||
for (OutputSection *osec : output_sections) {
|
for (OutputSection *osec : output_sections) {
|
||||||
for (InputSection *isec : osec->sections) {
|
for (InputSection *isec : osec->sections) {
|
||||||
off = align_to(off, isec->alignment);
|
filesize = align_to(filesize, isec->alignment);
|
||||||
isec->output_file_offset = off;
|
isec->output_file_offset = filesize;
|
||||||
off += isec->get_size();
|
filesize += isec->get_size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_offset_timer.stopTimer();
|
file_offset_timer.stopTimer();
|
||||||
|
|
||||||
#if 0
|
llvm::outs() << " osec=" << output_sections.size() << "\n"
|
||||||
int max_align = 0;
|
<< " filesize=" << filesize << "\n"
|
||||||
for (OutputSection *osec : output_sections) {
|
<< " num_defined=" << num_defined << "\n"
|
||||||
for (InputSection *isec : osec->sections) {
|
<< "num_undefined=" << num_undefined << "\n";
|
||||||
if (isec->alignment > max_align) {
|
|
||||||
llvm::outs() << toString(isec) << " " << isec->alignment << "\n";
|
|
||||||
max_align = isec->alignment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
// Create an output file
|
||||||
int64_t filesize = 0;
|
Expected<std::unique_ptr<FileOutputBuffer>> buf_or_err =
|
||||||
for (OutputSection *sec : output_sections) {
|
FileOutputBuffer::create(config.output, filesize, 0);
|
||||||
sec->set_offset(filesize);
|
|
||||||
filesize += sec->get_size();
|
if (!buf_or_err)
|
||||||
}
|
error("failed to open " + config.output + ": " +
|
||||||
#endif
|
llvm::toString(buf_or_err.takeError()));
|
||||||
|
|
||||||
|
std::unique_ptr<FileOutputBuffer> output_buffer = std::move(*buf_or_err);
|
||||||
|
uint8_t *buf = output_buffer->getBufferStart();
|
||||||
|
|
||||||
|
// Copy input sections to the output file
|
||||||
|
copy_timer.startTimer();
|
||||||
|
for_each(output_sections, [&](OutputSection *osec) { osec->copy_to(buf); });
|
||||||
|
copy_timer.stopTimer();
|
||||||
|
|
||||||
|
if (auto e = output_buffer->commit())
|
||||||
|
error("failed to write to the output file: " + toString(std::move(e)));
|
||||||
|
|
||||||
out::ehdr = new OutputEhdr;
|
out::ehdr = new OutputEhdr;
|
||||||
out::shdr = new OutputShdr;
|
out::shdr = new OutputShdr;
|
||||||
out::phdr = new OutputPhdr;
|
out::phdr = new OutputPhdr;
|
||||||
|
|
||||||
llvm::outs() << " osec=" << output_sections.size() << "\n";
|
|
||||||
llvm::outs() << " num_defined=" << num_defined << "\n"
|
|
||||||
<< "num_undefined=" << num_undefined << "\n";
|
|
||||||
|
|
||||||
llvm::TimerGroup::printAll(llvm::outs());
|
llvm::TimerGroup::printAll(llvm::outs());
|
||||||
llvm::outs().flush();
|
llvm::outs().flush();
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user