wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
10.23k stars 689 forks source link

Profiler build failure on Debian Buster with CMake #913

Open de-passage opened 1 month ago

de-passage commented 1 month ago

On the master branch, building the profiler alone with CMake fails on Debian Buster with X11 for ~2~ 1 reasons:

  1. ~Wayland is incorrectly selected despite LEGACY=ON being given in the CMake configuration. This leads to searching for wayland-scanner which is apparently not available on Debian Buster.~
  2. The final link step is missing -ldl, leading to undefined reference to symbol 'dlclose@@GLIBC_2.2.5'

~I fixed problem 1 by adding the following to profiler/CMakeLists.txt and reconfiguring:~ (PEBKAC)

if (LEGACY)
    set(USE_WAYLAND OFF)
else()
    set(USE_WAYLAND ON)
endif()

I went around 2. by running the link command manually adding -ldl to it. I guess there's a target_link_libraries(... dl) missing somewhere.

The resulting binary appears to be working.

Commands reproducing the problem:

$ cmake -B build-profiler -DCMAKE_BUILD_TYPE=Release -G Ninja -DCMAKE_CXX_FLAGS="-Wl,-rpath,/opt/gcc-14.2/lib64" -DLEGACY=ON -S profiler # Error 1.
$ cmake --build build-profiler # Error 2

System:

$ uname -a 
Linux FRIDF-L00174 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

Compiler:

$ c++ --version
c++ (GCC) 15.0.0 20241001 (experimental)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Toolchain:

$ cmake --version
cmake version 3.30.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).

$ ninja --version
1.8.2
wolfpld commented 1 month ago

I fixed problem 1 by adding the following to profiler/CMakeLists.txt and reconfiguring:

There's an equivalent condition already in cmake/config.cmake, which is included at the top of profiler's CMakeLists.txt. Can you step through the CMake configuration (for example with the "Configure with CMake Debugger" command in VS Code) to see what's the problem here?

wolfpld commented 1 month ago

The second problem is an interesting one to figure out.

[11:22 wolf@mimir:~/tracy/profiler/build]% objdump -t tracy-profiler|grep dlclose
00000000015a6030 l     F .plt   0000000000000000              dlclose$plt
0000000000000000       F *UND*  0000000000000000              dlclose
[11:22 wolf@mimir:~/tracy/profiler/build]% libtree tracy-profiler                
tracy-profiler 
├── libEGL.so.1 [default path]
│   └── libGLdispatch.so.0 [default path]
├── libdbus-1.so.3 [default path]
│   └── libsystemd.so.0 [default path]
│       └── libcap.so.2 [default path]
├── libfreetype.so.6 [default path]
│   ├── libz.so.1 [default path]
│   ├── libbrotlidec.so.1 [default path]
│   │   └── libbrotlicommon.so.1 [default path]
│   ├── libharfbuzz.so.0 [default path]
│   │   ├── libgraphite2.so.3 [default path]
│   │   ├── libglib-2.0.so.0 [default path]
│   │   │   └── libpcre2-8.so.0 [default path]
│   │   └── libfreetype.so.6 [default path]
│   ├── libpng16.so.16 [default path]
│   │   └── libz.so.1 [default path]
│   └── libbz2.so.1.0 [default path]
├── libxkbcommon.so.0 [default path]
├── libwayland-cursor.so.0 [default path]
│   └── libwayland-client.so.0 [default path]
│       └── libffi.so.8 [default path]
├── libwayland-client.so.0 [default path]
└── libwayland-egl.so.1 [default path]
de-passage commented 1 month ago

I tried starting from scratches and error 1 went away. I guess LEGACY=OFF got cached and never reset correctly. Sorry about that. I have reproduced error 2 however. I don't have much more information unfortunately.

Here's the full error message:

