1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-27 10:23:41 +03:00
This commit is contained in:
Rui Ueyama 2021-03-11 17:58:43 +09:00
parent 1da77d0061
commit 2d0e34fccc
4 changed files with 24 additions and 31 deletions

View File

@ -10,10 +10,12 @@ static u64 read64be(u8 *buf) {
((u64)buf[6] << 8) | (u64)buf[7];
}
InputChunk::InputChunk(ObjectFile *file, const ElfShdr *shdr,
std::string_view name)
InputSection::InputSection(ObjectFile *file, const ElfShdr *shdr,
std::string_view name, i64 section_idx)
: file(file), shdr(shdr), name(name),
output_section(OutputSection::get_instance(name, shdr->sh_type, shdr->sh_flags)) {
output_section(OutputSection::get_instance(name, shdr->sh_type,
shdr->sh_flags)),
section_idx(section_idx) {
auto do_uncompress = [&](std::string_view data, u64 size) {
u8 *buf = new u8[size];
unsigned long size2 = size;

View File

@ -435,7 +435,7 @@ static void set_isec_offsets() {
i64 off = 0;
i64 align = 1;
for (InputChunk *isec : slices[i]) {
for (InputSection *isec : slices[i]) {
off = align_to(off, isec->shdr->sh_addralign);
isec->offset = off;
off += isec->shdr->sh_size;
@ -453,7 +453,7 @@ static void set_isec_offsets() {
start[i] = align_to(start[i - 1] + size[i - 1], align);
tbb::parallel_for((i64)1, (i64)slices.size(), [&](i64 i) {
for (InputChunk *isec : slices[i])
for (InputSection *isec : slices[i])
isec->offset += start[i];
});

View File

@ -6,7 +6,7 @@
void print_map() {
// Construct a section-to-symbol map.
std::unordered_map<InputChunk *, std::vector<Symbol *>> map;
std::unordered_map<InputSection *, std::vector<Symbol *>> map;
for (ObjectFile *file : out::objs)
for (Symbol *sym : file->symbols)
if (sym->file == file && sym->input_section)
@ -27,7 +27,7 @@ void print_map() {
if (osec->kind != OutputChunk::REGULAR)
continue;
for (InputChunk *mem : ((OutputSection *)osec)->members) {
for (InputSection *mem : ((OutputSection *)osec)->members) {
std::cout << std::setw(16) << (osec->shdr.sh_addr + mem->offset)
<< std::setw(9) << (u64)mem->shdr->sh_size
<< std::setw(6) << (u64)mem->shdr->sh_addralign

39
mold.h
View File

@ -38,7 +38,6 @@ static constexpr i64 PLT_SIZE = 16;
static constexpr i64 PLT_GOT_SIZE = 8;
static constexpr i64 SHA256_SIZE = 32;
class InputChunk;
class InputFile;
class InputSection;
class MergedSection;
@ -310,23 +309,6 @@ std::ostream &operator<<(std::ostream &out, const Symbol &sym);
// input_sections.cc
//
class InputChunk {
public:
virtual void copy_buf() {}
inline u64 get_addr() const;
ObjectFile *file;
const ElfShdr *shdr;
OutputSection *output_section = nullptr;
std::string_view name;
std::string_view contents;
u32 offset = -1;
protected:
InputChunk(ObjectFile *file, const ElfShdr *shdr, std::string_view name);
};
enum RelType : u8 {
R_NONE = 1,
R_ABS,
@ -394,19 +376,28 @@ struct CieRecord {
u32 icf_idx = -1;
};
class InputSection : public InputChunk {
class InputSection {
public:
InputSection(ObjectFile *file, const ElfShdr *shdr, std::string_view name,
i64 section_idx)
: InputChunk(file, shdr, name), section_idx(section_idx) {}
i64 section_idx);
void copy_buf() override;
void scan_relocations();
void report_undefined_symbols();
void copy_buf();
void apply_reloc_alloc(u8 *base);
void apply_reloc_nonalloc(u8 *base);
void kill();
inline i64 get_priority() const;
inline u64 get_addr() const;
ObjectFile *file;
const ElfShdr *shdr;
OutputSection *output_section = nullptr;
std::string_view name;
std::string_view contents;
u32 offset = -1;
std::span<ElfRela> rels;
std::vector<bool> has_fragments;
@ -1026,7 +1017,7 @@ private:
const ElfShdr *symtab_sec;
};
inline std::ostream &operator<<(std::ostream &out, const InputChunk &isec) {
inline std::ostream &operator<<(std::ostream &out, const InputSection &isec) {
out << *isec.file << ":(" << isec.name << ")";
return out;
}
@ -1375,7 +1366,7 @@ inline u64 SectionFragment::get_addr() const {
return output_section.shdr.sh_addr + offset;
}
inline u64 InputChunk::get_addr() const {
inline u64 InputSection::get_addr() const {
return output_section->shdr.sh_addr + offset;
}