llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.77k stars 11.89k forks source link

Can not build lldb15.0.0 on i686 against older kernel (pre-4.1) #57594

Open satmandu opened 2 years ago

satmandu commented 2 years ago

14.x built fine. This might be related to this issue with llvm 13: https://bugs.llvm.org/show_bug.cgi?id=51917

Building llvm 15.0.0 on i686 gives me this error:

[7465/7686] Building CXX object tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/NativeThreadLinux.cpp.o
samu: job failed: CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/local/bin/ccache /usr/local/lib/ccache/bin/clang++ -DHAVE_ROUND -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/usr/local/tmp/crew/llvm.20220906180702.dir/builddir/tools/lldb/source/Plugins/Process/Linux -I/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux -I/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/include -I/usr/local/tmp/crew/llvm.20220906180702.dir/builddir/tools/lldb/include -I/usr/local/tmp/crew/llvm.20220906180702.dir/builddir/include -I/usr/local/tmp/crew/llvm.20220906180702.dir/llvm/include -I/usr/local/tmp/crew/llvm.20220906180702.dir/llvm/../clang/include -I/usr/local/tmp/crew/llvm.20220906180702.dir/builddir/tools/lldb/../clang/include -I/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source -I/usr/local/tmp/crew/llvm.20220906180702.dir/builddir/tools/lldb/source -isystem /usr/local/include/libxml2 -latomic -fPIC -flto=thin -fvisibility-inlines-hidden -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -fdiagnostics-color -flto=thin -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG  -fno-exceptions -std=c++14 -MD -MT tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/Perf.cpp.o -MF tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/Perf.cpp.o.d -o tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/Perf.cpp.o -c /usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp
clang-14: warning: -latomic: 'linker' input unused [-Wunused-command-line-argument]
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:135:17: error: no member named 'aux_offset' in 'perf_event_mmap_page'
  metadata_page.aux_offset =
  ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:136:21: error: no member named 'data_offset' in 'perf_event_mmap_page'
      metadata_page.data_offset + metadata_page.data_size;
      ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:136:49: error: no member named 'data_size' in 'perf_event_mmap_page'
      metadata_page.data_offset + metadata_page.data_size;
                                  ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:137:17: error: no member named 'aux_size' in 'perf_event_mmap_page'
  metadata_page.aux_size = num_aux_pages * getpagesize();
  ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:140:41: error: no member named 'aux_size' in 'perf_event_mmap_page'
          DoMmap(nullptr, metadata_page.aux_size, PROT_READ, MAP_SHARED,
                          ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:141:32: error: no member named 'aux_offset' in 'perf_event_mmap_page'
                 metadata_page.aux_offset, "aux buffer")) {
                 ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:177:29: error: no member named 'data_offset' in 'perf_event_mmap_page'
              mmap_metadata.data_offset,
              ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:178:46: error: no member named 'data_size' in 'perf_event_mmap_page'
           static_cast<size_t>(mmap_metadata.data_size)};
                               ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:184:46: error: no member named 'aux_size' in 'perf_event_mmap_page'
           static_cast<size_t>(mmap_metadata.aux_size)};
                               ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:208:38: error: no member named 'data_size' in 'perf_event_mmap_page'
  uint64_t data_size = mmap_metadata.data_size;
                       ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:244:37: error: no member named 'aux_head' in 'perf_event_mmap_page'
  uint64_t aux_head = mmap_metadata.aux_head;
                      ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:301:47: error: no member named 'data_size' in 'perf_event_mmap_page'
  if (mmap_metadata.data_head < mmap_metadata.data_size)
                                ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:304:26: error: no member named 'data_size' in 'perf_event_mmap_page'
    return mmap_metadata.data_size; // The buffer has wrapped.
           ~~~~~~~~~~~~~ ^
/usr/local/tmp/crew/llvm.20220906180702.dir/lldb/source/Plugins/Process/Linux/Perf.cpp:310:8: warning: unused variable 'log' [-Wunused-variable]
llvmbot commented 2 years ago

