From nobody Tue Jan 28 23:27:25 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YjLzd6StJz5mL43; Tue, 28 Jan 2025 23:27:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YjLzd27Kzz3Rk1; Tue, 28 Jan 2025 23:27:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738106845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BT4vGwxfaPDT2M/UaBzKFGW15RySwfUwAH6i0hsHJOU=; b=Sk5fZGYDXEOctoMt3b/9pk6Hwq6iLM/299FCqqWp+rQz9UtL81Nzr3ZWMRA+s4k4M1fTf/ T4DeRPZHy+6m21uTqdIHahAAZPryhUGBbYqW3ZPnz9yi2SIeLPVcXUhZttHHwj7Dbg9CFk jLSKRs4vFnpTa2X6GcHwpo6z1TmBR+cwdEOxznhImOVwdVfmznNloeakoynFNUO9v8L53K gNn5D8LS5TWuZMagKV9PBzR7Q9MOZ6pKTdmZvqVo47cTqoGao2G2GNRWWMjXi79np7sWTv tCPwwz9c61J6bQafG8DlDkd62wlp09btAF6XaGAFdTvvxJ/B0uR8PLe1RuIXzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738106845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BT4vGwxfaPDT2M/UaBzKFGW15RySwfUwAH6i0hsHJOU=; b=rZv5/9wuZCxfCHScEEGNRb+Sjq10072zN/VhkIgdTpM61PHx1bc/u0b55HMF5YbLx4J8hC lod9eq9nAxm7L7SxWv02vV3JXUwfMJldTlIyzE30WT3zUPiRjGuoy0q3VdZ4Eb9Dshi5o2 r4GMxFQwYP46jaaIGlF/hyUS/uaK7BGVtvOLBjktXi+wTBg2s3hkJFsM8RECX3WcIG04I1 uqdhsH2T9+pAVrElHWVL7DsKo+wkN6IFftNSaeBPVAkdo2WRM6xQC6TmC3HGrpAH9kXGhb LioGiNlKiabO+m8XeAV80usktXIsbU/3mRABeFhW7eKrc4LafTiX/zlYrUmSSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738106845; a=rsa-sha256; cv=none; b=aqMJnee+/yibH3qGoQqBx1TKK5lR0pkN1sjIAyX4twJQ0IIZoteN/jTvG/IY4mLjSpMFr2 k0aGAf3BnOQwjsrThzHKyQKYZ9z+OVHKGoV1q+cN4xdFpdA6dneWWYnTn4MRHIh2WzUL4P QA83V3LTBKa8WVWrH+GLsgF6tBmgxjvlIcncWzo0jHgLIk7UPQjj4GdjK14cbdcOiag5KW 82PEGUQAB6ywWrZo64ST5uqYDe+yFV9eytjb4RCMo78X/fgG8yHNq3Qp6/6cztIf6CfKpE kBYt7U2xlMUWXKOTjhrMRlN33hFRSnXrr822M/xk+ttZUi2Q6Nrj25n5CWNajg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YjLzd1WXKzcXs; Tue, 28 Jan 2025 23:27:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50SNRP1X076107; Tue, 28 Jan 2025 23:27:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50SNRPBw076104; Tue, 28 Jan 2025 23:27:25 GMT (envelope-from git) Date: Tue, 28 Jan 2025 23:27:25 GMT Message-Id: <202501282327.50SNRPBw076104@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 21502f9a926c - main - crtend: accurately check for the start of .ctors List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 21502f9a926c7e0c24ce230bb029fde4bf570a14 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=21502f9a926c7e0c24ce230bb029fde4bf570a14 commit 21502f9a926c7e0c24ce230bb029fde4bf570a14 Author: Konstantin Belousov AuthorDate: 2025-01-27 20:38:27 +0000 Commit: Konstantin Belousov CommitDate: 2025-01-28 22:59:20 +0000 crtend: accurately check for the start of .ctors For the hypothetic situation where crtbegin.o is not linked into the binary, but crtend.o is, which results in the missing starting sentinel in the ctors array, be careful to not iterate past the start of the section. Reviewed by: andrew, dim Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D48700 --- 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 +#include #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(); }