[clang] make ndk-build integration compatible with clang 8

Summary:
Somehow clang now chooses slightly different arguments to pass to `ld`
in the invocation that `ndk-build` makes to link:

```
 --- clang7      2019-05-28 07:47:19.214949009 -0700
+++ clang8      2019-05-28 07:46:55.095924374 -0700
@@ -1,6 +1,15 @@
 "/opt/android_ndk/r15c/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld"
 "--sysroot=/opt/android_ndk/r15c/platforms/android-21/arch-arm64"
+"-EL"
 "--fix-cortex-a53-843419"
+"-z"
+"now"
+"-z"
+"relro"
+"-z"
+"max-page-size=4096"
+"--hash-style=gnu"
+"--hash-style=both"
 "--no-add-needed"
 "--enable-new-dtags"
 "--eh-frame-hdr"
@@ -32,7 +41,7 @@
 "--fatal-warnings"
 "-lc"
 "-lm"
-"-lstdc++"
+"-lc++"
 "-lm"
 "-lgcc"
 "-ldl"
```

In particular:
- `lc++` results in `libc++.so` not found from the toolchain
- the forced relocation `-z relro` fails with "/..//bin/ld: ./obj/local/arm64-v8a/objs/hello/__/hello.o: Relocations in generic ELF (EM: 183)" and other weirder errors

Somehow pretending the C++ compiler is `clang` instead of `clang++` stops the insanity.

Also add an Application.mk file to specify some sane defaults.

Also add `V=1` to the `ndk-build` invocation in our tests so that when it fails we have a bit more to work with.

Reviewed By: mbouaziz, martintrojer

Differential Revision: D15518447

fbshipit-source-id: 40203814b
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 2c15245260
commit 4697b22fb4

@ -29,8 +29,13 @@ create_argparser = util.base_argparser(MODULE_DESCRIPTION, MODULE_NAME)
class NdkBuildCapture(): class NdkBuildCapture():
def __init__(self, args, cmd): def __init__(self, args, cmd):
cmd = [cmd[0], 'NDK_TOOLCHAIN_VERSION=clang', 'TARGET_CC=clang', cmd = [
'TARGET_CXX=clang++', 'TARGET_LD=ld'] + cmd[1:] cmd[0],
'NDK_TOOLCHAIN_VERSION=clang',
'TARGET_CC=clang',
'TARGET_CXX=clang',
'TARGET_LD=ld',
] + cmd[1:]
self.args = args self.args = args
self.cmd = cmd self.cmd = cmd
command_name = os.path.basename(cmd[0]) command_name = os.path.basename(cmd[0])

@ -0,0 +1,5 @@
# Copyright (c) 2019-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
APP_PLATFORM := android-21

@ -9,7 +9,7 @@ PROJECT_ROOT = ../codetoanalyze/ndk-build/hello_app
SOURCES = $(PROJECT_ROOT)/hello.c SOURCES = $(PROJECT_ROOT)/hello.c
OBJECTS = $(PROJECT_ROOT)/hello.o OBJECTS = $(PROJECT_ROOT)/hello.o
INFERPRINT_OPTIONS = --issues-tests INFERPRINT_OPTIONS = --issues-tests
CLEAN_EXTRA = libs obj CLEAN_EXTRA = $(PROJECT_ROOT)/libs $(PROJECT_ROOT)/obj
include $(TESTS_DIR)/infer.make include $(TESTS_DIR)/infer.make
@ -21,4 +21,4 @@ infer-out/report.json: $(CLANG_DEPS) $(SOURCES)
$(QUIET)cd $(PROJECT_ROOT) && \ $(QUIET)cd $(PROJECT_ROOT) && \
$(call silent_on_success,Testing ndk-build clang integration,\ $(call silent_on_success,Testing ndk-build clang integration,\
$(INFER_BIN) --results-dir $(CURDIR)/infer-out -- \ $(INFER_BIN) --results-dir $(CURDIR)/infer-out -- \
$(NDKBUILD) -B NDK_LIBS_OUT=./libs NDK_OUT=./obj) $(NDKBUILD) -B NDK_LIBS_OUT=./libs NDK_OUT=./obj V=1)

Loading…
Cancel
Save