1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 16:58:12 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-12-13 20:40:01 +09:00
parent 13dfb94621
commit 05e6aea2fd
2 changed files with 19 additions and 23 deletions

3
mold.h
View File

@ -932,6 +932,7 @@ public:
protected:
template<typename T> std::span<T> get_data(const ElfShdr &shdr) const;
template<typename T> std::span<T> get_data(u32 idx) const;
ElfShdr *find_section(u32 type);
};
class ObjectFile : public InputFile {
@ -998,7 +999,7 @@ public:
std::vector<std::string_view> version_strings;
private:
std::string_view get_soname(std::span<ElfShdr> elf_sections);
std::string_view get_soname();
void maybe_override_symbol(Symbol &sym, const ElfSym &esym);
std::vector<std::string_view> read_verdef();

View File

@ -47,20 +47,19 @@ std::span<T> InputFile::get_data(u32 idx) const {
return get_data<T>(elf_sections[idx]);
}
ElfShdr *InputFile::find_section(u32 type) {
for (ElfShdr &sec : elf_sections)
if (sec.sh_type == type)
return &sec;
return nullptr;
}
ObjectFile::ObjectFile(MemoryMappedFile mb, std::string archive_name)
: InputFile(mb), archive_name(archive_name),
is_in_archive(archive_name != "") {
is_alive = (archive_name == "");
}
static const ElfShdr
*find_section(std::span<ElfShdr> sections, u32 type) {
for (const ElfShdr &sec : sections)
if (sec.sh_type == type)
return &sec;
return nullptr;
}
void ObjectFile::initialize_sections() {
// Read sections
for (int i = 0; i < elf_sections.size(); i++) {
@ -315,7 +314,7 @@ void ObjectFile::initialize_mergeable_sections() {
void ObjectFile::parse() {
sections.resize(elf_sections.size());
symtab_sec = find_section(elf_sections, SHT_SYMTAB);
symtab_sec = find_section(SHT_SYMTAB);
if (symtab_sec) {
first_global = symtab_sec->sh_info;
@ -667,25 +666,21 @@ std::string to_string(const InputFile *file) {
return std::string(obj->archive_name) + ":(" + std::string(obj->name) + ")";
}
std::string_view SharedFile::get_soname(std::span<ElfShdr> elf_sections) {
const ElfShdr *sec = find_section(elf_sections, SHT_DYNAMIC);
if (!sec)
return name;
for (const ElfDyn &dyn : get_data<ElfDyn>(*sec))
if (dyn.d_tag == DT_SONAME)
return std::string_view(symbol_strtab.data() + dyn.d_val);
std::string_view SharedFile::get_soname() {
if (ElfShdr *sec = find_section(SHT_DYNAMIC))
for (ElfDyn &dyn : get_data<ElfDyn>(*sec))
if (dyn.d_tag == DT_SONAME)
return std::string_view(symbol_strtab.data() + dyn.d_val);
return name;
}
void SharedFile::parse() {
symtab_sec = find_section(elf_sections, SHT_DYNSYM);
symtab_sec = find_section(SHT_DYNSYM);
if (!symtab_sec)
return;
symbol_strtab = get_string(symtab_sec->sh_link);
soname = get_soname(elf_sections);
soname = get_soname();
version_strings = read_verdef();
// Read a symbol table.
@ -693,7 +688,7 @@ void SharedFile::parse() {
std::span<ElfSym> esyms = get_data<ElfSym>(*symtab_sec);
std::span<u16> vers;
if (const ElfShdr *sec = find_section(elf_sections, SHT_GNU_VERSYM))
if (ElfShdr *sec = find_section(SHT_GNU_VERSYM))
vers = get_data<u16>(*sec);
std::vector<std::pair<const ElfSym *, u16>> pairs;
@ -735,7 +730,7 @@ void SharedFile::parse() {
}
std::vector<std::string_view> SharedFile::read_verdef() {
const ElfShdr *verdef_sec = find_section(elf_sections, SHT_GNU_VERDEF);
ElfShdr *verdef_sec = find_section(SHT_GNU_VERDEF);
if (!verdef_sec)
return {};