mirror of
https://github.com/rui314/mold.git
synced 2024-11-11 05:46:58 +03:00
temporary
This commit is contained in:
parent
dca18cad13
commit
f451c5cba4
@ -28,6 +28,31 @@ void InputSection::copy_to(uint8_t *buf) {
|
||||
memcpy(buf + offset, &data[0], data.size());
|
||||
}
|
||||
|
||||
thread_local int count;
|
||||
|
||||
void InputSection::scan_relocations() {
|
||||
if (rels.empty())
|
||||
return;
|
||||
|
||||
for (const ELF64LE::Rela &rel : rels) {
|
||||
Symbol *sym = file->symbols[rel.getSymbol(false)];
|
||||
if (!sym)
|
||||
continue;
|
||||
|
||||
switch (rel.getType(false)) {
|
||||
case R_X86_64_GOTPCREL:
|
||||
case R_X86_64_TLSGD:
|
||||
case R_X86_64_GOTTPOFF:
|
||||
case R_X86_64_PLT32:
|
||||
if (!sym->needs_got)
|
||||
sym->needs_got = true;
|
||||
break;
|
||||
default:
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputSection::relocate(uint8_t *buf) {
|
||||
if (rels.empty())
|
||||
return;
|
||||
|
@ -241,6 +241,12 @@ void ObjectFile::eliminate_duplicate_comdat_groups() {
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectFile::scan_relocations() {
|
||||
for (InputSection *isec : sections)
|
||||
if (isec)
|
||||
isec->scan_relocations();
|
||||
}
|
||||
|
||||
StringRef ObjectFile::get_filename() {
|
||||
return mb.getBufferIdentifier();
|
||||
}
|
||||
|
7
main.cc
7
main.cc
@ -192,6 +192,7 @@ int main(int argc, char **argv) {
|
||||
llvm::Timer add_symbols_timer("add_symbols", "add_symbols", before_copy);
|
||||
llvm::Timer comdat_timer("comdat", "comdat", before_copy);
|
||||
llvm::Timer bin_sections_timer("bin_sections", "bin_sections", before_copy);
|
||||
llvm::Timer scan_rel_timer("scan_rel", "scan_rel", before_copy);
|
||||
llvm::Timer file_offset_timer("file_offset", "file_offset", before_copy);
|
||||
llvm::Timer copy_timer("copy", "copy");
|
||||
llvm::Timer reloc_timer("reloc", "reloc");
|
||||
@ -235,6 +236,12 @@ int main(int argc, char **argv) {
|
||||
isec->output_section->chunks.push_back(isec);
|
||||
bin_sections_timer.stopTimer();
|
||||
|
||||
// Scan relocations to fix the sizes of .got, .plt, .got.plt, .dynstr,
|
||||
// .rela.dyn, .rela.plt.
|
||||
scan_rel_timer.startTimer();
|
||||
for_each(files, [](ObjectFile *file) { file->scan_relocations(); });
|
||||
scan_rel_timer.stopTimer();
|
||||
|
||||
// Create linker-synthesized sections.
|
||||
out::ehdr = new OutputEhdr;
|
||||
out::phdr = new OutputPhdr;
|
||||
|
11
mold.h
11
mold.h
@ -154,9 +154,11 @@ public:
|
||||
Symbol(StringRef name) : name(name) {}
|
||||
Symbol(const Symbol &other) : name(other.name), file(other.file) {}
|
||||
|
||||
std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
||||
StringRef name;
|
||||
ObjectFile *file = nullptr;
|
||||
std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
||||
std::atomic_bool needs_got;
|
||||
std::atomic_bool needs_plt;
|
||||
};
|
||||
|
||||
inline std::string toString(Symbol sym) {
|
||||
@ -183,8 +185,11 @@ public:
|
||||
class InputSection : public InputChunk {
|
||||
public:
|
||||
InputSection(ObjectFile *file, const ELF64LE::Shdr *hdr, StringRef name);
|
||||
|
||||
void copy_to(uint8_t *buf) override;
|
||||
void relocate(uint8_t *buf) override;
|
||||
void scan_relocations();
|
||||
|
||||
uint64_t get_size() const override;
|
||||
|
||||
ObjectFile *file;
|
||||
@ -376,9 +381,12 @@ public:
|
||||
void register_defined_symbols();
|
||||
void register_undefined_symbols();
|
||||
void eliminate_duplicate_comdat_groups();
|
||||
void scan_relocations();
|
||||
|
||||
StringRef get_filename();
|
||||
bool is_in_archive();
|
||||
|
||||
std::vector<Symbol *> symbols;
|
||||
std::vector<InputSection *> sections;
|
||||
StringRef archive_name;
|
||||
ELFFile<ELF64LE> obj;
|
||||
@ -392,7 +400,6 @@ private:
|
||||
void read_string_pieces(const ELF64LE::Shdr &shdr);
|
||||
|
||||
MemoryBufferRef mb;
|
||||
std::vector<Symbol *> symbols;
|
||||
std::vector<std::pair<ComdatGroup *, uint32_t>> comdat_groups;
|
||||
std::vector<StringPiece *> merged_strings_alloc;
|
||||
std::vector<StringPiece *> merged_strings_noalloc;
|
||||
|
Loading…
Reference in New Issue
Block a user