From 1438e9b499353b9d72413eaffeefd1884620c073 Mon Sep 17 00:00:00 2001 From: "J.W. Jagersma" Date: Wed, 28 Jun 2023 18:30:29 +0200 Subject: [PATCH 3/3] silence array-bounds warning in gcc 12 --- src/libc/crt0/mcount.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libc/crt0/mcount.c b/src/libc/crt0/mcount.c index a0479b1b..a859c89c 100644 --- a/src/libc/crt0/mcount.c +++ b/src/libc/crt0/mcount.c @@ -52,9 +52,10 @@ static int profiling_p; ** the last used MTABE, so that repeated calls to/from the same ** pair works quickly - no lookup. */ -void mcount(int _to); -void mcount(int _to) +void mcount(int arg); +void mcount(int arg) { + int *arg_ptr = &arg; MTAB *m; int i; unsigned int to; @@ -71,11 +72,14 @@ void mcount(int _to) if (!profiling_p) return; - if (&_to < &etext) + /* Launder arg_ptr to suppress warnings. */ + __asm__ ("" : "+rm" (arg_ptr)); + + if (arg_ptr < &etext) *(int *)(-1) = 0; /* fault! */ - to = *((&_to)-1) - 12; - ebp = *((&_to)-2); /* glean the caller's return address from the stack */ + to = arg_ptr[-1] - 12; + ebp = arg_ptr[-2]; /* glean the caller's return address from the stack */ from = ((int *)ebp)[1]; /* Do nothing if the FROM address is outside the sampling range. */ if (from < h.low || from >= h.high) -- 2.40.1