From 966dd5de4ab9d546738ca7e618c0cc69054df800 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 22 Oct 2020 20:06:45 +0900 Subject: [PATCH] temporary --- main.cc | 1 + mold.h | 16 +++++++++++++--- output_chunks.cc | 11 ----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/main.cc b/main.cc index a74c1dae..00d51245 100644 --- a/main.cc +++ b/main.cc @@ -171,6 +171,7 @@ static void fill_shdrs(ArrayRef output_chunks) { continue; chunk->hdr.sh_name = out::shstrtab->add_string(chunk->name); + llvm::outs() << "sh_name=" << chunk->hdr.sh_name << "\n"; chunk->hdr.sh_offset = chunk->get_offset(); chunk->hdr.sh_size = chunk->get_size(); chunk->index = i++; diff --git a/mold.h b/mold.h index ca3671b7..aa7eaf50 100644 --- a/mold.h +++ b/mold.h @@ -319,16 +319,26 @@ class StringTableSection : public OutputChunk { public: StringTableSection(StringRef name) { this->name = name; + contents = '\0'; hdr.sh_flags = 0; hdr.sh_type = llvm::ELF::SHT_STRTAB; } - uint64_t add_string(StringRef s); - void copy_to(uint8_t *buf) override; + uint64_t add_string(StringRef s) { + uint64_t ret = contents.size(); + contents += s.str(); + contents += '\0'; + return ret; + } + + void copy_to(uint8_t *buf) override { + memcpy(buf + offset, &contents[0], contents.size()); + } + uint64_t get_size() const override { return contents.size(); } private: - std::string contents = "\0"; + std::string contents; }; namespace out { diff --git a/output_chunks.cc b/output_chunks.cc index 89665abc..126e4c6a 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -78,14 +78,3 @@ OutputSection *OutputSection::get_instance(InputSection *isec) { return osec; return new OutputSection(iname, iflags, isec->hdr->sh_type); } - -uint64_t StringTableSection::add_string(StringRef s) { - uint64_t ret = contents.size(); - contents += s.str(); - contents += "\0"; - return ret; -} - -void StringTableSection::copy_to(uint8_t *buf) { - memcpy(buf + offset, &contents[0], contents.size()); -}