Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Feb 2025 00:29:47 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 40fb3c401e1d - stable/14 - crtend: accurately check for the start of .ctors
Message-ID:  <202502040029.5140TlTj097437@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=40fb3c401e1d86dbf93c6d97ef1de9f600b76b81

commit 40fb3c401e1d86dbf93c6d97ef1de9f600b76b81
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-01-27 20:38:27 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-02-04 00:28:37 +0000

    crtend: accurately check for the start of .ctors
    
    (cherry picked from commit 21502f9a926c7e0c24ce230bb029fde4bf570a14)
---
 lib/csu/common/crtend.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/csu/common/crtend.c b/lib/csu/common/crtend.c
index d9259729bb0e..bf25c1d836a9 100644
--- a/lib/csu/common/crtend.c
+++ b/lib/csu/common/crtend.c
@@ -21,7 +21,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
+#include <sys/types.h>
 #include "crt.h"
 
 typedef void (*crt_func)(void);
@@ -45,15 +45,22 @@ static crt_func __DTOR_END__[] __section(".dtors") __used = {
 	(crt_func)0
 };
 
+extern const char startof_ctors[] __asm(".startof..ctors")
+    __weak_symbol __hidden;
+
 static void
 __do_global_ctors_aux(void)
 {
 	crt_func fn;
+	uintptr_t ctors_start;
 	int n;
 
+	ctors_start = (uintptr_t)&startof_ctors;
 	for (n = 1;; n++) {
 		fn = __CTOR_END__[-n];
-		if (fn == (crt_func)0 || fn == (crt_func)-1)
+		if (fn == (crt_func)0 || fn == (crt_func)-1 ||
+		    (ctors_start > 0 &&
+		    (uintptr_t)&__CTOR_END__[-n] < ctors_start))
 			break;
 		fn();
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502040029.5140TlTj097437>