@llvm/issue-subscribers-lldb

labath commented 2 years ago

@a20012251

Failures to build on kernels this old aren't completely surprising. We don't have an officially set minimum target version, but I doubt that anybody tests these configurations on a regular basis.

Still, if this is the only failure, then it should be fairly easy to make this work, perhaps by disabling the entire tracing feature in this setups. Could you create patch that does that?

satmandu commented 2 years ago

I'm not a CMake expert, but one way to deal with this might be to add a check for that kernel functionality in https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/Linux/CMakeLists.txt to surround the inclusion of https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/Linux/Perf.cpp using cmake's CheckStructHasMember functionality?

Something along the lines of using code like this?

CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" aux_head linux/perf_event.h HAVE_PERF_AUX_HEAD)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" aux_offset linux/perf_event.h HAVE_PERF_AUX_OFFSET)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" aux_size linux/perf_event.h HAVE_PERF_AUX_SIZE)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" data_offset linux/perf_event.h HAVE_PERF_DATA_OFFSET)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" data_size linux/perf_event.h HAVE_PERF_DATA_SIZE)
labath commented 2 years ago

Yes, that sounds reasonable. You probably don't have to check for every single member that's being used, checking the oldest one would suffice.

satmandu commented 2 years ago

I tried replacing https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/Linux/CMakeLists.txt with this:

include(CheckStructHasMember)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" aux_head linux/perf_event.h HAVE_PERF_AUX_HEAD)
if(HAVE_PERF_AUX_HEAD)
add_lldb_library(lldbPluginProcessLinux
  IntelPTCollector.cpp
  IntelPTSingleBufferTrace.cpp
  IntelPTMultiCoreTrace.cpp
  IntelPTPerThreadProcessTrace.cpp
  IntelPTThreadTraceCollection.cpp
  NativeProcessLinux.cpp
  NativeRegisterContextLinux.cpp
  NativeRegisterContextLinux_arm.cpp
  NativeRegisterContextLinux_arm64.cpp
  NativeRegisterContextLinux_ppc64le.cpp
  NativeRegisterContextLinux_riscv64.cpp
  NativeRegisterContextLinux_s390x.cpp
  NativeRegisterContextLinux_x86_64.cpp
  NativeThreadLinux.cpp
  Perf.cpp
  Procfs.cpp
  SingleStepCheck.cpp

  LINK_LIBS
    lldbCore
    lldbHost
    lldbSymbol
    lldbTarget
    lldbUtility
    lldbPluginProcessPOSIX
    lldbPluginProcessUtility
  LINK_COMPONENTS
    Support
  )
else()
  add_lldb_library(lldbPluginProcessLinux
    IntelPTCollector.cpp
    IntelPTSingleBufferTrace.cpp
    IntelPTMultiCoreTrace.cpp
    IntelPTPerThreadProcessTrace.cpp
    IntelPTThreadTraceCollection.cpp
    NativeProcessLinux.cpp
    NativeRegisterContextLinux.cpp
    NativeRegisterContextLinux_arm.cpp
    NativeRegisterContextLinux_arm64.cpp
    NativeRegisterContextLinux_ppc64le.cpp
    NativeRegisterContextLinux_riscv64.cpp
    NativeRegisterContextLinux_s390x.cpp
    NativeRegisterContextLinux_x86_64.cpp
    NativeThreadLinux.cpp
    Procfs.cpp
    SingleStepCheck.cpp

    LINK_LIBS
      lldbCore
      lldbHost
      lldbSymbol
      lldbTarget
      lldbUtility
      lldbPluginProcessPOSIX
      lldbPluginProcessUtility
    LINK_COMPONENTS
      Support
    )
endif()

(It looks like aux{head,offset,size} and data{head,offset,size} were introduced together in Linux 4.1.)

