diff --git a/main.cc b/main.cc index a58fead7..9f13e134 100644 --- a/main.cc +++ b/main.cc @@ -116,8 +116,9 @@ static std::vector create_phdrs() { static std::vector create_shdrs(ArrayRef output_chunks) { std::vector vec; + vec.push_back({}); for (OutputChunk *chunk : output_chunks) - if (ELF64LE::Shdr *hdr = chunk->get_shdr()) + if (const ELF64LE::Shdr *hdr = chunk->get_shdr()) vec.push_back(*hdr); return vec; } diff --git a/mold.h b/mold.h index 652f318a..f5e0163a 100644 --- a/mold.h +++ b/mold.h @@ -243,7 +243,7 @@ public: uint64_t get_offset() const { return offset; } virtual uint64_t get_size() const = 0; virtual StringRef get_name() const { return ""; } - virtual ELF64LE::Shdr *get_shdr() const { return nullptr; } + virtual const ELF64LE::Shdr *get_shdr() const { return nullptr; } protected: int64_t offset = -1; @@ -314,12 +314,13 @@ public: void set_offset(uint64_t off) override; StringRef get_name() const override { return name; } - ELF64LE::Shdr *get_shdr() const override { return nullptr; } + const ELF64LE::Shdr *get_shdr() const override { return &hdr; } std::vector chunks; StringRef name; private: + ELF64LE::Shdr hdr = {}; uint64_t file_offset = 0; uint64_t on_file_size = -1; };