Re: [REGRESSION] perf build failed after 5cf6e76e4f4f ("libperf: Don't remove -g when EXTRA_CFLAGS are used") on riscv64 with gcc 13

Yan, Haixiao (CN)
2026-03-20T03:30:52Z

On 3/19/2026 4:21 PM, Ian Rogers wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> On Wed, Mar 18, 2026 at 6:57 PM Haixiao Yan
> <haixiao.yan.cn@windriver.com> wrote:
>> Hi,
>>
>> Commit[5cf6e76e4f4f](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/tools/lib/perf/Makefile?h=linux-6.6.y&id=5cf6e76e4f4fee54c0056758b639cf4919cffba9)
>> changed the libperf Makefile to preserve external CFLAGS instead of overriding them. As a result, the -O6 optimization flags from perf's
>> build system are now inherited by libperf during compilation. This triggers a false positive -Walloc-size-larger-than= warning in GCC 13 on
>> riscv64, causing the build to fail with -Werror.
>>
>> | cpumap.c: In function 'perf_cpu_map__merge':
>> | cpumap.c:422:20: error: argument 1 range [18446744065119617024, 18446744073709551612] exceeds maximum objec
>> t size 9223372036854775807 [-Werror=alloc-size-larger-than=]
>> | 422 | tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu));
>> | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> | In file included from cpumap.c:3:
>> | /buildarea5/hyan-cn/project_yocto/poky/build-riscv64/tmp/work/qemuriscv64-poky-linux/perf/1.0/recipe-sysroo
>> t/usr/include/stdlib.h:672:14: note: in a call to allocation function 'malloc' declared here
>> | 672 | extern void *malloc (size_t __size) __THROW __attribute_malloc__
>> | | ^~~~~~
>> | rm -f /buildarea5/hyan-cn/project_yocto/poky/build-riscv64/tmp/work/qemuriscv64-poky-linux/perf/1.0/perf-1.
>> 0/libapi/libapi.a && riscv64-poky-linux-gcc-ar rcs /buildarea5/hyan-cn/project_yocto/poky/build-riscv64/tmp/w
>> ork/qemuriscv64-poky-linux/perf/1.0/perf-1.0/libapi/libapi.a /buildarea5/hyan-cn/project_yocto/poky/build-ris
>> cv64/tmp/work/qemuriscv64-poky-linux/perf/1.0/perf-1.0/libapi/libapi-in.o
>> | cc1: all warnings being treated as errors
> Hi Haixiao,
>
> this was raised before by Chingbin in:
> https://lore.kernel.org/lkml/20260212025127.841090-1-liqb365@163.com/
> I was concerned about the introduction of volatile to avoid this
> warning. I've mailed out what is hopefully a fix without volatile in
> it:
> https://lore.kernel.org/lkml/20260319081843.1650640-1-irogers@google.com/
> If you could take a look.

Hi Ian,

I have verified this patch on the master branch using gcc 13.4.0 for
both riscv64 and ppc64 targets, and
can confirm the issue is resolved.

It would be greatly appreciated if this could be backported to the
linux-6.6.y stable branch.

Thanks,

Haixiao

>
> Thanks,
> Ian
>
>> Steps to reproduce:
>>
>> git clone -b scarthgap https://git.yoctoproject.org/poky
>> cd poky
>> sed -i 's/af240d7d57ebf66e87bc2dff34855e630a97ead1/5cf6e76e4f4fee54c0056758b639cf4919cffba9/' meta/recipes-kernel/linux/linux-yocto_6.6.bb
>>
>> source oe-init-build-env build-riscv64
>>
>> cat >> conf/local.conf << 'EOF'
>> MACHINE = "qemuriscv64"
>> 'KERNEL_VERSION_SANITY_SKIP = "1"'
>> EOF
>>
>> bitbake perf
>>
>> I have confirmed that:
>> Known to fail: gcc 13.3.0, 13.4.0
>> Known to work: gcc 11.5.0, 12.5.0, 14.3.0, 15.2.0
>>
>> Not sure whether this is a gcc bug.
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124549 filed to gcc.
>>
>> Thanks,
>> Haixiao
>>
>>