satmandu commented 2 years ago

That doesn't appear to fix the issue...

-- Performing Test HAVE_STEADY_CLOCK -- success
-- Configuring incomplete, errors occurred!
See also "/usr/local/tmp/crew/llvm.20220907195444.dir/builddir/CMakeFiles/CMakeOutput.log".
See also "/usr/local/tmp/crew/llvm.20220907195444.dir/builddir/CMakeFiles/CMakeError.log".
llvm failed to build: `CREW_DISABLE_ENV_OPTIONS="1" bash -c LLVM_IAS=1 PATH=/usr/local/lib/ccache/bin:/usr/local/bin:/usr/bin:/bin LD=ld.lld             cmake -G Ninja             -DCMAKE_ASM_COMPILER_TARGET=i686-cros-linux-gnu             -DCMAKE_BUILD_TYPE=Release             -DCMAKE_C_COMPILER=$(which clang)             -DCMAKE_C_COMPILER_TARGET=i686-cros-linux-gnu             -DCMAKE_C_FLAGS='-latomic -fPIC -fuse-ld=mold -flto=thin'             -DCMAKE_CXX_COMPILER=$(which clang++)             -DCMAKE_CXX_FLAGS='-latomic -fPIC -fuse-ld=mold -flto=thin'             -DCMAKE_EXE_LINKER_FLAGS='-Wl,-znotext -flto=thin'             -DCMAKE_INSTALL_PREFIX=/usr/local             -DCMAKE_LINKER=$(which ld.lld)             -D_CMAKE_TOOLCHAIN_PREFIX=llvm-             -DCOMPILER_RT_BUILD_BUILTINS=ON             -DCOMPILER_RT_BUILD_LIBFUZZER=OFF             -DCOMPILER_RT_BUILD_SANITIZERS=OFF             -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON             -DLIBOMP_ENABLE_SHARED=ON             -DLIBOMP_INSTALL_ALIASES=OFF             -DLIBUNWIND_C_FLAGS='-fno-exceptions -funwind-tables'             -DLIBUNWIND_CXX_FLAGS='-fno-exceptions -funwind-tables'             -DLIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG=ON             -DLIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG=ON             -DLLVM_BINUTILS_INCDIR='/usr/local/include'             -DLLVM_BUILD_LLVM_DYLIB=ON             -DLLVM_CCACHE_BUILD=ON             -DLLVM_DEFAULT_TARGET_TRIPLE=i686-cros-linux-gnu             -DLLVM_ENABLE_FFI=ON             -DLLVM_ENABLE_LTO=Thin             -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;libcxx;libcxxabi;libunwind;lldb;compiler-rt;lld;polly'             -DLLVM_ENABLE_RTTI=ON             -DLLVM_ENABLE_RUNTIME=openmp             -DLLVM_ENABLE_TERMINFO=ON             -DLLVM_INSTALL_UTILS=ON             -DLLVM_LIBDIR_SUFFIX=''             -DLLVM_LINK_LLVM_DYLIB=ON             -DLLVM_OPTIMIZED_TABLEGEN=ON             -DLLVM_TARGETS_TO_BUILD='all'             -DOPENMP_ENABLE_LIBOMPTARGET=OFF             -DPYTHON_EXECUTABLE=$(which python3)             -Wno-dev             ../llvm` exited with 1
DavidSpickett commented 2 years ago
-- Configuring incomplete, errors occurred!

I'm guessing this means there's some issue with your cmake not with the compilation part of it. It can be tricky to make these try_compile sorts of things verbose but the CMakeError.log is a decent place to start.

satmandu commented 2 years ago

Looks like we can't just remove Perf.cpp since then we get complaints during the lldb-server linking:

