[PATCH] tools/lib/perf: Fix -Werror=alloc-size-larger-than in cpumap.c
Madhavan Srinivasan
maddy at linux.ibm.com
Mon Apr 14 11:38:33 AEST 2025
On 4/7/25 5:38 PM, Venkat Rao Bagalkote wrote:
>
> On 07/04/25 12:10 am, Athira Rajeev wrote:
>>
>>> On 6 Apr 2025, at 10:04 PM, Likhitha Korrapati <likhitha at linux.ibm.com> wrote:
>>>
>>> perf build break observed when using gcc 13-3 (FC39 ppc64le)
>>> with the following error.
>>>
>>> cpumap.c: In function 'perf_cpu_map__merge':
>>> cpumap.c:414:20: error: argument 1 range [18446744069414584320, 18446744073709551614] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
>>> 414 | tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu));
>>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> In file included from cpumap.c:4:
>>> /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__
>>> | ^~~~~~
>>> cc1: all warnings being treated as errors
>>>
>>> Error happens to be only in gcc13-3 and not in latest gcc 14.
>>> Even though git-bisect pointed bad commit as:
>>> 'commit f5b07010c13c ("libperf: Don't remove -g when EXTRA_CFLAGS are used")',
>>> issue is with tmp_len being "int". It holds number of cpus and making
>>> it "unsigned int" fixes the issues.
>>>
>>> After the fix:
>>>
>>> CC util/pmu-flex.o
>>> CC util/expr-flex.o
>>> LD util/perf-util-in.o
>>> LD perf-util-in.o
>>> AR libperf-util.a
>>> LINK perf
>>> GEN python/perf.cpython-312-powerpc64le-linux-gnu.so
>>>
>>> Signed-off-by: Likhitha Korrapati <likhitha at linux.ibm.com>
>> Looks good to me
>>
>> Reviewed-by: Athira Rajeev <atrajeev at linux.ibm.com>
>
> Tested this patch on perf-tools-next repo, and this patch fixes the issue.
>
> Tested-by: Venkat Rao Bagalkote <venkat88 at linux.ibm.com>
>
>
Arnaldo, Namhyung,
can you consider pulling this fix? since it is breaking the build in gcc13-3 or
if you have any comments do let us know.
Thanks
Maddy
> Regards,
>
> Venkat.
>
>>
>> Thanks
>> Athira
>>> ---
>>> tools/lib/perf/cpumap.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
>>> index 4454a5987570..c7c784e18225 100644
>>> --- a/tools/lib/perf/cpumap.c
>>> +++ b/tools/lib/perf/cpumap.c
>>> @@ -398,7 +398,7 @@ bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu
>>> int perf_cpu_map__merge(struct perf_cpu_map **orig, struct perf_cpu_map *other)
>>> {
>>> struct perf_cpu *tmp_cpus;
>>> - int tmp_len;
>>> + unsigned int tmp_len;
>>> int i, j, k;
>>> struct perf_cpu_map *merged;
>>>
>>> --
>>> 2.43.5
>>>
>>
More information about the Linuxppc-dev
mailing list