1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-26 18:02:30 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-29 22:32:55 +09:00
parent fb824e144a
commit a9b203ee2b
6 changed files with 37 additions and 36 deletions

View File

@ -154,7 +154,7 @@ void ObjectFile::read_string_pieces(const ELF64LE::Shdr &shdr) {
bool is_alloc = shdr.sh_type & SHF_ALLOC;
ConcurrentMap<StringPiece> &map = is_alloc ? map1 : map2;
ArrayRef<uint8_t> arr = CHECK(obj.getSectionContents(shdr), this);
ArrayRef<u8> arr = CHECK(obj.getSectionContents(shdr), this);
StringRef data((const char *)&arr[0], arr.size());
while (!data.empty()) {
@ -360,9 +360,9 @@ void ObjectFile::compute_symtab() {
}
void
ObjectFile::write_local_symtab(uint8_t *buf, u64 symtab_off, u64 strtab_off) {
uint8_t *symtab = buf + out::symtab->shdr.sh_offset;
uint8_t *strtab = buf + out::strtab->shdr.sh_offset;
ObjectFile::write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off) {
u8 *symtab = buf + out::symtab->shdr.sh_offset;
u8 *strtab = buf + out::strtab->shdr.sh_offset;
for (int i = 0; i < first_global; i++) {
const ELF64LE::Sym &esym = elf_syms[i];
@ -387,9 +387,9 @@ ObjectFile::write_local_symtab(uint8_t *buf, u64 symtab_off, u64 strtab_off) {
}
void
ObjectFile::write_global_symtab(uint8_t *buf, u64 symtab_off, u64 strtab_off) {
uint8_t *symtab = buf + out::symtab->shdr.sh_offset;
uint8_t *strtab = buf + out::strtab->shdr.sh_offset;
ObjectFile::write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off) {
u8 *symtab = buf + out::symtab->shdr.sh_offset;
u8 *strtab = buf + out::strtab->shdr.sh_offset;
for (int i = first_global; i < elf_syms.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[i];

View File

@ -17,11 +17,11 @@ InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRe
error(toString(file) + ": section sh_addralign is not a power of two");
}
void InputSection::copy_to(uint8_t *buf) {
void InputSection::copy_to(u8 *buf) {
if (shdr.sh_type == SHT_NOBITS || shdr.sh_size == 0)
return;
ArrayRef<uint8_t> data = check(file->obj.getSectionContents(shdr));
ArrayRef<u8> data = check(file->obj.getSectionContents(shdr));
buf = buf + output_section->shdr.sh_offset + offset;
memcpy_nontemporal(buf, &data[0], data.size());
}
@ -60,11 +60,11 @@ std::tuple<u64, u64> InputSection::scan_relocations() {
return {num_got, num_plt};
}
void InputSection::relocate(uint8_t *buf) {
void InputSection::relocate(u8 *buf) {
int i = 0;
for (const ELF64LE::Rela &rel : rels) {
u32 sym_idx = rel.getSymbol(false);
uint8_t *loc = buf + output_section->shdr.sh_offset + offset + rel.r_offset;
u8 *loc = buf + output_section->shdr.sh_offset + offset + rel.r_offset;
u64 cur = output_section->shdr.sh_addr + offset + rel.r_offset;
Symbol *sym = file->get_symbol(sym_idx);

View File

@ -322,7 +322,7 @@ static void unlink_async(tbb::task_group &tg, StringRef path) {
tg.run([=]() { close(fd); });
}
static void write_symtab(uint8_t *buf, std::vector<ObjectFile *> files) {
static void write_symtab(u8 *buf, std::vector<ObjectFile *> files) {
std::vector<u64> symtab_off(files.size() + 1);
std::vector<u64> strtab_off(files.size() + 1);
strtab_off[0] = 1;
@ -583,7 +583,7 @@ int main(int argc, char **argv) {
llvm::toString(buf_or_err.takeError()));
std::unique_ptr<FileOutputBuffer> output_buffer = std::move(*buf_or_err);
uint8_t *buf = output_buffer->getBufferStart();
u8 *buf = output_buffer->getBufferStart();
// Fill .symtab and .strtab
tbb::task_group tg_symtab;

41
mold.h
View File

@ -45,6 +45,7 @@
#define SECTOR_SIZE 512
#define PAGE_SIZE 4096
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
@ -182,7 +183,7 @@ public:
u64 plt_addr = 0;
u64 value;
uint8_t visibility = 0;
u8 visibility = 0;
bool is_weak = false;
std::atomic_bool needs_got = ATOMIC_VAR_INIT(false);
@ -201,8 +202,8 @@ class InputSection {
public:
InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRef name);
void copy_to(uint8_t *buf);
void relocate(uint8_t *buf);
void copy_to(u8 *buf);
void relocate(u8 *buf);
std::tuple<u64, u64> scan_relocations();
ObjectFile *file;
@ -229,8 +230,8 @@ class OutputChunk {
public:
OutputChunk() { shdr.sh_addralign = 1; }
virtual void copy_to(uint8_t *buf) = 0;
virtual void relocate(uint8_t *buf) {}
virtual void copy_to(u8 *buf) = 0;
virtual void relocate(u8 *buf) {}
bool is_bss() const { return shdr.sh_type == llvm::ELF::SHT_NOBITS; }
@ -248,8 +249,8 @@ class OutputEhdr : public OutputChunk {
public:
OutputEhdr() { shdr.sh_flags = llvm::ELF::SHF_ALLOC; }
void copy_to(uint8_t *buf) override {}
void relocate(uint8_t *buf) override;
void copy_to(u8 *buf) override {}
void relocate(u8 *buf) override;
u64 get_size() const override {
return sizeof(ELF64LE::Ehdr);
@ -261,7 +262,7 @@ class OutputShdr : public OutputChunk {
public:
OutputShdr() { shdr.sh_flags = llvm::ELF::SHF_ALLOC; }
void copy_to(uint8_t *buf) override {
void copy_to(u8 *buf) override {
auto *p = (ELF64LE::Shdr *)(buf + shdr.sh_offset);
for (ELF64LE::Shdr *ent : entries)
*p++ = *ent;
@ -279,7 +280,7 @@ class OutputPhdr : public OutputChunk {
public:
OutputPhdr() { shdr.sh_flags = llvm::ELF::SHF_ALLOC; }
void copy_to(uint8_t *buf) override;
void copy_to(u8 *buf) override;
u64 get_size() const override {
return entries.size() * sizeof(ELF64LE::Phdr);
@ -309,12 +310,12 @@ public:
instances.push_back(this);
}
void copy_to(uint8_t *buf) override {
void copy_to(u8 *buf) override {
if (!is_bss())
for_each(sections, [&](InputSection *isec) { isec->copy_to(buf); });
}
void relocate(uint8_t *buf) override {
void relocate(u8 *buf) override {
if (!is_bss())
for_each(sections, [&](InputSection *isec) { isec->relocate(buf); });
}
@ -344,7 +345,7 @@ public:
shdr.sh_type = llvm::ELF::SHT_PROGBITS;
}
void copy_to(uint8_t *buf) override {
void copy_to(u8 *buf) override {
memcpy(buf + shdr.sh_offset, path, sizeof(path));
}
@ -364,9 +365,9 @@ public:
shdr.sh_addralign = 8;
}
void copy_to(uint8_t *buf) override {}
void copy_to(u8 *buf) override {}
void relocate(uint8_t *buf) override {
void relocate(u8 *buf) override {
buf += shdr.sh_offset;
for (Symbol *sym : symbols) {
*(u64 *)buf = sym->addr;
@ -396,7 +397,7 @@ public:
return ret;
}
void copy_to(uint8_t *buf) override {
void copy_to(u8 *buf) override {
memcpy(buf + shdr.sh_offset, &contents[0], contents.size());
}
@ -416,7 +417,7 @@ public:
shdr.sh_addralign = 8;
}
void copy_to(uint8_t *buf) override {}
void copy_to(u8 *buf) override {}
u64 get_size() const override { return size; }
u64 size = 0;
@ -433,7 +434,7 @@ public:
shdr.sh_type = llvm::ELF::SHT_STRTAB;
}
void copy_to(uint8_t *buf) override {}
void copy_to(u8 *buf) override {}
u64 get_size() const override { return size; }
u64 size = 1;
@ -486,8 +487,8 @@ public:
void fix_sym_addrs();
void compute_symtab();
void write_local_symtab(uint8_t *buf, u64 symtab_off, u64 strtab_off);
void write_global_symtab(uint8_t *buf, u64 symtab_off, u64 strtab_off);
void write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
void write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off);
StringRef get_filename();
bool is_in_archive();
@ -565,7 +566,7 @@ public:
private:
std::unique_ptr<llvm::FileOutputBuffer> output_buffer;
uint8_t *buf;
u8 *buf;
};
//

View File

@ -13,7 +13,7 @@ StrtabSection *out::strtab;
std::vector<OutputSection *> OutputSection::instances;
void OutputEhdr::relocate(uint8_t *buf) {
void OutputEhdr::relocate(u8 *buf) {
auto *hdr = (ELF64LE::Ehdr *)buf;
memset(hdr, 0, sizeof(*hdr));
@ -108,7 +108,7 @@ void OutputPhdr::construct(std::vector<OutputChunk *> &chunks) {
ent.members.front()->starts_new_ptload = true;
}
void OutputPhdr::copy_to(uint8_t *buf) {
void OutputPhdr::copy_to(u8 *buf) {
for (Phdr &ent : entries) {
OutputChunk *front = ent.members.front();
OutputChunk *back = ent.members.back();

View File

@ -17,7 +17,7 @@ static std::unique_ptr<FileOutputBuffer> open_output_file() {
void write() {
std::unique_ptr<FileOutputBuffer> buffer = open_output_file();
uint8_t *buf = buffer->getBufferStart();
u8 *buf = buffer->getBufferStart();
memset(buf, 0, sizeof(ELF64LE::Ehdr));
memcpy(buf, "\177ELF", 4);