infer icon indicating copy to clipboard operation
infer copied to clipboard

how to use infer for cross compile

Open liujian56 opened this issue 7 years ago • 8 comments

with https://github.com/facebook/infer/releases/download/v0.15.0/infer-linux64-v0.15.0.tar.xz,it seem can not work for cross compile?

use aarch64-linux-gnu-gcc :

$ infer --keep-going -- aarch64-linux-gnu-gcc -g main.c -o abc
Internal Error: Unsupported build command aarch64-linux-gnu-gcc
Error backtrace:
Raised at file "base/Die.ml" (inlined), line 25, characters 6-36
Called from file "base/Die.ml" (inlined), line 36, characters 44-66
Called from file "format.ml", line 1364, characters 4-36
Called from file "integration/Driver.ml", line 468, characters 12-68
Called from file "camlinternalLazy.ml", line 27, characters 17-27
Re-raised at file "camlinternalLazy.ml", line 34, characters 4-11
Called from file "infer.ml" (inlined), line 34, characters 24-64
Called from file "infer.ml", line 116, characters 2-10

use host gcc:

$ infer --keep-going -- gcc -g main.c -o abc
Capturing in make/cc mode...
Found 1 source file to analyze in /home/liujian/tmp/infer-out
Starting analysis...

legend:
  "F" analyzing a file
  "." analyzing a procedure

F.
Found 1 issue

main.c:17: error: RESOURCE_LEAK
  resource acquired to `fd` by call to `open()` at line 16, column 7 is not released after line 17, column 2.
  15.           int fd;
  16.           fd = open("aa",O_RDONLY);
  17. >         printf("test..fd:%d.\n", fd);
  18.           return 0;
  19.   }

liujian56 avatar Jun 20 '18 09:06 liujian56

Does this work for you?

$ infer --force-integration cc -- aarch64-linux-gnu-gcc -g main.c -o abc

It will still call a host compiler under the hood so some things may still not work.

jvillard avatar Jun 20 '18 15:06 jvillard

Thank you jvillard ! It can work for the above example, but can not work with make. I want to check one project which compiled by cross compiler (aarch64-linux-gnu-gcc and aarch64-linux-android-gcc) on x86 host computer. infer --force-integration make -- make the above command, it can not work yet. How to do in this situation? Do we need build Infer from source?
If yes, what do we need to configure when build the Infer from source?

liujian56 avatar Jun 21 '18 01:06 liujian56

The issue here is that the make integration relies on running make with some hardcoded compilers set to point to infer. You can see them in /path/to/infer/install/lib/infer/infer/lib/wrappers:

$ ls -l /usr/local/lib/infer/infer/lib/wrappers
c++ -> ../../bin/infer
cc -> ../../bin/infer
clang -> ../../bin/infer
clang++ -> ../../bin/infer
g++ -> ../../bin/infer
gcc -> ../../bin/infer

There are two ways you can make this mechanism work in your case:

  1. If possible, generate Makefiles that point to a compiler that infer knows about (eg, gcc) instead aarch64-linux-gnu-gcc
  2. Otherwise, you can add your compiler name to the wrappers directory:
cd /path/to/infer/install/lib/infer/infer/lib/wrappers
ln -s ../../bin/infer aarch64-linux-gnu-gcc

Let me know if this helps.

jvillard avatar Jun 21 '18 10:06 jvillard

hi jvillard, Thanks for your reply.

It still can not work.

add the compiler name: ls -ln total 4 lrwxrwxrwx 1 1003 1006 15 6月 22 06:38 aarch64-linux-android-c++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:38 aarch64-linux-android-cc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:38 aarch64-linux-android-clang -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:38 aarch64-linux-android-clang++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:38 aarch64-linux-android-g++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:35 aarch64-linux-android-gcc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:28 aarch64-linux-gnu-c++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:28 aarch64-linux-gnu-cc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:29 aarch64-linux-gnu-g++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:28 aarch64-linux-gnu-gcc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:39 arm-eabi-c++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:39 arm-eabi-cc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:39 arm-eabi-g++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 22 06:30 arm-eabi-gcc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 5 03:08 c++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 5 03:08 cc -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 5 03:08 clang -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 5 03:08 clang++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 5 03:08 g++ -> ../../bin/infer lrwxrwxrwx 1 1003 1006 15 6月 5 03:08 gcc -> ../../bin/infer -rwxr-xr-x 1 1003 1006 843 6月 5 03:08 javac

