From 7f4da62ee9c53126e05c754fdeb65fe32def407f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 1 Mar 2021 12:45:13 +0900 Subject: [PATCH] Fix DT_INIT and DT_FINI --- output_chunks.cc | 8 ++++---- test/dt_init.sh | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 test/dt_init.sh diff --git a/output_chunks.cc b/output_chunks.cc index 2d8f0f69..b29a270a 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -349,10 +349,10 @@ static std::vector create_dynamic_section() { 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); + if (Symbol *sym = Symbol::intern("_init"); sym->file) + define(DT_INIT, sym->get_addr()); + if (Symbol *sym = Symbol::intern("_fini"); sym->file) + define(DT_FINI, sym->get_addr()); i64 flags = 0; i64 flags1 = 0; diff --git a/test/dt_init.sh b/test/dt_init.sh new file mode 100755 index 00000000..059801aa --- /dev/null +++ b/test/dt_init.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e +echo -n "Testing $(basename -s .sh $0) ... " +t=$(pwd)/tmp/$(basename -s .sh $0) +mkdir -p $t + +cat < $t/log + +grep -Pq '\(INIT\)\s+0x201020' $t/log +grep -Pq '\(FINI\)\s+0x201010' $t/log +grep -Pq '0000000000201020\s+0 FUNC GLOBAL HIDDEN \d+ _init$' $t/log +grep -Pq '0000000000201010\s+0 FUNC GLOBAL HIDDEN \d+ _fini$' $t/log + +echo OK