1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-12-10 21:13:02 +09:00
parent 4071f1076b
commit e46294562c
3 changed files with 23 additions and 12 deletions

View File

@ -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);

15
mold.h
View File

@ -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<ELF64LE::Phdr> create_phdr();
std::vector<ElfPhdr> create_phdr();
//
// object_file.cc

View File

@ -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<ELF64LE::Phdr> create_phdr() {
std::vector<ELF64LE::Phdr> vec;
std::vector<ElfPhdr> create_phdr() {
std::vector<ElfPhdr> 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<u64>(align, chunk->shdr.sh_addralign);
@ -72,7 +72,7 @@ std::vector<ELF64LE::Phdr> create_phdr() {
};
auto append = [&](OutputChunk *chunk) {
ELF64LE::Phdr &phdr = vec.back();
ElfPhdr &phdr = vec.back();
phdr.p_align = std::max<u64>(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<ELF64LE::Phdr> 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() {