I wrote a test Makefile as below: all: #aarch64-linux-android-gcc $(CFLAGS) -g main.c -o abc aarch64-linux-gnu-gcc $(CFLAGS) -g main.c -o abc #gcc $(CFLAGS) -g main.c -o abc

$ infer --force-integration make -- make Capturing in make/cc mode... #aarch64-linux-android-gcc -g main.c -o abc aarch64-linux-gnu-gcc -g main.c -o abc /home/liujian/infer-linux64-v0.15.0/lib/infer/infer/bin/infer: Unexpected anonymous argument: 'main.c'. Infer version v0.15.0 Copyright 2009 - present Facebook. All Rights Reserved. Usage: infer command [options] See infer --help for more information. Makefile:3: recipe for target 'all' failed make: *** [all] Error 1 External Error: *** capture command failed: *** make *** exited with code 2

Error backtrace: Raised at file "base/Die.ml" (inlined), line 23, characters 6-36 Called from file "base/Logging.ml", line 314, characters 58-80 Called from file "infer.ml", line 20, characters 2-36 Called from file "infer.ml", line 130, characters 8-54

Run the command again with --keep-going to try and ignore this error.

$ infer -- make Capturing in make/cc mode... #aarch64-linux-android-gcc -g main.c -o abc aarch64-linux-gnu-gcc -g main.c -o abc /home/liujian/infer-linux64-v0.15.0/lib/infer/infer/bin/infer: Unexpected anonymous argument: 'main.c'. Infer version v0.15.0 Copyright 2009 - present Facebook. All Rights Reserved. Usage: infer command [options] See infer --help for more information. Makefile:3: recipe for target 'all' failed make: *** [all] Error 1 External Error: *** capture command failed: *** make *** exited with code 2

Error backtrace: Raised at file "base/Die.ml" (inlined), line 23, characters 6-36 Called from file "base/Logging.ml", line 314, characters 58-80 Called from file "infer.ml", line 20, characters 2-36 Called from file "infer.ml", line 130, characters 8-54

Run the command again with --keep-going to try and ignore this error.

I find clang's target is x86_64, Does this have an effect? infer-linux64-v0.15.0/lib/infer/facebook-clang-plugins/clang/install/bin$ ./clang --version clang version 7.0.0 Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/liujian/infer-linux64-v0.15.0/lib/infer/facebook-clang-plugins/clang/install/bin/. And I modified facebook-clang-plugins/clang/setup.sh, but faild to compile out one clang whose target is aarch64.

liujian56 avatar Jun 21 '18 13:06 liujian56

Ah, I think that infer needs to know about the new compilers too, the symbolic links are not enough. It would be good to add the possibility of changing that hardcoded list of compilers from infer itself but for now we cannot...

Can you edit the Makefile? If so, you may get away with adding this to the top of your Makefile, which adds an argument to the infer subprocesses that will run once make is called:

export INFER_ARGS=$(shell printf "%s" "$$INFER_ARGS")^--force-integration^cc

jvillard avatar Jun 21 '18 14:06 jvillard

The project is for arm platform, can not use host(x86) gcc compile successfully.

And add the command to Makefile, it seems useless ... export INFER_ARGS=$(shell printf "%s" "$$INFER_ARGS")^--force-integration^cc

I change Makefile in %.o target as below: infer --force-integration cc -- $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c $< -o $@

Some errors as below:

error 1:

