Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Compilation error with NDK-21: couldn't infer template argument 'Fun' #1328

Closed
emrekultursay opened this issue Aug 4, 2020 · 2 comments
Assignees
Labels

Comments

@emrekultursay
Copy link

Description

I was trying to cross-compile lldb-server for Android based on the public documentation here.

I can compile lldb-server for aarch64 using NDK 20 (20.0.5594570). However, using NDK 21 (I tried both 21.1.6352462 and 21.3.6528147) gives a compilation error. There might be a regression (in the compiler frontend?).

Here's the error:

FAILED: tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/PseudoTerminal.cpp.o 
/usr/local/google/home/emrekultursay/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/usr/local/google/home/emrekultursay/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/usr/local/google/home/emrekultursay/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/sysroot  -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -DLLDB_CONFIGURATION_RELEASE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/lldb/source/Host -I/usr/local/google/home/emrekultursay/llvm-project/lldb/source/Host -Itools/lldb/source -I/usr/local/google/home/emrekultursay/llvm-project/lldb/include -Itools/lldb/include -Iinclude -I/usr/local/google/home/emrekultursay/llvm-project/llvm/include -I/usr/local/google/home/emrekultursay/llvm-project/llvm/../clang/include -Itools/lldb/../clang/include -I/usr/local/google/home/emrekultursay/llvm-project/lldb/source/. -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O2 -DNDEBUG  -fPIC    -fno-exceptions -fno-rtti -std=c++14 -MD -MT tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/PseudoTerminal.cpp.o -MF tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/PseudoTerminal.cpp.o.d -o tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/PseudoTerminal.cpp.o -c /usr/local/google/home/emrekultursay/llvm-project/lldb/source/Host/common/PseudoTerminal.cpp
/usr/local/google/home/emrekultursay/llvm-project/lldb/source/Host/common/PseudoTerminal.cpp:138:7: error: no matching function for call to 'RetryAfterSignal'
      llvm::sys::RetryAfterSignal(-1, ::open, secondary_name, oflag);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/google/home/emrekultursay/llvm-project/llvm/include/llvm/Support/Errno.h:33:23: note: candidate template ignored: couldn't infer template argument 'Fun'
inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F,
                      ^
1 error generated.

Environment Details

  • NDK Version: 21.1.6352462 and 21.3.6528147
  • Build system: CMake
  • Host OS: Linux
  • ABI: target abi is aarch64

Repro instructions

bash$ git clone https://github.com/llvm/llvm-project.git
bash$ mkdir lldb-server-build && cd lldb-server-build
bash$ cat > build.sh << EOF
#!/bin/bash
export ANDROID_NDK_HOME=~/Android/Sdk/ndk/21.3.6528147
cmake \
  -B out \
  -G Ninja \
  ../llvm-project/llvm \
  -DLLVM_TARGETS_TO_BUILD=AArch64 \
  -DLLDB_ENABLE_PYTHON=0 \
  -DLLDB_ENABLE_LIBEDIT=0 \
  -DLLDB_ENABLE_CURSES=0 \
  -DLLVM_ENABLE_TERMINFO=0 \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="clang;lldb" \
  -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-21 \
  -DANDROID_ALLOW_UNDEFINED_SYMBOLS=On \
  -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-android \
  -DCROSS_TOOLCHAIN_FLAGS_NATIVE='-DCMAKE_C_COMPILER=cc;-DCMAKE_CXX_COMPILER=c++'
EOF
bash$ ./build.sh
bash$ cd out
bash$ ninja lldb-server

Some of the CMake/LLDB flags above may be redundant, but don't change the outcome.

Note: The following commit might be relevant: llvm/llvm-project@0a0e411

@DanAlbert DanAlbert added this to the r21e milestone Aug 4, 2020
@DanAlbert DanAlbert removed this from the r21e milestone Feb 2, 2021
@Kudo
Copy link

Kudo commented May 30, 2021

thank @emrekultursay for sharing the related commit for llvm.
a finding that there was a bionic fortify change:
https://android.googlesource.com/platform/bionic/+/9349b9e51b41d12fd054b925802b626ca2db0afb%5E%21/#F0
This removal of #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ landed after NDK r21 and that's why the problem happens only after r21.

facebook-github-bot pushed a commit to facebook/folly that referenced this issue Jun 27, 2021
Summary:
Android NDK bionic with FORTIFY will override original `open()` definition and making folly `wrapNoInt` template failed to deduct.
The issue may happen only after NDK r21 because [this commit landed after r21](https://android.googlesource.com/platform/bionic/+/9349b9e51b41d12fd054b925802b626ca2db0afb%5E%21/#F0)

References:
android/ndk#1328
llvm/llvm-project@0a0e411

Pull Request resolved: #1593

Test Plan:
Tested running `objdump -dr` on the object file generated in both `mode/opt`
and `mode/opt-gcc` build modes and confirmed the generated code was
identical.

Reviewed By: yfeldblum

Differential Revision: D28953120

Pulled By: simpkins

fbshipit-source-id: 225583a5a011e8456592a0bcfcd669fe966ea6af
@DanAlbert
Copy link
Member

I believe this is obsolete, since we're building LLDB with r23 now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants