Bug 217706 - [perf] Build error when using LTO on 6.4
Summary: [perf] Build error when using LTO on 6.4
Status: NEW
Alias: None
Product: Tools
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P3 normal
Assignee: Tools.Other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-25 18:44 UTC by Marcus Seyfarth
Modified: 2023-07-27 10:44 UTC (History)
0 users

See Also:
Kernel Version:
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Marcus Seyfarth 2023-07-25 18:44:18 UTC
Starting with Kernel 6.4, I see a build error when using "-flto" to build perf. This used to work fine with earlier Kernels when using either bfd or mold as linker when using GCC 13.1.1.

This is the PKGBUILD I use as my build recipe: https://github.com/ms178/archpkgbuilds/blob/main/packages/bpf/PKGBUILD

This is the konsole output I get now with Kernel 6.4.5:

[CODE]
CFLAGS='-Wno-error=bad-function-cast -Wno-error=declaration-after-statement -Wno-error=switch-enum -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wno-type-limits -Wstrict-aliasing=3 -Wshadow -DHAVE_SYSCALL_TABLE_SUPPORT -DHAVE_ARCH_X86_64_SUPPORT -Iarch/x86/include/generated -DHAVE_PERF_REGS_SUPPORT -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET -Werror -DNDEBUG=1 -O6 -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu11 -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/tmp/makepkg/linux-tools/src/linux/tools/perf/util/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/arch/x86/include -I/tmp/makepkg/linux-tools/src/linux/tools/include/ -I/tmp/makepkg/linux-tools/src/linux/tools/arch/x86/include/uapi -I/tmp/makepkg/linux-tools/src/linux/tools/include/uapi -I/tmp/makepkg/linux-tools/src/linux/tools/arch/x86/include/ -I/tmp/makepkg/linux-tools/src/linux/tools/arch/x86/ -I/tmp/makepkg/linux-tools/src/linux/tools/perf/util -I/tmp/makepkg/linux-tools/src/linux/tools/perf -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP -DHAVE_PTHREAD_BARRIER -DHAVE_EVENTFD_SUPPORT -DHAVE_GET_CURRENT_DIR_NAME -DHAVE_GETTID -DHAVE_FILE_HANDLE -DHAVE_DWARF_GETLOCATIONS_SUPPORT -DHAVE_AIO_SUPPORT -DHAVE_SCANDIRAT_SUPPORT -DHAVE_SCHED_GETCPU_SUPPORT -DHAVE_SETNS_SUPPORT -DHAVE_LIBELF_SUPPORT -DHAVE_ELF_GETPHDRNUM_SUPPORT -DHAVE_GELF_GETNOTE_SUPPORT -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT -DHAVE_DEBUGINFOD_SUPPORT -DHAVE_DWARF_SUPPORT  -DHAVE_LIBBPF_SUPPORT -DHAVE_BPF_PROLOGUE -DHAVE_JITDUMP -DHAVE_DWARF_UNWIND_SUPPORT -DNO_LIBUNWIND_DEBUG_FRAME -DHAVE_LIBUNWIND_SUPPORT -DHAVE_LIBCRYPTO_SUPPORT -DHAVE_SLANG_SUPPORT -DNO_LIBPERL -DHAVE_TIMERFD_SUPPORT -DHAVE_LIBPYTHON_SUPPORT -DHAVE_CXA_DEMANGLE_SUPPORT -DHAVE_ZLIB_SUPPORT -DHAVE_LZMA_SUPPORT -DHAVE_ZSTD_SUPPORT -DHAVE_LIBCAP_SUPPORT -DHAVE_BACKTRACE_SUPPORT -DHAVE_LIBNUMA_SUPPORT -DHAVE_KVM_STAT_SUPPORT -DDISASM_FOUR_ARGS_SIGNATURE -DDISASM_INIT_STYLED -DHAVE_PERF_READ_VDSO32 -DHAVE_AUXTRACE_SUPPORT -DHAVE_LIBTRACEEVENT -DLIBTRACEEVENT_VERSION=66813 -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libapi/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libsubcmd/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libsymbol/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libperf/include' LDFLAGS='-Wl,-O3,--as-needed,-Bsymbolic-functions,--sort-common,-flto=auto -fopenmp -fuse-ld=mold -march=native -mtune=native -maes -mbmi2 -mpclmul -Wl,-zmax-page-size=0x200000 -Wl,-z,noexecstack  -lunwind-x86_64 -lunwind -llzma  -L/usr/lib ' \
  '/usr/bin/python' util/setup.py \
  --quiet build_ext; \
cp python_ext_build/lib/perf*.so python/
rm -f -f /tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/libbpf.a; ar rcs /tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/libbpf.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/staticobjs/libbpf-in.o
[snip]
gcc -Wno-error=bad-function-cast -Wno-error=declaration-after-statement -Wno-error=switch-enum -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wno-type-limits -Wstrict-aliasing=3 -Wshadow -DHAVE_SYSCALL_TABLE_SUPPORT -DHAVE_ARCH_X86_64_SUPPORT -Iarch/x86/include/generated -DHAVE_PERF_REGS_SUPPORT -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET -Werror -DNDEBUG=1 -O6 -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu11 -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/tmp/makepkg/linux-tools/src/linux/tools/perf/util/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/arch/x86/include -I/tmp/makepkg/linux-tools/src/linux/tools/include/ -I/tmp/makepkg/linux-tools/src/linux/tools/arch/x86/include/uapi -I/tmp/makepkg/linux-tools/src/linux/tools/include/uapi -I/tmp/makepkg/linux-tools/src/linux/tools/arch/x86/include/ -I/tmp/makepkg/linux-tools/src/linux/tools/arch/x86/ -I/tmp/makepkg/linux-tools/src/linux/tools/perf/util -I/tmp/makepkg/linux-tools/src/linux/tools/perf -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP -DHAVE_PTHREAD_BARRIER -DHAVE_EVENTFD_SUPPORT -DHAVE_GET_CURRENT_DIR_NAME -DHAVE_GETTID -DHAVE_FILE_HANDLE -DHAVE_DWARF_GETLOCATIONS_SUPPORT -DHAVE_AIO_SUPPORT -DHAVE_SCANDIRAT_SUPPORT -DHAVE_SCHED_GETCPU_SUPPORT -DHAVE_SETNS_SUPPORT -DHAVE_LIBELF_SUPPORT -DHAVE_ELF_GETPHDRNUM_SUPPORT -DHAVE_GELF_GETNOTE_SUPPORT -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT -DHAVE_DEBUGINFOD_SUPPORT -DHAVE_DWARF_SUPPORT  -DHAVE_LIBBPF_SUPPORT -DHAVE_BPF_PROLOGUE -DHAVE_JITDUMP -DHAVE_DWARF_UNWIND_SUPPORT -DNO_LIBUNWIND_DEBUG_FRAME -DHAVE_LIBUNWIND_SUPPORT -DHAVE_LIBCRYPTO_SUPPORT -DHAVE_SLANG_SUPPORT -DNO_LIBPERL -DHAVE_TIMERFD_SUPPORT -DHAVE_LIBPYTHON_SUPPORT -DHAVE_CXA_DEMANGLE_SUPPORT -DHAVE_ZLIB_SUPPORT -DHAVE_LZMA_SUPPORT -DHAVE_ZSTD_SUPPORT -DHAVE_LIBCAP_SUPPORT -DHAVE_BACKTRACE_SUPPORT -DHAVE_LIBNUMA_SUPPORT -DHAVE_KVM_STAT_SUPPORT -DDISASM_FOUR_ARGS_SIGNATURE -DDISASM_INIT_STYLED -DHAVE_PERF_READ_VDSO32 -DHAVE_AUXTRACE_SUPPORT -DHAVE_LIBTRACEEVENT -DLIBTRACEEVENT_VERSION=66813 -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libapi/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libsubcmd/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libsymbol/include -I/tmp/makepkg/linux-tools/src/linux/tools/perf/libperf/include -Wl,-O3,--as-needed,-Bsymbolic-functions,--sort-common,-flto=auto -fopenmp -fuse-ld=mold -march=native -mtune=native -maes -mbmi2 -mpclmul -Wl,-zmax-page-size=0x200000 -Wl,-z,noexecstack  -lunwind-x86_64 -lunwind -llzma  -L/usr/lib  \
        perf-in.o pmu-events/pmu-events-in.o -Wl,--whole-archive /tmp/makepkg/linux-tools/src/linux/tools/perf/libapi/libapi.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libperf/libperf.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libsubcmd/libsubcmd.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libsymbol/libsymbol.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/libbpf.a  -Wl,--no-whole-archive -Wl,--start-group -lpthread -lrt -lm -ldl -lelf -ldebuginfod -ldw -lunwind-x86_64 -lunwind -llzma -lcrypto -lslang -lpython3.11 -ldl -lm -lutil -lstdc++ -lz -llzma -lzstd -lcap -lnuma -ltraceevent -Wl,--end-group -o perf
mold: error: undefined symbol: main
>>> referenced by /usr/lib/Scrt1.o:(.text)
>>>               /usr/lib/Scrt1.o:(_start)
mold: error: undefined symbol: perf_pmu__getcpuid
>>> referenced by pmu-events.c
>>>               pmu-events/pmu-events-in.o:(perf_pmu__find_events_table)>>>
>>>               referenced by pmu-events.c
>>>               pmu-events/pmu-events-in.o:(perf_pmu__find_metrics_table)
mold: error: undefined symbol: strcmp_cpuid_str
>>> referenced by pmu-events.c
>>>               pmu-events/pmu-events-in.o:(perf_pmu__find_events_table)>>>
>>>               referenced by pmu-events.c
>>>               pmu-events/pmu-events-in.o:(perf_pmu__find_metrics_table)>>>
>>>               referenced by pmu-events.c
>>>               pmu-events/pmu-events-in.o:(find_core_events_table)>>>
>>>               referenced 1 more times

mold: error: undefined symbol: _ctype
>>> referenced by kallsyms.c
>>>              
>>>               /tmp/makepkg/linux-tools/src/linux/tools/perf/libsymbol/libsymbol.a(libsymbol-in.o):(__tolower)>>>
>>>               referenced by kallsyms.c
>>>              
>>>               /tmp/makepkg/linux-tools/src/linux/tools/perf/libsymbol/libsymbol.a(libsymbol-in.o):(__toupper)
mold: error: undefined symbol: strlcpy
>>> referenced by exec-cmd.c
>>>              
>>>               /tmp/makepkg/linux-tools/src/linux/tools/perf/libsubcmd/libsubcmd.a(libsubcmd-in.o):(get_pwd_cwd)
[/CODE]

I have noticed a patch series of Ian Rodgers that might adress this issue, but his reported errors were different to mine, see: https://www.spinics.net/lists/kernel/msg4872566.html

Compiler: gcc-version 13.1.1 20230714 (GCC)
Comment 1 Marcus Seyfarth 2023-07-27 10:35:48 UTC
When patching in Ian's LTO patches and setting LTO=1 for perf, I now see these warnings that are treated as errors:

perf-in.o pmu-events/pmu-events-in.o -Wl,--whole-archive /tmp/makepkg/linux-tools/src/linux/tools/perf/libapi/libapi.a /tmp/makepkg /linux-tools/src/linux/tools/perf/libperf/libperf.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libsubcmd/libsubcmd.a /tmp/makepkg/linux-tools/src /linux/tools/perf/libsymbol/libsymbol.a /tmp/makepkg/linux-tools/src/linux/tools/perf/libbpf/libbpf.a -Wl,--no-whole-archive -Wl,--start -group -lpthread -lrt -lm -ldl -lelf -ldebuginfod -ldw -lunwind-x86_64 -lunwind -llzma -lcrypto -lslang -lpython3.11 -ldl -lm -lutil -lstdc++ -lz -llzma -lzstd -lcap -lnuma -ltraceevent -Wl,--end-group -o perf
util/parse-events.c: In function "parse_events_add_pmu":
util/parse-events.c:1571:23: error: 'info.unit' could be used uninitialized [-Werror=maybe-uninitialized]
  1571 | evsel->unit = strdup(info.unit);
       | ^
util/parse-events.c:1458:30: Note: "info.unit" was declared here
  1458 | struct perf_pmu_info info;
       | ^
util/parse-events.c:1572:22: error: 'info.scale' could be used uninitialized [-Werror=maybe-uninitialized]
  1572 | evsel->scale = info.scale;
       | ^
util/parse-events.c:1458:30: Note: "info.scale" was declared here
  1458 | struct perf_pmu_info info;
       | ^
util/parse-events.c:1573:30: error: "MEM <unsigned char> [(struct perf_pmu_info *)&info + 16B]" could be used uninitialized [-Werror=maybe-uninitialized]
  1573 | evsel->per_pkg = info.per_pkg;
       | ^
util/parse-events.c:1458:30: Note: "MEM <unsigned char> [(struct perf_pmu_info *)&info + 16B]" was declared here
  1458 | struct perf_pmu_info info;
       | ^
util/parse-events.c:1574:31: error: "MEM <unsigned char> [(struct perf_pmu_info *)&info + 17B]" could be used uninitialized [-Werror=maybe-uninitialized]
  1574 | evsel->snapshot = info.snapshot;
       | ^
util/parse-events.c:1458:30: Note: "MEM <unsigned char> [(struct perf_pmu_info *)&info + 17B]" was declared here
  1458 | struct perf_pmu_info info;
       | ^
lto1: All warnings are treated as errors
make[2]: *** [/tmp/ccqCyWfp.mk:65: /tmp/ccpuVfDq.ltrans21.ltrans.o] Error 1
Comment 2 Marcus Seyfarth 2023-07-27 10:44:04 UTC
And if I set -Wno-error=maybe-uninitialized the build errors out soon after with:

mold: error: undefined symbol: perf_regs_load
>>> referenced by <artificial>
>>>               /tmp/ccZ9Po2M.ltrans18.ltrans.o:(test_dwarf_unwind__thread)
mold: error: undefined symbol: memcpy_orig
>>> referenced by <artificial>
>>>               /tmp/ccZ9Po2M.ltrans12.ltrans.o
mold: error: undefined symbol: __memset
>>> referenced by <artificial>
>>>               /tmp/ccZ9Po2M.ltrans12.ltrans.o
mold: error: undefined symbol: __memcpy
>>> referenced by <artificial>
>>>               /tmp/ccZ9Po2M.ltrans12.ltrans.o
mold: error: undefined symbol: memset_orig
>>> referenced by <artificial>
>>>               /tmp/ccZ9Po2M.ltrans12.ltrans.o

This is on Kernel 6.4.6 by the way.

Note You need to log in before you can comment on or make changes to this bug.