From e46294562c98e2afe06dd8627337d13c25f66077 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 10 Dec 2020 21:13:02 +0900 Subject: [PATCH] temporary --- main.cc | 2 +- mold.h | 15 +++++++++++++-- output_chunks.cc | 18 +++++++++--------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/main.cc b/main.cc index 242663a9..477489e7 100644 --- a/main.cc +++ b/main.cc @@ -1042,7 +1042,7 @@ int main(int argc, char **argv) { // Some types of relocations for TLS symbols need the ending address // of the TLS section. Find it out now. - for (ELF64LE::Phdr phdr : create_phdr()) + for (ElfPhdr phdr : create_phdr()) if (phdr.p_type == PT_TLS) out::tls_end = align_to(phdr.p_vaddr + phdr.p_memsz, phdr.p_align); diff --git a/mold.h b/mold.h index d4418bcd..1067512a 100644 --- a/mold.h +++ b/mold.h @@ -185,6 +185,17 @@ struct ElfEhdr { u16 e_shstrndx; }; +struct ElfPhdr { + u32 p_type; + u32 p_flags; + u64 p_offset; + u64 p_vaddr; + u64 p_paddr; + u64 p_filesz; + u64 p_memsz; + u64 p_align; +}; + struct ElfRela { u64 r_offset; @@ -401,7 +412,7 @@ class OutputEhdr : public OutputChunk { public: OutputEhdr() : OutputChunk(HEADER) { shdr.sh_flags = llvm::ELF::SHF_ALLOC; - shdr.sh_size = sizeof(ELF64LE::Ehdr); + shdr.sh_size = sizeof(ElfEhdr); } void copy_buf() override; @@ -723,7 +734,7 @@ public: }; bool is_c_identifier(std::string_view name); -std::vector create_phdr(); +std::vector create_phdr(); // // object_file.cc diff --git a/output_chunks.cc b/output_chunks.cc index ae8dc0ec..9d1253d5 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -5,7 +5,7 @@ using namespace llvm::ELF; void OutputEhdr::copy_buf() { - auto &hdr = *(ELF64LE::Ehdr *)(out::buf + shdr.sh_offset); + auto &hdr = *(ElfEhdr *)(out::buf + shdr.sh_offset); memset(&hdr, 0, sizeof(hdr)); memcpy(&hdr.e_ident, "\177ELF", 4); @@ -18,9 +18,9 @@ void OutputEhdr::copy_buf() { hdr.e_entry = Symbol::intern("_start")->get_addr(); hdr.e_phoff = out::phdr->shdr.sh_offset; hdr.e_shoff = out::shdr->shdr.sh_offset; - hdr.e_ehsize = sizeof(ELF64LE::Ehdr); - hdr.e_phentsize = sizeof(ELF64LE::Phdr); - hdr.e_phnum = out::phdr->shdr.sh_size / sizeof(ELF64LE::Phdr); + hdr.e_ehsize = sizeof(ElfEhdr); + hdr.e_phentsize = sizeof(ElfPhdr); + hdr.e_phnum = out::phdr->shdr.sh_size / sizeof(ElfPhdr); hdr.e_shentsize = sizeof(ElfShdr); hdr.e_shnum = out::shdr->shdr.sh_size / sizeof(ElfShdr); hdr.e_shstrndx = out::shstrtab->shndx; @@ -53,12 +53,12 @@ static u32 to_phdr_flags(OutputChunk *chunk) { return ret; } -std::vector create_phdr() { - std::vector vec; +std::vector create_phdr() { + std::vector vec; auto define = [&](u32 type, u32 flags, u32 align, OutputChunk *chunk) { vec.push_back({}); - ELF64LE::Phdr &phdr = vec.back(); + ElfPhdr &phdr = vec.back(); phdr.p_type = type; phdr.p_flags = flags; phdr.p_align = std::max(align, chunk->shdr.sh_addralign); @@ -72,7 +72,7 @@ std::vector create_phdr() { }; auto append = [&](OutputChunk *chunk) { - ELF64LE::Phdr &phdr = vec.back(); + ElfPhdr &phdr = vec.back(); phdr.p_align = std::max(phdr.p_align, chunk->shdr.sh_addralign); phdr.p_filesz = (chunk->shdr.sh_type == SHT_NOBITS) ? chunk->shdr.sh_offset - phdr.p_offset @@ -128,7 +128,7 @@ std::vector create_phdr() { } void OutputPhdr::update_shdr() { - shdr.sh_size = create_phdr().size() * sizeof(ELF64LE::Phdr); + shdr.sh_size = create_phdr().size() * sizeof(ElfPhdr); } void OutputPhdr::copy_buf() {