1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-25 17:34:02 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-12-12 12:44:22 +09:00
parent 22f8add31c
commit 59da68d156
2 changed files with 17 additions and 5 deletions

6
mold.h
View File

@ -951,11 +951,7 @@ struct ComdatGroup {
class InputFile {
public:
InputFile(MemoryMappedFile mb)
: mb(mb), name(mb.name), obj(mb), ehdr(*(ElfEhdr *)mb.data) {
elf_sections = obj.get_sections();
is_dso = (ehdr.e_type == ET_DYN);
}
InputFile(MemoryMappedFile mb);
MemoryMappedFile mb;
ElfFile obj;

View File

@ -3,6 +3,22 @@
#include <cstring>
#include <regex>
InputFile::InputFile(MemoryMappedFile mb)
: mb(mb), name(mb.name), obj(mb), ehdr(*(ElfEhdr *)mb.data),
is_dso(ehdr.e_type == ET_DYN) {
if (mb.size < sizeof(ElfEhdr))
error(mb.name + ": file too small");
if (memcmp(mb.data, "\177ELF", 4))
error(mb.name + ": not an ELF file");
u8 *sh_begin = mb.data + ehdr.e_shoff;
u8 *sh_end = sh_begin + ehdr.e_shnum * sizeof(ElfShdr);
if (mb.data + mb.size < sh_end)
error(mb.name + ": e_shoff or e_shnum corrupted: " +
std::to_string(mb.size) + " " + std::to_string(ehdr.e_shnum));
elf_sections = {(ElfShdr *)sh_begin, (ElfShdr *)sh_end};
}
ObjectFile::ObjectFile(MemoryMappedFile mb, std::string_view archive_name)
: InputFile(mb), archive_name(archive_name),
is_in_archive(archive_name != "") {