1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-26 01:44:29 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-11-03 19:33:46 +09:00
parent 49551c5bfc
commit 5e930b0fb0
3 changed files with 39 additions and 33 deletions

36
main.cc
View File

@ -113,38 +113,6 @@ static std::vector<ArrayRef<T>> split(const std::vector<T> &input, int unit) {
return vec;
}
static ObjectFile *create_internal_file() {
// Create a dummy object file.
static char buf[256];
std::unique_ptr<MemoryBuffer> mb =
MemoryBuffer::getMemBuffer(StringRef(buf, sizeof(buf)));
auto *obj = new ObjectFile(mb->getMemBufferRef(), "");
obj->name = "<internal>";
mb.release();
// Create linker-synthesized symbols.
auto *elf_syms = new std::vector<ELF64LE::Sym>;
auto create = [&](StringRef name) {
Symbol *sym = Symbol::intern(name);
sym->file = obj;
obj->symbols.push_back(sym);
ELF64LE::Sym esym = {};
esym.setType(STT_NOTYPE);
esym.setBinding(STB_GLOBAL);
elf_syms->push_back(esym);
return sym;
};
out::__bss_start = create("__bss_start");
out::__ehdr_start = create("__ehdr_start");
out::__rela_iplt_start = create("__rela_iplt_start");
out::__rela_iplt_end = create("__rela_iplt_end");
obj->elf_syms = *elf_syms;
return obj;
}
static void bin_sections(std::vector<ObjectFile *> &files) {
#if 1
int unit = (files.size() + 127) / 128;
@ -559,7 +527,9 @@ int main(int argc, char **argv) {
for_each(files, [](ObjectFile *file) { file->hanlde_undefined_weak_symbols(); });
}
files.push_back(create_internal_file());
// Create a dummy file containing linker-synthesized symbols
// (e.g. `__bss_start`).
files.push_back(ObjectFile::create_internal_file());
// Eliminate duplicate comdat groups.
{

2
mold.h
View File

@ -535,6 +535,8 @@ public:
bool is_in_archive();
static ObjectFile *create_internal_file();
std::vector<InputSection *> sections;
StringRef archive_name;
ELFFile<ELF64LE> obj;

View File

@ -421,6 +421,40 @@ bool ObjectFile::is_in_archive() {
return !archive_name.empty();
}
ObjectFile *ObjectFile::create_internal_file() {
// Create a dummy object file.
constexpr int bufsz = 256;
char *buf = new char[bufsz];
std::unique_ptr<MemoryBuffer> mb =
MemoryBuffer::getMemBuffer(StringRef(buf, bufsz));
auto *obj = new ObjectFile(mb->getMemBufferRef(), "");
obj->name = "<internal>";
mb.release();
// Create linker-synthesized symbols.
auto *elf_syms = new std::vector<ELF64LE::Sym>;
obj->elf_syms = *elf_syms;
auto add = [&](StringRef name) {
Symbol *sym = Symbol::intern(name);
sym->file = obj;
obj->symbols.push_back(sym);
ELF64LE::Sym esym = {};
esym.setType(STT_NOTYPE);
esym.setBinding(STB_GLOBAL);
elf_syms->push_back(esym);
return sym;
};
out::__bss_start = add("__bss_start");
out::__ehdr_start = add("__ehdr_start");
out::__rela_iplt_start = add("__rela_iplt_start");
out::__rela_iplt_end = add("__rela_iplt_end");
return obj;
}
std::string toString(ObjectFile *obj) {
StringRef s = obj->name;
if (obj->archive_name == "")