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 08:39:46 +09:00
parent b7d5918bcd
commit 2d419448da
2 changed files with 14 additions and 4 deletions

14
main.cc
View File

@ -665,7 +665,7 @@ static std::vector<u8> create_phdr(ArrayRef<OutputChunk *> chunks) {
}
static std::vector<u8>
create_dynamic_section(ArrayRef<OutputChunk *> chunks) {
create_dynamic_section(ArrayRef<ObjectFile *> files) {
std::vector<u64> vec;
auto define = [&](u64 tag, u64 val) {
@ -673,6 +673,14 @@ create_dynamic_section(ArrayRef<OutputChunk *> chunks) {
vec.push_back(val);
};
int i = 1;
for (ObjectFile *file : files) {
if (!file->soname.empty()) {
define(DT_NEEDED, i);
i += file->soname.size() + 1;
}
}
define(DT_RELA, out::reldyn->shdr.sh_addr);
define(DT_RELASZ, out::reldyn->shdr.sh_size);
define(DT_RELAENT, sizeof(ELF64LE::Rela));
@ -1097,7 +1105,7 @@ int main(int argc, char **argv) {
out::shdr->shdr.sh_size = create_shdr(chunks).size();
out::phdr->shdr.sh_size = create_phdr(chunks).size();
if (out::dynamic)
out::dynamic->shdr.sh_size = create_dynamic_section(chunks).size();
out::dynamic->shdr.sh_size = create_dynamic_section(files).size();
if (out::hash)
out::hash->set_num_dynsym(out::dynsym->shdr.sh_size / sizeof(ELF64LE::Sym));
@ -1182,7 +1190,7 @@ int main(int argc, char **argv) {
if (out::interp)
write_string(buf + out::interp->shdr.sh_offset, config.dynamic_linker);
if (out::dynamic)
write_vector(buf + out::dynamic->shdr.sh_offset, create_dynamic_section(chunks));
write_vector(buf + out::dynamic->shdr.sh_offset, create_dynamic_section(files));
// Zero-clear paddings between sections
clear_padding(buf, chunks, filesize);

View File

@ -11,8 +11,10 @@
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
// RUN: readelf --dynamic %t.exe | FileCheck %s
// CHECK: Dynamic section at offset 0x2068 contains 17 entries:
// CHECK: Dynamic section at offset 0x2068 contains 19 entries:
// CHECK: Tag Type Name/Value
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
// CHECK: 0x0000000000000007 (RELA) 0x2003a0
// CHECK: 0x0000000000000008 (RELASZ) 0 (bytes)
// CHECK: 0x0000000000000009 (RELAENT) 24 (bytes)