ld linker error using clang analyzer checker

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
Hi,

I am trying to use clang static checker from command line. I knew there are two ways to do that. One is using scan-build command, which works fine for me. But I need to use the checker in another way, which is from the official website, like:

               clang -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format not recognized. It seems like the xxx.o file never being generated using this command line. 

When I added -cc1 option, using it like this way,

                clang -cc1 -analyze -analyzer-checker=xxx test.c

The error is gone, but I have to include all the default compiler headers manually, which I don't wanna do.

My question is, what's the right way to pass the checker to clang to get the bug report and the built file at the same time?

Thanks,
Ying

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
Hello,

It looks like clang is thinking that he has to compile the file because the default behaviour was not changed via cmdline options. Could you try:

clang --analyze -Xclang -analyzer-checker=checker_name test.c

? --analyze will tell clang that he doesn't need to produce binary, only to analyze the file.


06.02.2018 04:24, Yingtong Liu via cfe-dev пишет:
Hi,

I am trying to use clang static checker from command line. I knew there are two ways to do that. One is using scan-build command, which works fine for me. But I need to use the checker in another way, which is from the official website, like:

               clang -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format not recognized. It seems like the xxx.o file never being generated using this command line. 

When I added -cc1 option, using it like this way,

                clang -cc1 -analyze -analyzer-checker=xxx test.c

The error is gone, but I have to include all the default compiler headers manually, which I don't wanna do.

My question is, what's the right way to pass the checker to clang to get the bug report and the built file at the same time?

Thanks,
Ying


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


-- 
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
Thank you Aleksei, it worked to run the checkers.

It seems like clang can't run the checker and do the compiling at the same time, meaning in one cmd? Just passing the -analyze option and allowing clang to compile the file will report ld error like I said before. Is that ture? 

Best,
Yingtong

--
Ph.D
Computer Science Department
University of California, Irvine

On Tue, Feb 6, 2018 at 1:34 AM, Aleksei Sidorin <[hidden email]> wrote:
Hello,

It looks like clang is thinking that he has to compile the file because the default behaviour was not changed via cmdline options. Could you try:

clang --analyze -Xclang -analyzer-checker=checker_name test.c

? --analyze will tell clang that he doesn't need to produce binary, only to analyze the file.


06.02.2018 04:24, Yingtong Liu via cfe-dev пишет:
Hi,

I am trying to use clang static checker from command line. I knew there are two ways to do that. One is using scan-build command, which works fine for me. But I need to use the checker in another way, which is from the official website, like:

               clang -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format not recognized. It seems like the xxx.o file never being generated using this command line. 

When I added -cc1 option, using it like this way,

                clang -cc1 -analyze -analyzer-checker=xxx test.c

The error is gone, but I have to include all the default compiler headers manually, which I don't wanna do.

My question is, what's the right way to pass the checker to clang to get the bug report and the built file at the same time?

Thanks,
Ying


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


-- 
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
That's right, you cannot analyze and compile in a single clang instance.
I don't remember why it was designed this way, but i don't think anybody
is planning to fix it.

* It'd be much more scary to work on the analyzer if we had a chance to
cause code generation failures after our work is done, or if you'd be
unable to compile without tweaking your build system when the analyzer
is crashing.
* In particular, we're sometimes enjoying the ability to modify the AST
(eg. do the "body farms" thing).
* We have the fancy __clang_analyzer__ macro that hides code from the
analyzer without affecting compilation.
* Very often the project is compiled with a different compiler anyway.
* Anyway, compilation time is usually very small compared to analysis
time, so doing two compilations is not going to make things much slower.

On 06/02/2018 9:55 AM, Yingtong Liu via cfe-dev wrote:

> Thank you Aleksei, it worked to run the checkers.
>
> It seems like clang can't run the checker and do the compiling at the
> same time, meaning in one cmd? Just passing the -analyze option and
> allowing clang to compile the file will report ld error like I said
> before. Is that ture?
>
> Best,
> Yingtong
>
> --
> Ph.D
> Computer Science Department
> University of California, Irvine
>
> On Tue, Feb 6, 2018 at 1:34 AM, Aleksei Sidorin <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hello,
>
>     It looks like clang is thinking that he has to compile the file
>     because the default behaviour was not changed via cmdline options.
>     Could you try:
>
>     clang --analyze -Xclang -analyzer-checker=checker_name test.c
>
>     ? --analyze will tell clang that he doesn't need to produce
>     binary, only to analyze the file.
>
>
>     06.02.2018 04:24, Yingtong Liu via cfe-dev пишет:
>>     Hi,
>>
>>     I am trying to use clang static checker from command line. I knew
>>     there are two ways to do that. One is using scan-build command,
>>     which works fine for me. But I need to use the checker in another
>>     way, which is from the official website, like:
>>
>>                    clang -Xclang -analyze -Xclang
>>     -analyzer-checker=checker_name test.c
>>
>>     This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format
>>     not recognized. It seems like the xxx.o file never being
>>     generated using this command line.
>>
>>     When I added -cc1 option, using it like this way,
>>
>>                     clang -cc1 -analyze -analyzer-checker=xxx test.c
>>
>>     The error is gone, but I have to include all the default compiler
>>     headers manually, which I don't wanna do.
>>
>>     My question is, what's the right way to pass the checker to clang
>>     to get the bug report and the built file at the same time?
>>
>>     Thanks,
>>     Ying
>>
>>
>>     _______________________________________________
>>     cfe-dev mailing list
>>     [hidden email] <mailto:[hidden email]>
>>     http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>     <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>
>
>     --
>     Best regards,
>     Aleksei Sidorin,
>     SRR, Samsung Electronics
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
Hi Artem,

