Need Clarify of Compiler Documentation

Need Clarify of Compiler Documentation

eric s.'s picture

In the System Studio 2013 documentation, there is a reference to the Compiler Reference Guide in regards how to set up the Intel compiler for static analysis. I searched the documentation and found the following html, "Intel® C++ Compiler XE 13.1 User and Reference Guides", which has a section Using Static Analysis.

The last section (Condsideration When Using Static Analysis) states:

On Linux* OS, you must build the static library for static analysis with the Intel archive program, xiar. If you want to generate a static analysis result for the static library, you need to use xiar and supply the static analysis compiler options such as -diag-enable=sc{1|2|3} but preceded by a "q", for example, -qdiag-enable=sc3.

Not clear on what this is saying. It sort of sounds like its saying two separate things, the first being some program calleed xiar must be run, while the second and separate thing is we have an option to include the "static library" in the analysis. Is this correct?

If so, the purpose of running xiar is not clear - what does this do?

What is the consequence if we don't run xiar, and just build with the -diag_enable=sc1???

Finally, there appears to be a discrepency in the Inspector documentation and compiler reference guide. In compiler reference guide, it states to invoke the static analysis with the string such as -diag_enable sc1. Whereas, in the html document quoted above, there is an = sign between the two parameters. Which is correct?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
kevin-oleary (Intel)'s picture

 

Hi Eric,

It sounds like you have 2 questions:

1. Can Inpspector XE 2013 do an interprocess race analysis? The answer to this question is No. The thread checking portion of Inspector is working on the threads within your process.

I'll have to get back to you regarding your question on static analysis. I'll find out and get back back to you as soon as I can.

Regards,

Kevin

 

 

sukruth-v (Intel)'s picture

Hi Eric,

             Regarding the static analysis and inspector usage for Static analysis :- So "Xiar" is an wrapper from intel on top of the native "ar" for creating static lib archives. "-diag-enable=sc<n>" is an option which can be used with "Xiar" alone to create the static profile information for the static library that you create.

Please see the below sample as how to work with this :-

root@bga1-dpd-ubuntu01:/home/sukruth/Office/ISS/Issues# xiar rcs -qdiag-enable=sc2 libstatic.a sample.o
xiar: executing 'ar'
xiar: remark #10336: Static analysis complete; results available in "./r001sc/r001sc.inspxe"

Here i am creating the static library "libstatic.a" using the obj file "sample.o". So i am using "xiar" instead of "ar" [native] archive tool. The reason for using the "xiar" wrapper is because the native "ar" cannot understand some intel specific options like "-diag-enable=sc<n>" option.

So we have to use xiar for this. Later xiar will call "ar" for further processing.

Now, The reason why we bring "Inspector for systems" is because the "diag-enable=sc<n>" option generates the result dir which can be opened only using Inspectpr tool for analyzing output.

Regards,

Sukruth H V

yang-wang (Intel)'s picture

Hi Eric,
As mentioned in the documentation, the static analysis results are generated at the link step. That means, when we compile the .c file to .o file, the static analysis result is actually not generated. For example, for my test.c file:
icc test.c -diag-enable sc3 -c -o test.o --> the static analysis result is not generated in this step because the linker is not invoked here. (note the -c option)
icc test.c -diag-enable sc3 --> the static analysis result will be generated since the "-c" option is not specified and the linker will be invoked.
The static analysis is based on the IPO(Interprocedural Optimization) in icc compiler. That means the analysis can be done among the multiple files. So we can do the static analysis cross the files of the project. For example, if we have multiple files, file1.c and file2.c, we can use the following command to generate one report:
icc file1.c -diag-enable sc3 -c -o file1.o
icc file2.c -diag-enable sc3 -c -o file2.o
icc file1.o file2.o -diag-enable sc3 -o a.out --> in this step, the static analysis report will be generated, you will find a folder such as r000sc in the current directory which contains the report. The analysis is cross file1 and file2. The linker is invoked in this step thus we can get the report.

In some cases, typically when you already have your Makefile for your project, you may use "ar" to generate a static library. For example:
ar rcs mylib.a file1.o file2.o
In this case, in order to generate the static report, we should replace "ar" with "xiar", plus the static analysis option, e.g.:
xiar rcs mylib.a file1.o file2.o -qdiag-enable=sc3
the static analysis report will be geneated in the above step. Please note that the option is preceded by a "q", -qdiag-enable, and must use "=" after the option: -qdiag-enable=sc3.
Similarly, if you use "ld" for your linking stage, you should change it to "xild" when using icc compiler.
"xiar" and "xild" are the drivers from icc compiler. They are working as a wrapper for gnu "ar" and "ld".

In your project Makefile (or from environment variable), if you change "gcc" to "icc", "ar" to "xiar", "ld" to "xild", mostlikely you are able to build with icc compiler.
Then you just need to add "-diag-enable sc3" option for CFLAGS which pass to icc, add "-qdiag-enable=sc3" option which pass to "xiar" or "xild", then you should able to get the static analyis report.
Hope this helps.
Thanks.
-Yang

yang-wang (Intel)'s picture

By the way, you are right that the document has some problems. The option pass to icc compiler is "-diag-enable xx" without "=", and the option pass to "xiar" should have "=": "-qdiag-enable=xx".
I will report this to the documentation team for fix.
thank you.

-Yang 

Login to leave a comment.