[CMake] Use LLVM own tools in extract_symbols.py
authorIgor Kudrin <ikudrin@accesssoftek.com>
Sat, 22 Apr 2023 03:01:10 +0000 (20:01 -0700)
committerIgor Kudrin <ikudrin@accesssoftek.com>
Mon, 15 May 2023 23:20:19 +0000 (16:20 -0700)
commitf649599ea93301bd0d0a2b8e450d1f77425ea92e
treeebe6ae52b4d878fdfa77de6ac53ccb4bc1212044
parent7d2b7be28d903a74f3ca10b2d5f97d69e006df62
[CMake] Use LLVM own tools in extract_symbols.py

As for now, 'extract_symbols.py' can use several tools to extract
symbols from object files and libraries and to guess if the target is
32-bit Windows. The tools are being found via PATH, so in most cases,
they are just system tools. This approach has a number of limitations,
in particular:

* System tools may not be able to handle the target format in case of
  cross-platform builds,
* They cannot read symbols from LLVM bitcode files, so the staged LTO
  build with plugins is not supported,
* The auto-selected tools may be suboptimal (see D113557),
* Support for multiple tools for a single task increases the complexity
  of the script code.

The patch proposes using LLVM's own tools to solve these issues.
Specifically, 'llvm-readobj' detects the target platform, and 'llvm-nm'
reads symbols from all supported formats, including bitcode files. The
tools can be built in Release mode for the host platform or overridden
using CMake settings 'LLVM_READOBJ' and 'LLVM_NM' respectively. The
implementation also supports using precompiled tools via
'LLVM_NATIVE_TOOL_DIR'.

Differential Revision: https://reviews.llvm.org/D149119
llvm/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/CrossCompile.cmake
llvm/tools/llvm-nm/CMakeLists.txt
llvm/tools/llvm-readobj/CMakeLists.txt
llvm/tools/llvm-shlib/CMakeLists.txt
llvm/utils/extract_symbols.py