This is an archive of the discontinued LLVM Phabricator instance.

Replace SVE_PT* macros in NativeRegisterContextLinux_arm64.{cpp,h} with their equivalent defintions in LinuxPTraceDefines_arm64sve.h
ClosedPublic

Authored by cmtice on Jun 23 2021, 4:47 PM.

Details

Summary

Commit 090306fc80dbf (August 2020) changed most of the arm64 SVE_PT* macros, but apparently did not make the changes in the NativeRegisterContextLinux_arm64.* files (or those files were pulled over from someplace else after that commit). This change replaces the macros NativeRegisterContextLinux_arm64.cpp (which as far as I can tell are no longer defined anywhere) with the replacement definitions in LinuxPTraceDefines_arm64sve.h. It also includes LinuxPTraceDefines_arm64sve.h in NativeRegisterContextLinux_arm64.h.

Diff Detail

Event Timeline

cmtice created this revision.Jun 23 2021, 4:47 PM
cmtice requested review of this revision.Jun 23 2021, 4:47 PM
cmtice added reviewers: labath, omjavaid.
cmtice retitled this revision from Replace SVE_PT* in NativeRegisterContextLinux_arm64.{cpp,h} with their equivalent defintions in LinuxPTraceDefines_arm64sve.h to Replace SVE_PT* macros in NativeRegisterContextLinux_arm64.{cpp,h} with their equivalent defintions in LinuxPTraceDefines_arm64sve.h.Jun 23 2021, 4:52 PM

Do you see a specific need for this change? We have used macro definition from ptrace.h in case we are running on native aarch64/linux. This was done deliberately because newer sysroots (ubuntu bionic or focal) include these macros defined in ptrace.h by default. However custom definitions of these macros was only required to cater the need for elf core register access while running on a foreign triple.

I found a need for this change when I was trying to build (cross-compile) lldb/lldb-server for aarch64 inside Chrome OS -- the build I had was failing for aarch64 with all of these symbols "undefined". If you can tell me the cmake configs and/or build flags I should use to try to get these symbols from ptrace.h, I can try that instead. But since this is a cross-compile, they might not be available on the build system?

To be clear, this is all elf/linux, and the builds happen on x86_64 machines.

You can try following steps on Ubuntu Bionic x86_64 thats what I am running and build works out of the box.

  1. Install build dependencies:
  2. sudo apt install gcc-8-aarch64-linux-gnu
  3. sudo apt install g++-8-aarch64-linux-gnu

BUILD_TYPE=Release
LLDB_TARGET_ARCH=AArch64

C_COMPILER=clang
CXX_COMPILER=clang++

LLVM_SRC_DIR=<llvm-project>

LLDB_HOST_TRIPLE=aarch64-linux-gnu

We need *tblgen from host

LLVM_HOST_BUILD_DIR=../host

BUILD_ENV_TRIPLE=gcc -dumpmachine

GCC_INC=/usr/$LLDB_HOST_TRIPLE/include
#GCC_V3=gcc --version | grep ^gcc | sed 's/^.* //g'
GCC_V3=gcc -dumpversion
TARGET_C_FLAGS="-target $LLDB_HOST_TRIPLE -I/$GCC_INC -I/$GCC_INC/c++/$GCC_V3/$LLDB_HOST_TRIPLE"
TARGET_CXX_FLAGS="$TARGET_C_FLAGS"

cmake -G Ninja \
-DCMAKE_CROSSCOMPILING=1 \
-DCMAKE_C_COMPILER=$C_COMPILER \
-DCMAKE_CXX_COMPILER=$CXX_COMPILER \
-DCMAKE_C_FLAGS="$TARGET_C_FLAGS" \
-DCMAKE_CXX_FLAGS="$TARGET_CXX_FLAGS" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLLVM_USE_LINKER=gold \
-DLLVM_TABLEGEN=$LLVM_HOST_BUILD_DIR/bin/llvm-tblgen \
-DCLANG_TABLEGEN=$LLVM_HOST_BUILD_DIR/bin/clang-tblgen \
-DLLDB_TABLEGEN=$LLVM_HOST_BUILD_DIR/bin/lldb-tblgen \
-DLLVM_HOST_TRIPLE=$LLDB_HOST_TRIPLE \
-DLLVM_TARGETS_TO_BUILD=$LLDB_TARGET_ARCH \
-DLLVM_ENABLE_PROJECTS="clang;lldb" \
-DCMAKE_LIBRARY_ARCHITECTURE=$LLDB_HOST_TRIPLE \
-DCMAKE_IGNORE_PATH=/usr/lib/$BUILD_ENV_TRIPLE \
-DLLDB_TEST_COMPILER=$LLDB_HOST_TRIPLE-gcc \
-DLLDB_EXPORT_ALL_SYMBOLS=1 \
-DLLVM_ENABLE_ASSERTIONS=On \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DLLDB_ENABLE_PYTHON=0 \
-DLLDB_ENABLE_LIBEDIT=0 \
-DLLDB_ENABLE_CURSES=0 \
-DLLVM_PARALLEL_LINK_JOBS=1 \
$LLVM_SRC_DIR/llvm

ninja lldb-server

Can we do this just using clang/llvm? We've stopped using GCC in Chrome OS and have pretty much removed it altogether.

Above instructions use clang as compiler but utilize GCC for library includes you can replace gcc includes with your version of include paths.

Matt added a subscriber: Matt.Jun 24 2021, 11:10 AM

I have tried to build lldb-server for aarch64 inside Chrome OS following the instructions above, but due to the way things build in Chrome OS (using the Gentoo Linux portage system) this does not work. I also have not been able to find these definitions in ptrace.h files inside Chrome OS.

omjavaid accepted this revision.Jun 28 2021, 4:17 PM

This is LGTM Kindly run clang-format before committing your changes. thanks!

This revision is now accepted and ready to land.Jun 28 2021, 4:17 PM
This revision was landed with ongoing or failed builds.Jun 30 2021, 9:27 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2021, 9:27 AM