Date: Tue, 28 Jan 2025 23:27:24 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 6ee34bca48a9 - main - crtbegin: accurately check for the end of .dtors Message-ID: <202501282327.50SNRO2r076071@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6ee34bca48a9e0867d46b24a78855e225d46ddda commit 6ee34bca48a9e0867d46b24a78855e225d46ddda Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2025-01-27 19:21:20 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2025-01-28 22:59:20 +0000 crtbegin: accurately check for the end of .dtors not relying only on the end section marker, but also checking for the section size when iterating. Reported by: kargl Analyzed by: dim Reviewed by: andrew, dim Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D48700 --- lib/csu/common/crtbegin.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/csu/common/crtbegin.c b/lib/csu/common/crtbegin.c index d6978859af4a..06fe990052f7 100644 --- a/lib/csu/common/crtbegin.c +++ b/lib/csu/common/crtbegin.c @@ -66,19 +66,27 @@ static crt_func __DTOR_LIST__[] __section(".dtors") __used = { (crt_func)-1 }; +extern const char startof_dtors[] __asm(".startof..dtors") + __weak_symbol __hidden; +extern const char sizeof_dtors[] __asm(".sizeof..dtors") + __weak_symbol __hidden; + static void __do_global_dtors_aux(void) { crt_func fn; + uintptr_t dtors_end; int n; #ifdef SHARED run_cxa_finalize(); #endif + dtors_end = (uintptr_t)&startof_dtors + (uintptr_t)&sizeof_dtors; for (n = 1;; n++) { fn = __DTOR_LIST__[n]; - if (fn == (crt_func)0 || fn == (crt_func)-1) + if (fn == (crt_func)0 || fn == (crt_func)-1 || (dtors_end > 0 && + (uintptr_t)&__DTOR_LIST__[n] >= dtors_end)) break; fn(); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202501282327.50SNRO2r076071>