From 961205a6622ebda424922ea59c1d57ef45c82506 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 15 Oct 2020 19:55:51 +0900 Subject: [PATCH] temporary --- chibild.h | 18 ++++++++---------- output_sections.cc | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/chibild.h b/chibild.h index f5e1036b..785cef7f 100644 --- a/chibild.h +++ b/chibild.h @@ -19,8 +19,9 @@ #include "tbb/partitioner.h" #include -#include #include +#include +#include #include #include @@ -159,27 +160,24 @@ protected: class OutputEhdr : public OutputChunk { public: - uint64_t get_size() const override { - return sizeof(hdr); - } + void writeTo(uint8_t *buf) override; + uint64_t get_size() const override; ELF64LE::Ehdr hdr; }; class OutputShdr : public OutputChunk { public: - uint64_t get_size() const override { - return hdr.size() * sizeof(hdr[0]); - } + void writeTo(uint8_t *buf) override; + uint64_t get_size() const override; std::vector hdr; }; class OutputPhdr : public OutputChunk { public: - uint64_t get_size() const override { - return hdr.size() * sizeof(hdr[0]); - } + void writeTo(uint8_t *buf) override; + uint64_t get_size() const override; std::vector hdr; }; diff --git a/output_sections.cc b/output_sections.cc index 5abfb585..4b8ea493 100644 --- a/output_sections.cc +++ b/output_sections.cc @@ -1,5 +1,29 @@ #include "chibild.h" +void OutputEhdr::writeTo(uint8_t *buf) { + memcpy(buf + offset, &hdr, sizeof(hdr)); +} + +uint64_t OutputEhdr::get_size() const { + return sizeof(hdr); +} + +void OutputShdr::writeTo(uint8_t *buf) { + memcpy(buf + offset, &hdr[0], get_size()); +} + +uint64_t OutputShdr::get_size() const { + return hdr.size() * sizeof(hdr[0]); +} + +void OutputPhdr::writeTo(uint8_t *buf) { + memcpy(buf + offset, &hdr[0], get_size()); +} + +uint64_t OutputPhdr::get_size() const { + return hdr.size() * sizeof(hdr[0]); +} + OutputSection::OutputSection(StringRef name) : name(name) {} uint64_t OutputSection::get_size() const {