diff --git a/output_chunks.cc b/output_chunks.cc index 918ed62e..39d2e9fe 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -286,6 +286,19 @@ static std::vector create_dynamic_section() { define(DT_INIT_ARRAYSZ, out::__init_array_end->value - out::__init_array_start->value); define(DT_FINI_ARRAY, out::__fini_array_start->value); define(DT_FINI_ARRAYSZ, out::__fini_array_end->value - out::__fini_array_start->value); + + auto find = [](StringRef name) -> OutputChunk * { + for (OutputChunk *chunk : out::chunks) + if (chunk->name == name) + return chunk; + return nullptr; + }; + + if (OutputChunk *chunk = find(".init")) + define(DT_INIT, chunk->shdr.sh_addr); + if (OutputChunk *chunk = find(".fini")) + define(DT_FINI, chunk->shdr.sh_addr); + define(DT_NULL, 0); return vec; } diff --git a/test/dynamic.s b/test/dynamic.s index 64968127..fef24dd1 100644 --- a/test/dynamic.s +++ b/test/dynamic.s @@ -11,7 +11,7 @@ // RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 // RUN: readelf --dynamic %t.exe | FileCheck %s -// CHECK: Dynamic section at offset 0x2080 contains 20 entries: +// CHECK: Dynamic section at offset 0x2080 contains 22 entries: // CHECK: Tag Type Name/Value // CHECK: 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1] // CHECK: 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] @@ -32,6 +32,8 @@ // CHECK: 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes) // CHECK: 0x000000000000001a (FINI_ARRAY) 0x202020 // CHECK: 0x000000000000001c (FINI_ARRAYSZ) 8 (bytes) +// CHECK: 0x000000000000000c (INIT) 0x201010 +// CHECK: 0x000000000000000d (FINI) 0x201000 // CHECK: 0x0000000000000000 (NULL) 0x0 // RUN: readelf --symbols --use-dynamic %t.exe | FileCheck --check-prefix=DYNAMIC %s diff --git a/test/plt.s b/test/plt.s index 73a05708..0433b267 100644 --- a/test/plt.s +++ b/test/plt.s @@ -15,7 +15,7 @@ // SECTIONS: [19] .got.plt PROGBITS 0000000000202058 00002058 // SECTIONS: 0000000000000028 0000000000000000 WA 0 0 8 // SECTIONS: [20] .dynamic DYNAMIC 0000000000202080 00002080 -// SECTIONS: 0000000000000140 0000000000000010 WA 9 0 8 +// SECTIONS: 0000000000000160 0000000000000010 WA 9 0 8 // RUN: readelf -x .got.plt %t.exe | FileCheck --check-prefix=GOTPLT %s // GOTPLT: 0x00202058 80202000 00000000 00000000 00000000