From bde5c4af0f5b4defb752bd2f924eff2861239f65 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 25 Oct 2020 10:47:57 +0900 Subject: [PATCH] temporary --- main.cc | 9 +-------- mold.h | 16 +++++++++++----- output_chunks.cc | 9 +++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/main.cc b/main.cc index 8a447626..ea70a5e4 100644 --- a/main.cc +++ b/main.cc @@ -143,10 +143,6 @@ static std::vector get_output_sections() { return vec; } -static std::vector create_phdrs() { - return {}; -} - static std::vector create_shdrs(ArrayRef output_chunks) { static ELF64LE::Shdr null_entry = {}; @@ -304,7 +300,7 @@ int main(int argc, char **argv) { output_chunks.push_back(out::shdr); // Create program header contents. - out::phdr->hdr = create_phdrs(); + out::phdr->construct(output_chunks); // Assign offsets to input sections uint64_t filesize = 0; @@ -316,9 +312,6 @@ int main(int argc, char **argv) { } } - // Fill section header. - fill_shdrs(output_chunks); - { MyTimer t("unlink", before_copy); unlink_async(tg, config.output); diff --git a/mold.h b/mold.h index 937afbfb..eb81bdd6 100644 --- a/mold.h +++ b/mold.h @@ -259,15 +259,21 @@ public: // Program header class OutputPhdr : public OutputChunk { public: - void copy_to(uint8_t *buf) override { - memcpy(buf + offset, &hdr[0], get_size()); - } + void copy_to(uint8_t *buf) override; uint64_t get_size() const override { - return hdr.size() * sizeof(ELF64LE::Phdr[0]); + return entries.size() * sizeof(ELF64LE::Phdr); } - std::vector hdr; + void construct(std::vector §ions); + +private: + struct Phdr { + ELF64LE::Phdr phdr; + std::vector members; + }; + + std::vector entries; }; // Sections diff --git a/output_chunks.cc b/output_chunks.cc index 4fd1a096..02b11867 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -33,6 +33,15 @@ void OutputEhdr::relocate(uint8_t *buf) { hdr->e_shstrndx = out::shstrtab->index; } +void OutputPhdr::copy_to(uint8_t *buf) { + auto *p = (ELF64LE::Phdr *)buf; + for (Phdr &ent : entries) + *p++ = ent.phdr; +} + +void OutputPhdr::construct(std::vector &chunks) { +} + void OutputSection::set_offset(uint64_t off) { offset = off; for (int i = 0; i < chunks.size(); i++) {