Thank you for your explaination. It makes sense. 

Best,
Yingtong

On Tue, Feb 6, 2018 at 1:03 PM, Artem Dergachev <[hidden email]> wrote:
That's right, you cannot analyze and compile in a single clang instance. I don't remember why it was designed this way, but i don't think anybody is planning to fix it.

* It'd be much more scary to work on the analyzer if we had a chance to cause code generation failures after our work is done, or if you'd be unable to compile without tweaking your build system when the analyzer is crashing.
* In particular, we're sometimes enjoying the ability to modify the AST (eg. do the "body farms" thing).
* We have the fancy __clang_analyzer__ macro that hides code from the analyzer without affecting compilation.
* Very often the project is compiled with a different compiler anyway.
* Anyway, compilation time is usually very small compared to analysis time, so doing two compilations is not going to make things much slower.

On 06/02/2018 9:55 AM, Yingtong Liu via cfe-dev wrote:
Thank you Aleksei, it worked to run the checkers.

It seems like clang can't run the checker and do the compiling at the same time, meaning in one cmd? Just passing the -analyze option and allowing clang to compile the file will report ld error like I said before. Is that ture?

Best,
Yingtong

--
Ph.D
Computer Science Department
University of California, Irvine

On Tue, Feb 6, 2018 at 1:34 AM, Aleksei Sidorin <[hidden email] <mailto:[hidden email]>> wrote:

    Hello,

    It looks like clang is thinking that he has to compile the file
    because the default behaviour was not changed via cmdline options.
    Could you try:

    clang --analyze -Xclang -analyzer-checker=checker_name test.c

    ? --analyze will tell clang that he doesn't need to produce
    binary, only to analyze the file.


    06.02.2018 04:24, Yingtong Liu via cfe-dev пишет:
    Hi,

    I am trying to use clang static checker from command line. I knew
    there are two ways to do that. One is using scan-build command,
    which works fine for me. But I need to use the checker in another
    way, which is from the official website, like:

                   clang -Xclang -analyze -Xclang
    -analyzer-checker=checker_name test.c

    This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format
    not recognized. It seems like the xxx.o file never being
    generated using this command line.

    When I added -cc1 option, using it like this way,

                    clang -cc1 -analyze -analyzer-checker=xxx test.c

    The error is gone, but I have to include all the default compiler
    headers manually, which I don't wanna do.

    My question is, what's the right way to pass the checker to clang
    to get the bug report and the built file at the same time?

    Thanks,
    Ying


    _______________________________________________
    cfe-dev mailing list
    [hidden email] <mailto:[hidden email]>
    http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
    <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>


    --     Best regards,
    Aleksei Sidorin,
    SRR, Samsung Electronics




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
In reply to this post by Matthieu Brucher via cfe-dev
Hi Ying,

On Feb 5, 2018, at 5:24 PM, Yingtong Liu via cfe-dev <[hidden email]> wrote:

Hi,

I am trying to use clang static checker from command line. I knew there are two ways to do that. One is using scan-build command, which works fine for me. But I need to use the checker in another way, which is from the official website, like:

               clang -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format not recognized. It seems like the xxx.o file never being generated using this command line. 

If the issue is simply invoking the linker, then you can do:

> clang -Xclang -analyze -Xclang -analyzer-checker=checker_name -fsyntax-only test.c

OR

> clang —analyze -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

(note the double dash before “analyze”)

I think both should work.


When I added -cc1 option, using it like this way,

                clang -cc1 -analyze -analyzer-checker=xxx test.c

The error is gone, but I have to include all the default compiler headers manually, which I don't wanna do.

My question is, what's the right way to pass the checker to clang to get the bug report and the built file at the same time?

Thanks,
Ying
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: ld linker error using clang analyzer checker

Matthieu Brucher via cfe-dev
Thanks George. Worked. 
On Tue, Feb 6, 2018 at 3:54 PM, George Karpenkov <[hidden email]> wrote:
Hi Ying,

On Feb 5, 2018, at 5:24 PM, Yingtong Liu via cfe-dev <[hidden email]> wrote:

Hi,

I am trying to use clang static checker from command line. I knew there are two ways to do that. One is using scan-build command, which works fine for me. But I need to use the checker in another way, which is from the official website, like:

               clang -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

This reported me /usr/bin/ld: cannot find /tmp/xxx.o: File format not recognized. It seems like the xxx.o file never being generated using this command line. 

If the issue is simply invoking the linker, then you can do:

> clang -Xclang -analyze -Xclang -analyzer-checker=checker_name -fsyntax-only test.c

OR

> clang —analyze -Xclang -analyze -Xclang -analyzer-checker=checker_name test.c

(note the double dash before “analyze”)

I think both should work.


When I added -cc1 option, using it like this way,

                clang -cc1 -analyze -analyzer-checker=xxx test.c

The error is gone, but I have to include all the default compiler headers manually, which I don't wanna do.

My question is, what's the right way to pass the checker to clang to get the bug report and the built file at the same time?

Thanks,
Ying
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev