Bug 2256856 - Please build perf with cxa-demangle enabled to support demangling C++ symbols
Summary: Please build perf with cxa-demangle enabled to support demangling C++ symbols
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: kernel
Version: rawhide
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Kernel Maintainer List
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-01-04 21:07 UTC by Michel Lind
Modified: 2024-05-13 22:07 UTC (History)
20 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Michel Lind 2024-01-04 21:07:07 UTC
`kernel-tools` is currently built without `cxa-demangle`.

This *should* just require adding BRs on gcc-c++ and libstdc++-devel, but somehow the way `perf` is built in the spec, this feature never gets detected (add VF=1 to see more features than in the current build log), while if I drop into a mock shell and run `make VF=1 -f Makefile.perf -C tools/perf fixdep` it is picked up. Seems like some of the extra settings passed or the environment variables set made this fail, but I'm not sure which.

`cplus-demangle` is also off - likely for the same reason - despite `HAVE_CPLUS_DEMANGLE=1` being set. Looking at Makefile.config that is not supposed to work anyway, looks like CPLUS_DEMANGLE is only ever configured if DISTRO_BUILD is off.

(Also, some of the other parameters passed like NO_GTK2 seem to not be necessary as well - I was trying to remove as much arguments as possible to see if I can get cxa-demangle to work, and to my surprise removing this and NO_BIONIC has no effect - the feature detection still kept them off).

Reproducible: Always

Steps to Reproduce:
1. Rebuild kernel-tools
2. Search for 'demangle:' in the feature detection
3. Search for util/demangle-cxx.cpp in the log

Actual Results:  
cxa-demangle is OFF. cplus-demangle is also OFF despite HAVE_CPLUS_DEMANGLE being set, which apparently has not worked for a while

Expected Results:  
cxa-demangle should be ON, and demangle-cxx.cpp should be compiled.

Comment 1 Ville Heikkinen 2024-01-24 09:03:08 UTC
The issue seems to be that the building of test-cxa-demangle.cpp fails with

"relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE"

Adding EXTRA_CXXFLAGS="${CXXFLAGS}" to perf make parameters would fix the issue:

diff --git a/kernel-tools.spec b/kernel-tools.spec
index 3fae77e..a30bdeb 100644
--- a/kernel-tools.spec
+++ b/kernel-tools.spec
@@ -251,7 +251,7 @@ cd linux-%{kversion}
 %endif
 
 %global perf_make \
-  make %{?make_opts} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" LDFLAGS="%{__global_ldflags}" %{?cross_opts} -C tools/perf V=1 NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1 NO_BIONIC=1 LIBBPF_DYNAMIC=1 LIBTRACEEVENT_DYNAMIC=1 %{?perf_build_extra_opts} prefix=%{_prefix} PYTHON=%{__python3}
+  make %{?make_opts} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" EXTRA_CXXFLAGS="${CXXFLAGS}" LDFLAGS="%{__global_ldflags}" %{?cross_opts} -C tools/perf V=1 NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1 NO_BIONIC=1 LIBBPF_DYNAMIC=1 LIBTRACEEVENT_DYNAMIC=1 %{?perf_build_extra_opts} prefix=%{_prefix} PYTHON=%{__python3} NO_LIBPERL=1
 # perf
 # make sure check-headers.sh is executable
 chmod +x tools/perf/check-headers.sh

Comment 2 Aoife Moloney 2024-02-15 23:08:57 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 40 development cycle.
Changing version to 40.

Comment 3 Michel Lind 2024-05-13 21:39:22 UTC
Reassigning to the kernel component since kernel-tools is no more.

I tried getting this enabled in kernel-tools, but the build system is so janky - hopefully it's easier now that we're building the tools the way upstream intends (though building as part of the kernel is slow, sigh).

I'll see if I can produce a build that works and then submit a PR

Comment 4 Andrew Gallagher 2024-05-13 22:07:22 UTC
Not sure this is right, but from what I could tell, the build command was using `HAVE_CPLUS_DEMANGLE` but the sources/Makefile referenced `HAVE_CPLUS_DEMANGLE_SUPPORT` -- I wonder if it's as simple as fixing that?

```
kernel-tools.spec:  make %{?make_opts} EXTRA_CFLAGS="${RPM_OPT_FLAGS}" LDFLAGS="%{__global_ldflags}" %{?cross_opts} -C tools/perf V=1 NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1 NO_BIONIC=1 LIBTRACEEVENT_DYNAMIC=1 %{?perf_build_extra_opts} prefix=%{_prefix} PYTHON=%{__python3}
linux-6.4/tools/perf/util/symbol-elf.c:#if defined(HAVE_LIBBFD_SUPPORT) || defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
linux-6.4/tools/perf/util/symbol-elf.c:#elif defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
linux-6.4/tools/perf/Makefile.config:      CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
linux-6.4/tools/perf/Makefile.config:      CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
linux-6.4/tools/perf/util/demangle-cxx.cpp:#if defined(HAVE_LIBBFD_SUPPORT) || defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
linux-6.4/tools/perf/util/demangle-cxx.cpp:#elif defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
```


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