1

I am trying to set up static analysis for our code base which is cross compiled for a ARM based CPU. It appears that scan-build provided by clang is one of the best open source solutions for this. When I run scan-build, this is what I get.

$ scan-build-3.8 --use-cc=arm-linux-gnueabi-gcc --analyzer-target=arm-linux-gnueabi make
    scan-build: Using '/usr/lib/llvm-3.8/bin/clang' for static analysis
    echo "(Version file)"
    (Version file)
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find crti.o: No such file or directory
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find crtbeginS.o: No such file or directory
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find -lgcc
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find -lgcc_s
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find -lc
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find -lgcc
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find -lgcc_s
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find crtendS.o: No such file or directory
    /opt/sysroots/x86_64-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld: cannot find crtn.o: No such file or directory
    collect2: error: ld returned 1 exit status

Clearly, Linker is trying to find some files and not finding it. I dug a little more deeper into how the linker gets the files by running this command.

$ /opt/sysroots/x86_64-dspg-linux/usr/libexec/arm-linux-gnueabi/gcc/arm-linux-gnueabi/6.3.0/real-ld crti.o --verbose

This prints a lot of data, this what I found interesting.

SEARCH_DIR("=/opt/dspg/v2.4.0-rc2/sysroots/x86_64-dspg-linux/usr/arm-dspg-linux-gnueabi/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");

My crti.o is not located in any of the paths above and hence ld is failing.

Now the question. When the scan-build calls the linker how does it inform the search directories and can I change it ?

Rohit Walavalkar
  • 790
  • 9
  • 28
  • Not an answer but for the static analysis portion does it matter if the program doesn't link correctly? The static analysis all happens prior to linking right? – Increasingly Idiotic Apr 13 '18 at 21:52
  • Yes. You are right. This question is not valid anymore I guess. I am getting warnings while compilation as well. Will post that soon. – Rohit Walavalkar Apr 15 '18 at 02:29

0 Answers0