[7660/7685] Linking CXX executable bin/lldb-server
clang-14: warning: -latomic: 'linker' input unused [-Wunused-command-line-argument]
samu: job failed: : && /usr/local/bin/clang++ -latomic -fPIC -flto=thin -fvisibility-inlines-hidden -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -fdiagnostics-color -flto=thin -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG -Wl,-znotext -flto=thin -flto=thin    -Wl,--gc-sections tools/lldb/tools/lldb-server/CMakeFiles/lldb-server.dir/Acceptor.cpp.o tools/lldb/tools/lldb-server/CMakeFiles/lldb-server.dir/lldb-gdbserver.cpp.o tools/lldb/tools/lldb-server/CMakeFiles/lldb-server.dir/lldb-platform.cpp.o tools/lldb/tools/lldb-server/CMakeFiles/lldb-server.dir/lldb-server.cpp.o tools/lldb/tools/lldb-server/CMakeFiles/lldb-server.dir/LLDBServerUtilities.cpp.o tools/lldb/tools/lldb-server/CMakeFiles/lldb-server.dir/SystemInitializerLLGS.cpp.o -o bin/lldb-server  -Wl,-rpath,"\$ORIGIN/../lib"  -lpthread  lib/liblldbHost.a  lib/liblldbInitialization.a  lib/liblldbVersion.a  lib/liblldbPluginProcessLinux.a  lib/liblldbPluginObjectFileELF.a  lib/liblldbPluginInstructionARM.a  lib/liblldbPluginInstructionMIPS.a  lib/liblldbPluginInstructionMIPS64.a  lib/liblldbPluginProcessGDBRemote.a  /usr/local/lib/libz.so  lib/liblldbPluginProcessPOSIX.a  lib/liblldbCore.a  lib/liblldbSymbol.a  lib/liblldbTarget.a  lib/liblldbPluginProcessUtility.a  lib/liblldbInterpreter.a  lib/liblldbBreakpoint.a  lib/liblldbDataFormatters.a  lib/liblldbExpression.a  lib/liblldbPluginCPlusPlusLanguage.a  lib/liblldbPluginObjCLanguage.a  lib/liblldbCommands.a  lib/liblldbPluginObjectFileJIT.a  lib/liblldbPluginClangCommon.a  lib/liblldbPluginCPPRuntime.a  lib/liblldbPluginTypeSystemClang.a  lib/liblldbPluginAppleObjCRuntime.a  lib/liblldbPluginExpressionParserClang.a  lib/liblldbPluginSymbolFileDWARF.a  lib/liblldbPluginSymbolFilePDB.a  lib/liblldbPluginObjCRuntime.a  lib/liblldbPluginRenderScriptRuntime.a  lib/liblldbPluginSymbolFileNativePDB.a  lib/liblldbPluginObjectFilePDB.a  lib/liblldbCore.a  lib/liblldbSymbol.a  lib/liblldbTarget.a  lib/liblldbPluginProcessUtility.a  lib/liblldbInterpreter.a  lib/liblldbBreakpoint.a  lib/liblldbDataFormatters.a  lib/liblldbExpression.a  lib/liblldbPluginCPlusPlusLanguage.a  lib/liblldbPluginObjCLanguage.a  lib/liblldbCommands.a  lib/liblldbPluginObjectFileJIT.a  lib/liblldbPluginClangCommon.a  lib/liblldbPluginCPPRuntime.a  lib/liblldbPluginTypeSystemClang.a  lib/liblldbPluginAppleObjCRuntime.a  lib/liblldbPluginExpressionParserClang.a  lib/liblldbPluginSymbolFileDWARF.a  lib/liblldbPluginSymbolFilePDB.a  lib/liblldbPluginObjCRuntime.a  lib/liblldbPluginRenderScriptRuntime.a  lib/liblldbPluginSymbolFileNativePDB.a  lib/liblldbPluginObjectFilePDB.a  lib/liblldbCore.a  lib/liblldbSymbol.a  lib/liblldbTarget.a  lib/liblldbPluginProcessUtility.a  lib/liblldbInterpreter.a  lib/liblldbBreakpoint.a  lib/liblldbDataFormatters.a  lib/liblldbExpression.a  lib/liblldbPluginCPlusPlusLanguage.a  lib/liblldbPluginObjCLanguage.a  lib/liblldbCommands.a  lib/liblldbPluginObjectFileJIT.a  lib/liblldbPluginClangCommon.a  lib/liblldbPluginCPPRuntime.a  lib/liblldbPluginTypeSystemClang.a  lib/liblldbPluginAppleObjCRuntime.a  lib/liblldbPluginExpressionParserClang.a  lib/liblldbPluginSymbolFileDWARF.a  lib/liblldbPluginSymbolFilePDB.a  lib/liblldbPluginObjCRuntime.a  lib/liblldbPluginRenderScriptRuntime.a  lib/liblldbPluginSymbolFileNativePDB.a  lib/liblldbPluginObjectFilePDB.a  lib/liblldbCore.a  lib/liblldbSymbol.a  lib/liblldbTarget.a  lib/liblldbPluginProcessUtility.a  lib/liblldbInterpreter.a  lib/liblldbBreakpoint.a  lib/liblldbDataFormatters.a  lib/liblldbExpression.a  lib/liblldbPluginCPlusPlusLanguage.a  lib/liblldbPluginObjCLanguage.a  lib/liblldbCommands.a  lib/liblldbPluginObjectFileJIT.a  lib/liblldbPluginClangCommon.a  lib/liblldbPluginCPPRuntime.a  lib/liblldbPluginTypeSystemClang.a  lib/liblldbPluginAppleObjCRuntime.a  lib/liblldbPluginExpressionParserClang.a  lib/liblldbPluginSymbolFileDWARF.a  lib/liblldbPluginSymbolFilePDB.a  lib/liblldbPluginObjCRuntime.a  lib/liblldbPluginRenderScriptRuntime.a  lib/liblldbPluginSymbolFileNativePDB.a  lib/liblldbPluginObjectFilePDB.a  lib/liblldbCore.a  lib/liblldbSymbol.a  lib/liblldbTarget.a  lib/liblldbPluginProcessUtility.a  lib/liblldbInterpreter.a  lib/liblldbBreakpoint.a  lib/liblldbDataFormatters.a  lib/liblldbExpression.a  lib/liblldbPluginCPlusPlusLanguage.a  lib/liblldbPluginObjCLanguage.a  lib/liblldbCommands.a  lib/liblldbPluginObjectFileJIT.a  lib/liblldbPluginClangCommon.a  lib/liblldbPluginCPPRuntime.a  lib/liblldbPluginTypeSystemClang.a  lib/liblldbPluginAppleObjCRuntime.a  lib/liblldbPluginExpressionParserClang.a  lib/liblldbPluginSymbolFileDWARF.a  lib/liblldbPluginSymbolFilePDB.a  lib/liblldbPluginObjCRuntime.a  lib/liblldbPluginRenderScriptRuntime.a  lib/liblldbPluginSymbolFileNativePDB.a  lib/liblldbPluginObjectFilePDB.a  lib/liblldbVersion.a  lib/liblldbHost.a  /usr/local/lib/libxml2.so  /usr/local/lib/libedit.so  /usr/local/lib/liblzma.so  lib/liblldbUtility.a  -lpthread  lib/libclang-cpp.so.15  lib/libLLVM-15.so  -ldl && :
mold: error: undefined symbol: lldb_private::process_linux::LoadPerfTscConversionParameters()
>>> referenced by IntelPTCollector.cpp
>>>               /usr/local/tmp/lto-llvm-adf267.o:(lldb_private::process_linux::IntelPTCollector::FetchPerfTscConversionParameters())
mold: error: undefined symbol: lldb_private::process_linux::PerfEvent::GetAuxBuffer() const
>>> referenced by IntelPTCollector.cpp
>>>               /usr/local/tmp/lto-llvm-adf267.o:(std::_Function_handler<void (unsigned long long, lldb_private::process_linux::IntelPTSingleBufferTrace&), lldb_private::process_linux::IntelPTCollector::GetState()::$_0>::_M_invoke(std::_Any_data const&, unsigned long long&&, lldb_private::process_linux::IntelPTSingleBufferTrace&))>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::_Function_handler<void (unsigned int, lldb_private::process_linux::IntelPTSingleBufferTrace&, lldb_private::process_linux::PerfEvent&), lldb_private::process_linux::IntelPTMultiCoreTrace::GetState()::$_2>::_M_invoke(std::_Any_data const&, unsigned int&&, lldb_private::process_linux::IntelPTSingleBufferTrace&, lldb_private::process_linux::PerfEvent&))>>> referenced by IntelPTPerThreadProcessTrace.cpp
>>>               /usr/local/tmp/lto-llvm-7e25a9.o:(std::_Function_handler<void (unsigned long long, lldb_private::process_linux::IntelPTSingleBufferTrace&), lldb_private::process_linux::IntelPTPerThreadProcessTrace::GetState()::$_0>::_M_invoke(std::_Any_data const&, unsigned long long&&, lldb_private::process_linux::IntelPTSingleBufferTrace&))>>> referenced 1 more times

