mirror of
https://github.com/rui314/mold.git
synced 2024-12-25 17:34:02 +03:00
temporary
This commit is contained in:
parent
ea2f2825db
commit
10c1716443
@ -15,46 +15,6 @@ InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRe
|
||||
error(toString(file) + ": section sh_addralign is not a power of two");
|
||||
}
|
||||
|
||||
static StringPiece *binary_search(ArrayRef<StringPiece *> pieces, u32 offset) {
|
||||
while (!pieces.empty()) {
|
||||
u32 mid = pieces.size() / 2;
|
||||
StringPiece *piece = pieces[mid];
|
||||
|
||||
if (piece->input_offset == offset)
|
||||
return piece;
|
||||
|
||||
if (offset < piece->input_offset)
|
||||
pieces = pieces.slice(0, mid);
|
||||
else
|
||||
pieces = pieces.slice(mid);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void InputSection::set_relocations(ArrayRef<ELF64LE::Rela> rels) {
|
||||
this->rel_pieces.resize(rels.size());
|
||||
|
||||
for (int i = 0; i < rels.size(); i++) {
|
||||
const ELF64LE::Rela &rel = rels[i];
|
||||
u32 sym_idx = rel.getSymbol(false);
|
||||
if (file->first_global <= sym_idx)
|
||||
continue;
|
||||
|
||||
Symbol *sym = file->symbols[sym_idx];
|
||||
ArrayRef<StringPiece *> pieces = sym->input_section->pieces;
|
||||
if (pieces.empty())
|
||||
continue;
|
||||
|
||||
u32 offset = sym->value + rel.r_addend;
|
||||
StringPiece *piece = binary_search(pieces, offset);
|
||||
if (!piece)
|
||||
error(toString(this) + ": bad relocation at " + std::to_string(sym_idx));
|
||||
|
||||
rel_pieces[i].piece = piece;
|
||||
rel_pieces[i].input_offset = piece->input_offset - offset;
|
||||
}
|
||||
}
|
||||
|
||||
void InputSection::copy_to(u8 *buf) {
|
||||
if (shdr.sh_type == SHT_NOBITS || shdr.sh_size == 0)
|
||||
return;
|
||||
|
5
mold.h
5
mold.h
@ -225,17 +225,17 @@ class InputSection {
|
||||
public:
|
||||
InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRef name);
|
||||
|
||||
void set_relocations(ArrayRef<ELF64LE::Rela> rels);
|
||||
void copy_to(u8 *buf);
|
||||
void scan_relocations();
|
||||
|
||||
ObjectFile *file;
|
||||
OutputSection *output_section;
|
||||
ArrayRef<ELF64LE::Rela> rels;
|
||||
std::vector<StringPieceRef> rel_pieces;
|
||||
std::vector<StringPiece *> pieces;
|
||||
const ELF64LE::Shdr &shdr;
|
||||
|
||||
std::vector<StringPieceRef> rel_pieces;
|
||||
|
||||
StringRef name;
|
||||
u64 offset;
|
||||
};
|
||||
@ -577,6 +577,7 @@ private:
|
||||
std::vector<std::pair<ComdatGroup *, u32>> comdat_groups;
|
||||
|
||||
std::vector<Symbol> local_symbols;
|
||||
std::vector<StringPieceRef> sym_pieces;
|
||||
bool has_common_symbol;
|
||||
|
||||
ArrayRef<ELF64LE::Shdr> elf_sections;
|
||||
|
@ -145,10 +145,74 @@ void ObjectFile::initialize_symbols() {
|
||||
}
|
||||
}
|
||||
|
||||
static StringPiece *binary_search(ArrayRef<StringPiece *> pieces, u32 offset) {
|
||||
if (offset < pieces[0]->input_offset)
|
||||
return nullptr;
|
||||
|
||||
while (pieces.size() > 1) {
|
||||
u32 mid = pieces.size() / 2;
|
||||
StringPiece *piece = pieces[mid];
|
||||
|
||||
if (offset < piece->input_offset)
|
||||
pieces = pieces.slice(0, mid);
|
||||
else
|
||||
pieces = pieces.slice(mid);
|
||||
}
|
||||
return pieces[0];
|
||||
}
|
||||
|
||||
void ObjectFile::initialize_mergeable_sections() {
|
||||
for (InputSection *isec : sections)
|
||||
if (isec && (isec->shdr.sh_flags & SHF_STRINGS) && isec->shdr.sh_entsize == 1)
|
||||
read_string_pieces(isec);
|
||||
|
||||
// Initialize rel_pieces
|
||||
for (InputSection *isec : sections) {
|
||||
if (!isec || isec->rels.empty())
|
||||
continue;
|
||||
|
||||
isec->rel_pieces.resize(isec->rels.size());
|
||||
|
||||
for (int i = 0; i < isec->rels.size(); i++) {
|
||||
const ELF64LE::Rela &rel = isec->rels[i];
|
||||
u32 sym_idx = rel.getSymbol(false);
|
||||
if (sym_idx >= this->first_global)
|
||||
continue;
|
||||
|
||||
Symbol *sym = symbols[sym_idx];
|
||||
ArrayRef<StringPiece *> pieces = sym->input_section->pieces;
|
||||
if (pieces.empty())
|
||||
continue;
|
||||
|
||||
u32 offset = sym->value + rel.r_addend;
|
||||
StringPiece *piece = binary_search(pieces, offset);
|
||||
if (!piece)
|
||||
error(toString(this) + ": bad relocation at " + std::to_string(sym_idx));
|
||||
|
||||
isec->rel_pieces[i].piece = piece;
|
||||
isec->rel_pieces[i].input_offset = piece->input_offset - offset;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize sym_pieces
|
||||
sym_pieces.resize(elf_syms.size());
|
||||
|
||||
for (int i = 0; i < elf_syms.size(); i++) {
|
||||
const ELF64LE::Sym &esym = elf_syms[i];
|
||||
if (esym.isAbsolute() || esym.isCommon())
|
||||
continue;
|
||||
|
||||
InputSection *isec = sections[esym.st_shndx];
|
||||
if (!isec || isec->pieces.empty())
|
||||
continue;
|
||||
|
||||
StringPiece *piece = binary_search(isec->pieces, esym.st_value);
|
||||
if (!piece)
|
||||
error(toString(this) + ": bad symbol value");
|
||||
|
||||
sym_pieces[i].piece = piece;
|
||||
sym_pieces[i].input_offset = piece->input_offset - esym.st_value;
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectFile::read_string_pieces(InputSection *isec) {
|
||||
|
Loading…
Reference in New Issue
Block a user