diff --git a/main.cc b/main.cc index bcde43fe..fc024a7c 100644 --- a/main.cc +++ b/main.cc @@ -823,8 +823,7 @@ int main(int argc, char **argv) { if (!config.is_static) { out::interp = new InterpSection; out::dynamic = new DynamicSection; - out::reldyn = new SpecialSection(".rela.dyn", SHT_RELA, SHF_ALLOC, 8, - sizeof(ELF64LE::Rela)); + out::reldyn = new RelDynSection; out::hash = new HashSection; } @@ -959,9 +958,6 @@ int main(int argc, char **argv) { out::symtab->shdr.sh_link = out::strtab->shndx; out::relplt->shdr.sh_link = out::dynsym->shndx; - if (out::reldyn) - out::reldyn->shdr.sh_link = out::dynsym->shndx; - for (OutputChunk *chunk : chunks) chunk->update_shdr(); diff --git a/mold.h b/mold.h index 34306586..11c7836a 100644 --- a/mold.h +++ b/mold.h @@ -439,6 +439,19 @@ public: } }; +class RelDynSection : public OutputChunk { +public: + RelDynSection() : OutputChunk(SYNTHETIC) { + name = ".rela.dyn"; + shdr.sh_type = llvm::ELF::SHT_RELA; + shdr.sh_flags = llvm::ELF::SHF_ALLOC; + shdr.sh_entsize = sizeof(ELF64LE::Rela); + shdr.sh_addralign = 8; + } + + void update_shdr() override; +}; + class StrtabSection : public OutputChunk { public: StrtabSection(StringRef name, u64 flags) : OutputChunk(SYNTHETIC) { @@ -587,7 +600,7 @@ inline InterpSection *interp; inline SpecialSection *got; inline GotPltSection *gotplt; inline SpecialSection *relplt; -inline SpecialSection *reldyn; +inline RelDynSection *reldyn; inline DynamicSection *dynamic; inline StrtabSection *strtab; inline DynstrSection *dynstr; diff --git a/output_chunks.cc b/output_chunks.cc index b3d0df6b..759e5e47 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -179,6 +179,10 @@ static std::vector create_dynamic_section() { return vec; } +void RelDynSection::update_shdr() { + shdr.sh_link = out::dynsym->shndx; +} + void ShstrtabSection::update_shdr() { shdr.sh_size = 1; for (OutputChunk *chunk : out::chunks) {