$ cmake --build build-profiler
[0/2] Re-checking globbed directories...
[153/153] Linking CXX executable tracy-profiler
FAILED: tracy-profiler
: && /usr/bin/c++ -Wl,-rpath,/opt/gcc-14.2/lib64 -O3 -DNDEBUG -flto=auto -fno-fat-lto-objects  CMakeFiles/tracy-profiler.dir/src/ConnectionHistory.cpp.o CMakeFiles/tracy-profiler.dir/src/Filters.cpp.o CMakeFiles/tracy-profiler.dir/src/Fonts.cpp.o CMakeFiles/tracy-profiler.dir/src/HttpRequest.cpp.o CMakeFiles/tracy-profiler.dir/src/ImGuiContext.cpp.o CMakeFiles/tracy-profiler.dir/src/ini.c.o CMakeFiles/tracy-profiler.dir/src/IsElevated.cpp.o CMakeFiles/tracy-profiler.dir/src/main.cpp.o CMakeFiles/tracy-profiler.dir/src/ResolvService.cpp.o CMakeFiles/tracy-profiler.dir/src/RunQueue.cpp.o CMakeFiles/tracy-profiler.dir/src/WindowPosition.cpp.o CMakeFiles/tracy-profiler.dir/src/winmain.cpp.o CMakeFiles/tracy-profiler.dir/src/winmainArchDiscovery.cpp.o CMakeFiles/tracy-profiler.dir/src/BackendGlfw.cpp.o CMakeFiles/tracy-profiler.dir/.cpm-cache/imgui/a7d9dcff67fb46707b5b248c3301f5b17dd9dfe9/backends/imgui_impl_glfw.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyAchievementData.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyAchievements.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyBadVersion.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyColor.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyEventDebug.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyFileselector.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyFilesystem.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyImGui.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyMicroArchitecture.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyMouse.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyProtoHistory.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracySourceContents.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracySourceTokenizer.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracySourceView.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyStorage.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTexture.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTimelineController.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTimelineItem.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTimelineItemCpuData.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTimelineItemGpu.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTimelineItemPlot.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyTimelineItemThread.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyUserData.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyUtility.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Annotations.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Callstack.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Compare.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_ConnectionState.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_ContextSwitch.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_CpuData.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_FindZone.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_FlameGraph.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_FrameOverview.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_FrameTimeline.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_FrameTree.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_GpuTimeline.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Locks.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Memory.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Messages.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Navigation.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_NotificationArea.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Options.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Playback.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Plots.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Ranges.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Samples.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Statistics.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Timeline.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_TraceInfo.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_Utility.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_ZoneInfo.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyView_ZoneTimeline.cpp.o CMakeFiles/tracy-profiler.dir/src/profiler/TracyWeb.cpp.o -o tracy-profiler  libTracyServer.a  libTracyImGui.a  libTracyNfd.a  _deps/capstone-build/libcapstone.a  libTracyZstd.a  -lpthread  /usr/lib/x86_64-linux-gnu/libfreetype.so  /usr/lib/x86_64-linux-gnu/libdbus-1.so  /usr/lib/x86_64-linux-gnu/libglfw.so && :
/home/sii/workspace/tracy/profiler/src/stb_image.h: In function ‘stbi__parse_png_file.constprop’:
/home/sii/workspace/tracy/profiler/src/stb_image.h:5164:56: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 5164 |                   for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
      |                                                        ^
/home/sii/workspace/tracy/profiler/src/stb_image.h:5080:25: note: at offset 3 into destination object ‘tc’ of size 3
 5080 |    stbi_uc has_trans=0, tc[3]={0};
      |                         ^
/usr/bin/ld: /tmp/cc4qu2td.ltrans54.ltrans.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO manquant dans la ligne de commande
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

ld version:

$ ld --version
GNU ld (GNU Binutils) 2.43.1
Copyright (C) 2024 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

ELF info:

$ objdump -t $(which tracy-profiler) | grep dlclose
0000000000000000       F *UND*  0000000000000000              dlclose@GLIBC_2.2.5

$ libtree $(which tracy-profiler)
/usr/local/bin/tracy-profiler
├── libglfw.so.3 [ld.so.conf]
│   ├── librt.so.1 [ld.so.conf]
│   │   └── libpthread.so.0 [ld.so.conf]
│   ├── libXinerama.so.1 [ld.so.conf]
│   │   ├── libX11.so.6 [ld.so.conf]
│   │   │   └── libxcb.so.1 [ld.so.conf]
│   │   │       ├── libXau.so.6 [ld.so.conf]
│   │   │       └── libXdmcp.so.6 [ld.so.conf]
│   │   │           └── libbsd.so.0 [ld.so.conf]
│   │   │               └── librt.so.1 [ld.so.conf]
│   │   └── libXext.so.6 [ld.so.conf]
│   │       └── libX11.so.6 [ld.so.conf]
│   ├── libXrandr.so.2 [ld.so.conf]
│   │   ├── libXext.so.6 [ld.so.conf]
│   │   ├── libX11.so.6 [ld.so.conf]
│   │   └── libXrender.so.1 [ld.so.conf]
│   │       └── libX11.so.6 [ld.so.conf]
│   ├── libpthread.so.0 [ld.so.conf]
│   ├── libX11.so.6 [ld.so.conf]
│   ├── libXxf86vm.so.1 [ld.so.conf]
│   │   ├── libX11.so.6 [ld.so.conf]
│   │   └── libXext.so.6 [ld.so.conf]
│   └── libXcursor.so.1 [ld.so.conf]
│       ├── libXrender.so.1 [ld.so.conf]
│       ├── libX11.so.6 [ld.so.conf]
│       └── libXfixes.so.3 [ld.so.conf]
│           └── libX11.so.6 [ld.so.conf]
├── libdbus-1.so.3 [ld.so.conf]
│   ├── libpthread.so.0 [ld.so.conf]
│   └── libsystemd.so.0 [ld.so.conf]
│       ├── librt.so.1 [ld.so.conf]
│       ├── libpthread.so.0 [ld.so.conf]
│       ├── libgcrypt.so.20 [ld.so.conf]
│       │   └── libgpg-error.so.0 [ld.so.conf]
│       ├── liblz4.so.1 [ld.so.conf]
│       └── liblzma.so.5 [ld.so.conf]
│           └── libpthread.so.0 [ld.so.conf]
├── libfreetype.so.6 [ld.so.conf]
│   ├── libpng16.so.16 [ld.so.conf]
│   │   └── libz.so.1 [ld.so.conf]
│   └── libz.so.1 [ld.so.conf]
└── libpthread.so.0 [ld.so.conf]

Edit: FWIW adding dl to target_link_libraries in profiler/CMakeLists.txt fixes it.

wolfpld commented 1 month ago

Edit: FWIW adding dl to target_link_libraries in profiler/CMakeLists.txt fixes it.

Yes, but the question is, why? Tracy doesn't use dlclose, so the problem seems to be somewhere else.

dieortin commented 1 month ago

I'm running into the same problem