1748239 Members
3784 Online
108759 Solutions
New Discussion юеВ

assembly listing from cc

 
unconsoled
New Member

assembly listing from cc

Is there a way to generate an assembler listing with embedded C source code from the hp-ux cc compiler, similar to using the -Wa,alh options to gcc? (Input to compiler is a C file).
5 REPLIES 5
Sandman!
Honored Contributor

Re: assembly listing from cc

Not sure if the ANSI C compiler can do that but you can certainly use gdb to get the assembly listing for each of the functions in your source code.

~cheers
Sandman!
Honored Contributor

Re: assembly listing from cc

As a follow-up to my last post you can get the assembly source listing from the ANSI C compiler as long as you provide the "-S" option on the command line to the C compiler. For ex. if you have a C source code file named "myprog.c" then compile as below:

# cc -S myprog.c

the above command will create an assembly language listing of your C source code in a file that ends with the ".s" suffix. Check for a file named "myprog.s" in the dir where "myprog.c" is located.

~hope it helps
unconsoled
New Member

Re: assembly listing from cc

Thanks for your replies. I had previously generated both the .s file using -S and a disassembly from the executable using gdb disassem func. What I was trying to avoid (although have now largely done) was the laborious process of trying to match the assembler to the 'C' code, which can be particularly time consuming when compiling with high levels of optimization (which I am). The gcc compiler will do this for you using the -Wa,alh flags, but it seems the hp ansi c compiler (cc) will not (or at least I haven't managed to find a way of making it). It does seem possible to do so to some degree if optimization is turned off but then the assembler no longer matches my executable, which defeats the point.
A. Clay Stephenson
Acclaimed Contributor

Re: assembly listing from cc

About as close as your are going to get is
cc -g -S myfile.c to include the debugger data in the .s file. That will give you source file line numbers as comments in the assembly source but the "gotcha" is that -g turns off optimization.
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: assembly listing from cc

As mentioned by Sandman, -S is the option. Note this output is for informational purposes only and you can't expect to assemble it or change and reassemble it.

What is the reason you want to see the C code mapping?

>Clay: About as close as your are going to get is: cc -g -S myfile.c

You can use -g +O2 -S and still get those line numbers. But you can't do it with +O3 or +O4 on PA.