Capturing in make/cc mode... ...... src/hmkapi.h:24:36: error: member reference type 'int' is not a pointer return (cref_t)(hmapi_tls_get()->thread_handler); ~~~~~~~~~~~~~~~ ^ src/hmkapi.h:51:36: error: member reference type 'int' is not a pointer return (cref_t)(hmapi_tls_get()->cnode_cref); ~~~~~~~~~~~~~~~ ^ src/hmkapi.h:206:36: error: member reference type 'int' is not a pointer return (cref_t)(hmapi_tls_get()->aspace); ~~~~~~~~~~~~~~~ ^ src/hmapi.c:649:27: error: member reference type 'int' is not a pointer return hmapi_tls_get()->thread_id; ~~~~~~~~~~~~~~~ ^ 5 errors generated. Error: the following clang command did not run successfully: /home/liujian/infer-linux64-v0.15.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-7.0 @/tmp/clang_command_.tmp.657dd7.txt ++Contents of '/tmp/clang_command_.tmp.657dd7.txt': "-cc1" "-load" "/home/liujian/infer-linux64-v0.15.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib" "-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-" "-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1" "-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "hmapi.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-momit-leaf-frame-pointer" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" ....

error 2:

Capturing in make/cc mode... error: unknown target CPU 'armv8-a+nofp' Uncaught Internal Error: (Bi_inbuf.End_of_input) Error backtrace: Raised at file "src/bi_inbuf.ml", line 49, characters 6-24 Called from file "src/bi_io.ml" (inlined), line 508, characters 12-35 Called from file "atd/clang_ast_b.ml", line 27643, characters 7-24 Called from file "clang/Capture.ml", line 56, characters 8-39 Called from file "clang/Capture.ml" (inlined), line 101, characters 6-35 Called from file "clang/Capture.ml", line 170, characters 26-73 Re-raised at file "istd/IExn.ml" (inlined), line 18, characters 15-63 Called from file "clang/Capture.ml" (inlined), line 102, characters 4-60 Called from file "clang/Capture.ml", line 170, characters 26-73 Called from file "base/Utils.ml" (inlined), line 218, characters 13-22 Called from file "base/Utils.ml" (inlined), line 165, characters 8-12 Called from file "base/Utils.ml", line 220, characters 2-40 Re-raised at file "istd/IExn.ml" (inlined), line 13, characters 2-50 Called from file "base/Utils.ml" (inlined), line 166, characters 6-141 Called from file "base/Utils.ml", line 220, characters 2-40 Called from file "clang/Capture.ml" (inlined), line 113, characters 8-78 Called from file "clang/Capture.ml" (inlined), line 140, characters 2-37 Called from file "clang/Capture.ml", line 169, characters 8-138 Called from file "clang/ClangWrapper.ml" (inlined), line 171, characters 15-45 Called from file "list.ml" (inlined), line 100, characters 12-15 Called from file "list.ml" (inlined), line 98, characters 13-64 Called from file "src/list0.ml" (inlined), line 26, characters 40-75 Called from file "clang/ClangWrapper.ml", line 171, characters 2-54 Called from file "infer.ml", line 20, characters 2-36 Called from file "infer.ml", line 130, characters 8-54

Run the command again with --keep-going to try and ignore this error.

Any suggestions for this?

liujian56 avatar Jun 22 '18 07:06 liujian56

Hi,

I changed the project's complier to aarch64-linux-android-clang.

With the infer command: infer -- make

has lots of unknown option errors, one like below: aarch64-linux-android-clang -DTEE_SUPPORT_HIVCODEC -DVCODEC_ENG_VERSION -DTEE_SUPPORT_TZMP2 -DHAVE_AUTOCONF -DARCH_ARM -DAARCH64 -D__KERNEL_64__ -DARMV8_A -DARM_CORTEX_A53 -DKIRIN -DDEBUG -DHM_DEBUG_KERNEL -DTRUSTEDCORE_PLATFORM_CHOOSE=WITH_KIRIN_PLATFORM -DWITH_KIRIN_PLATFORM=0 -DWITH_BALONG_V722_PLATFORM=1 -DWITH_DEVCHIP_PLATFORM=2 ... src/hmapi.c /home/liujian/infer-linux64-v0.15.0/lib/infer/infer/bin/infer: unknown option '-DTEE_SUPPORT_HIVCODEC'. Infer version v0.15.0 Copyright 2009 - present Facebook. All Rights Reserved. Usage: infer command [options] See infer --help for more information.

Why does this happen?

And I would like to consult, according to the information you know, someone used infer like this? I met so many problems ):

thank you~

liujian56 avatar Jun 23 '18 12:06 liujian56

any update?

donaldkuck avatar Feb 08 '23 07:02 donaldkuck