mold: error: undefined symbol: lldb_private::process_linux::PerfEvent::GetReadOnlyAuxBuffer()
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(lldb_private::process_linux::IntelPTMultiCoreTrace::TryGetBinaryData(lldb_private::TraceGetBinaryDataRequest const&))>>> referenced by IntelPTThreadTraceCollection.cpp
>>>               /usr/local/tmp/lto-llvm-3063fc.o:(lldb_private::process_linux::IntelPTThreadTraceCollection::TryGetBinaryData(lldb_private::TraceGetBinaryDataRequest const&))
mold: error: undefined symbol: lldb_private::process_linux::resource_handle::FileDescriptorDeleter::operator()(long*)
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(lldb_private::process_linux::IntelPTMultiCoreTrace::StartOnAllCores(lldb_private::TraceIntelPTStartRequest const&, lldb_private::NativeProcessProtocol&, llvm::Optional<int>))>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::pair<lldb_private::process_linux::IntelPTSingleBufferTrace, lldb_private::process_linux::PerfEvent>::~pair())>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::pair<lldb_private::process_linux::IntelPTSingleBufferTrace, lldb_private::process_linux::PerfEvent>::~pair())>>> referenced 4 more times

mold: error: undefined symbol: lldb_private::process_linux::PerfEvent::DisableWithIoctl()
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::_Function_handler<void (unsigned int, lldb_private::process_linux::IntelPTSingleBufferTrace&), lldb_private::process_linux::IntelPTMultiCoreTrace::ProcessDidStop()::$_0>::_M_invoke(std::_Any_data const&, unsigned int&&, lldb_private::process_linux::IntelPTSingleBufferTrace&))
mold: error: undefined symbol: lldb_private::process_linux::PerfEvent::GetReadOnlyDataBuffer()
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(lldb_private::process_linux::IntelPTMultiCoreTrace::TryGetBinaryData(lldb_private::TraceGetBinaryDataRequest const&))
mold: error: undefined symbol: lldb_private::process_linux::PerfEvent::EnableWithIoctl()
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::_Function_handler<void (unsigned int, lldb_private::process_linux::IntelPTSingleBufferTrace&), lldb_private::process_linux::IntelPTMultiCoreTrace::ProcessWillResume()::$_1>::_M_invoke(std::_Any_data const&, unsigned int&&, lldb_private::process_linux::IntelPTSingleBufferTrace&))
mold: error: undefined symbol: lldb_private::process_linux::PerfEvent::GetEffectiveDataBufferSize() const
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::_Function_handler<void (unsigned int, lldb_private::process_linux::IntelPTSingleBufferTrace&, lldb_private::process_linux::PerfEvent&), lldb_private::process_linux::IntelPTMultiCoreTrace::GetState()::$_2>::_M_invoke(std::_Any_data const&, unsigned int&&, lldb_private::process_linux::IntelPTSingleBufferTrace&, lldb_private::process_linux::PerfEvent&))
mold: error: undefined symbol: lldb_private::process_linux::resource_handle::MmapDeleter::operator()(void*)
>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(lldb_private::process_linux::IntelPTMultiCoreTrace::StartOnAllCores(lldb_private::TraceIntelPTStartRequest const&, lldb_private::NativeProcessProtocol&, llvm::Optional<int>))>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(lldb_private::process_linux::IntelPTMultiCoreTrace::StartOnAllCores(lldb_private::TraceIntelPTStartRequest const&, lldb_private::NativeProcessProtocol&, llvm::Optional<int>))>>> referenced by IntelPTMultiCoreTrace.cpp
>>>               /usr/local/tmp/lto-llvm-fd2716.o:(std::pair<lldb_private::process_linux::IntelPTSingleBufferTrace, lldb_private::process_linux::PerfEvent>::~pair())>>> referenced 11 more times

Any other suggestions on a cleaner way to handle this?

DavidSpickett commented 2 years ago

I suggest asking the people who wrote that part of the code. It may be that removing that file makes the rest unusable, even if it would link.

Easiest way is to git blame the file then if you look at the commit on github it'll show with their username and you can tag them here.

satmandu commented 2 years ago

Looks like @a20012251 is the person to ask about this. Any ideas on the best way to fix this? A workaround in the code for when perf_event_mmap_page in linux/perf_event.h doesn't have aux_head might be best?

satmandu commented 2 years ago

I guess you can't do that easily in cpp, so is there a good way to bypass building the Perf file without breaking the rest of the build?

satmandu commented 2 years ago

I'm thinking the cleanest way might be to add this to the CMakeLists.txt in that folder:

include(CheckStructHasMember)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_mmap_page" aux_head linux/perf_event.h HAVE_PERF_AUX_HEAD)
if(HAVE_PERF_AUX_HEAD)
  add_definitions(-DHAVE_PERF_AUX_HEAD)
endif()

And then there could be a conditional based upon that in Perf.cpp .

DavidSpickett commented 2 years ago

So it is possible to hack out the entire trace plugin, but I don't know that that is needed.

https://reviews.llvm.org/D133763 is a rough hack to get Perf.cpp to build without those fields. Of course you'd want to add asserts and wrap the new paths in #ifdef and so on.

(feel free to build on that, such as it is)

Even with that you should check what attempting to use the trace commands does. If they just error then ok but if they crash then the commands also need some tweaking.

I have zero idea if missing this field is fatal for the feature or only going to be a problem for a subset.

Perhaps @a20012251 or @jj10306 know.

If we want to build on this older kernel is it better to disable the intel trace plugin completely, or change the lower level parts to error as I did in the linked patch? (does IntelPT even exist for programs running in i686 mode?)

satmandu commented 2 years ago

Honestly, there's a question of whether it is worth the effort to make this work on older kernels. In the Chromebrew project we're just choosing not to build lldb any longer for the i686 machines with the older kernels. :/

calebzulawski commented 2 years ago

This affects CentOS/Red Hat 7 which are still supported until at least 2024.

DavidSpickett commented 2 years ago

@calebzulawski Could you write a post on the lldb discourse https://discourse.llvm.org/c/subprojects/lldb/8 outlining your concerns and datapoints like that. It'll get more attention there.

This is worth talking about generally and there may be input from the Android side too.

calebzulawski commented 2 years ago

Sure, I can try to put something together.

Also, I just submitted a more complete patch that should fix this, but doesn't address preventing it in the future: https://reviews.llvm.org/D133778