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-11-13 00:02:33 +09:00
parent f9ee54c209
commit 6e7a23d317
4 changed files with 38 additions and 17 deletions

17
main.cc
View File

@ -478,6 +478,16 @@ static void write_shstrtab(u8 *buf, ArrayRef<OutputChunk *> chunks) {
}
}
static void write_dso_paths(u8 *buf, ArrayRef<ObjectFile *> files) {
int offset = out::dynstr->shdr.sh_offset + 1;
for (ObjectFile *file : files) {
if (!file->soname.empty()) {
write_string(buf + offset, file->soname);
offset += file->soname.size() + 1;
}
}
}
static void write_merged_strings(u8 *buf, ArrayRef<ObjectFile *> files) {
MyTimer t("write_merged_strings", copy_timer);
@ -1073,11 +1083,9 @@ int main(int argc, char **argv) {
}
// Reserve space in .dynsym for DT_NEEDED strings.
#if 0
for (ObjectFile *file : files)
if (file->is_alive && file->is_dso)
out::dynsym->shdr.sh_size += file->
#endif
out::dynstr->shdr.sh_size += file->soname.size() + 1;
// Set section indices.
for (int i = 0, shndx = 1; i < chunks.size(); i++)
@ -1157,6 +1165,9 @@ int main(int argc, char **argv) {
// Fill .shstrtab
write_shstrtab(buf, chunks);
// Write DT_NEEDED paths to .dynstr.
write_dso_paths(buf, files);
// Fill .plt, .got, got.plt, .rela.plt sections
write_got(buf, files);

1
mold.h
View File

@ -588,6 +588,7 @@ public:
std::vector<MergeableSection> mergeable_sections;
private:
void initialize_soname();
void initialize_sections();
void initialize_symbols();
std::vector<StringPieceRef> read_string_pieces(InputSection *isec);

View File

@ -21,6 +21,23 @@ static const ELF64LE::Shdr
return nullptr;
}
void ObjectFile::initialize_soname() {
for (const ELF64LE::Shdr &shdr : elf_sections) {
if (shdr.sh_type != SHT_DYNAMIC)
continue;
ArrayRef<ELF64LE::Dyn> tags =
CHECK(obj.template getSectionContentsAsArray<ELF64LE::Dyn>(shdr), this);
for (const ELF64LE::Dyn &dyn : tags) {
if (dyn.d_tag == DT_NEEDED) {
this->soname = StringRef(symbol_strtab.data() + dyn.d_un.d_val);
return;
}
}
}
}
void ObjectFile::initialize_sections() {
StringRef section_strtab = CHECK(obj.getSectionStringTable(elf_sections), this);
@ -60,17 +77,6 @@ void ObjectFile::initialize_sections() {
case SHT_SYMTAB_SHNDX:
error(toString(this) + ": SHT_SYMTAB_SHNDX section is not supported");
break;
case SHT_DYNAMIC: {
ArrayRef<ELF64LE::Dyn> tags =
CHECK(obj.template getSectionContentsAsArray<ELF64LE::Dyn>(shdr), this);
for (const ELF64LE::Dyn &dyn : tags) {
if (dyn.d_tag == DT_NEEDED) {
soname = StringRef(symbol_strtab.data() + dyn.d_un.d_val);
break;
}
}
break;
}
case SHT_SYMTAB:
case SHT_STRTAB:
case SHT_REL:
@ -277,7 +283,10 @@ void ObjectFile::parse() {
}
sections.resize(elf_sections.size());
if (!is_dso)
if (is_dso)
initialize_soname();
else
initialize_sections();
if (symtab_sec)

View File

@ -23,8 +23,8 @@
// CHECK: 0x0000000000000006 (SYMTAB) 0x2003a0
// CHECK: 0x000000000000000b (SYMENT) 24 (bytes)
// CHECK: 0x0000000000000005 (STRTAB) 0x2003e8
// CHECK: 0x000000000000000a (STRSZ) 26 (bytes)
// CHECK: 0x0000000000000004 (HASH) 0x200404
// CHECK: 0x000000000000000a (STRSZ) 58 (bytes)
// CHECK: 0x0000000000000004 (HASH) 0x200424
// CHECK: 0x0000000000000019 (INIT_ARRAY) 0x202028
// CHECK: 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
// CHECK: 0x000000000000001a (FINI_ARRAY) 0x202020