1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-20 09:27:45 +03:00
mold/output_sections.cc

40 lines
1.0 KiB
C++
Raw Normal View History

2020-10-13 14:35:35 +03:00
#include "chibild.h"
2020-10-16 10:38:03 +03:00
using namespace llvm::ELF;
2020-10-17 07:24:48 +03:00
OutputEhdr *out::ehdr;
OutputShdr *out::shdr;
OutputPhdr *out::phdr;
2020-10-17 07:00:53 +03:00
void OutputEhdr::relocate(uint8_t *buf) {
auto *hdr = (ELF64LE::Ehdr *)buf;
memcpy(&hdr->e_ident, "\177ELF", 4);
hdr->e_ident[EI_CLASS] = ELFCLASS64;
hdr->e_ident[EI_DATA] = ELFDATA2LSB;
hdr->e_ident[EI_VERSION] = EV_CURRENT;
hdr->e_ident[EI_OSABI] = 0;
hdr->e_ident[EI_ABIVERSION] = 0;
hdr->e_machine = EM_X86_64;
hdr->e_version = EV_CURRENT;
hdr->e_entry = 0;
2020-10-17 07:24:48 +03:00
hdr->e_phoff = out::phdr->get_offset();
hdr->e_shoff = out::shdr->get_offset();
2020-10-17 07:00:53 +03:00
hdr->e_flags = 0;
hdr->e_ehsize = sizeof(ELF64LE::Ehdr);
hdr->e_phentsize = sizeof(ELF64LE::Phdr);
2020-10-17 07:24:48 +03:00
hdr->e_phnum = out::phdr->hdr.size();
2020-10-17 07:00:53 +03:00
hdr->e_shentsize = sizeof(ELF64LE::Shdr);
2020-10-17 07:24:48 +03:00
hdr->e_shnum = out::shdr->hdr.size();
2020-10-17 07:00:53 +03:00
hdr->e_shstrndx = 0;
2020-10-14 10:27:45 +03:00
}
2020-10-15 13:27:35 +03:00
void OutputSection::set_offset(uint64_t off) {
offset = off;
2020-10-14 10:27:45 +03:00
for (InputSection *sec : sections) {
2020-10-15 13:27:35 +03:00
sec->offset = off;
off += sec->get_size();
2020-10-14 10:27:45 +03:00
}
2020-10-15 13:27:35 +03:00
size = off - offset;
2020-10-14 10:27:45 +03:00
}