anonymous
2012-Feb-16 10:43 UTC
[LLVMdev] difference in function prologue generated with clang and gcc
1.
I would like to know why there is a difference in function prologue
generated for same function with clang and gcc.
Compiler options used for gcc were as follows:
arm-linux-gnueabi-gcc all-types.c -w -march=armv7-a
-mtune=cortex-a8 -mfloat-abi=softfp -mfpu=vfp -g -lm -o all-types_gcc
Compiler options used for clang were as follows:
/usr/local/bin/clang all-types.c -w -ccc-gcc-name
arm-linux-gnueabi-gcc -ccc-host-triple arm-linux-gnueabi
-ccc-clang-archs arm -march=armv7-a -mtune=cortex-a8
-mfloat-abi=softfp -mfpu=vfp -g -lm -o all-types
Dissassembly of main() from all-types.c compiled with GCC.
00008448 <main>:
float v_float;
double v_double;
int main ()
{
8448: e92d4800 push {fp, lr}
844c: e28db004 add fp, sp, #4
extern void dummy();
#ifdef usestubs
set_debug_traps();
breakpoint();
#endif
dummy();
8450: eb000002 bl 8460 <dummy>
return 0;
8454: e3a03000 mov r3, #0
}
8458: e1a00003 mov r0, r3
845c: e8bd8800 pop {fp, pc}
00008460 <dummy>:
void dummy()
{
8460: e52db004 push {fp} ; (str fp,
[sp, #-4]!)
8464: e28db000 add fp, sp, #0
/* Some linkers (e.g. on AIX) remove unreferenced variables,
so make sure to reference them. */
v_char = 'A';
Raw dump of debug contents of section .debug_line:
Offset: 0x0
Length: 74
*DWARF Version: 2
* Prologue Length: 34
Minimum Instruction Length: 2
Initial value of 'is_stmt': 1
Line Base: -5
Line Range: 14
Opcode Base: 13
###################################################################################################################################
Dissassembly of main() from all-types.c compiled with CLANG.
00008444 <main>:
float v_float;
double v_double;
int main ()
{
8444: e92d4800 push {fp, lr}
8448: e1a0b00d mov fp, sp
844c: e24dd008 sub sp, sp, #8
8450: e3a00000 mov r0, #0
8454: e58d0004 str r0, [sp, #4]
extern void dummy();
#ifdef usestubs
set_debug_traps();
breakpoint();
#endif
dummy();
8458: e58d0000 str r0, [sp]
845c: eb000002 bl 846c <dummy>
return 0;
8460: e59d0000 ldr r0, [sp]
8464: e1a0d00b mov sp, fp
8468: e8bd8800 pop {fp, pc}
0000846c <dummy>:
}
void dummy()
{
846c: e3a00006 mov r0, #6
/* Some linkers (e.g. on AIX) remove unreferenced variables,
so make sure to reference them. */
v_char = 'A';
Raw dump of debug contents of section .debug_line:
Offset: 0x0
Length: 206
* DWARF Version: 2
* Prologue Length: 157
Minimum Instruction Length: 2
Initial value of 'is_stmt': 1
Line Base: -5
Line Range: 14
Opcode Base: 13
The prologue length in .debug_line is 157 for clang generated one,
whereas it is 34 for gcc generated one. I am curious about the results
of making prologue generated by clang look similar with one generated
by gcc.
Could anyone let me know why this difference exists and if it is
for good /better purposes than for gcc. ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120216/fd0b3a3a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: all-types.c
Type: text/x-csrc
Size: 1056 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120216/fd0b3a3a/attachment.c>
Anton Korobeynikov
2012-Feb-16 13:22 UTC
[LLVMdev] difference in function prologue generated with clang and gcc
Hello> The prologue length in .debug_line is 157 for clang generated one, whereas > it is 34 for gcc generated one. I am curious about the results of making > prologue generated by clang look similar with one generated by gcc. > Could anyone let me know why this difference exists and if it is for good > /better purposes than for gcc. ?1. This is not function prologue length. It's the header (aka 'prologue') length of .debug_line section 2. The length of function prologue is 3 instructions in case of clang (12 bytes) and 2 instruction (8 bytes) in case of gcc 3. Comparison of code size of unoptimized code does not make any sense. Hope this makes the stuff clear. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
anonymous
2012-Feb-16 18:39 UTC
[LLVMdev] difference in function prologue generated with clang and gcc
Hello Anton, Thanks for the reply. I have not specified optimization level explicitly during compilation. For GCC default is O0 ie., no optimization. Do you mean that clang uses other optimization level other than O0 ? Could you please clarify ? On Thu, Feb 16, 2012 at 6:52 PM, Anton Korobeynikov <anton at korobeynikov.info> wrote:> Hello > > > The prologue length in .debug_line is 157 for clang generated one, > whereas > > it is 34 for gcc generated one. I am curious about the results of making > > prologue generated by clang look similar with one generated by gcc. > > Could anyone let me know why this difference exists and if it is for good > > /better purposes than for gcc. ? > 1. This is not function prologue length. It's the header (aka > 'prologue') length of .debug_line section > 2. The length of function prologue is 3 instructions in case of clang > (12 bytes) and 2 instruction (8 bytes) in case of gcc > 3. Comparison of code size of unoptimized code does not make any sense. > > Hope this makes the stuff clear. > > -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120217/ac6e3b63/attachment.html>
Seemingly Similar Threads
- [LLVMdev] difference in function prologue generated with clang and gcc
- [LLVMdev] DW_AT_inline not present in assembly for an inlined inline function
- [LLVMdev] difference in function prologue generated with clang and gcc
- [LLVMdev] difference in function prologue generated with clang and gcc
- [LLVMdev] difference in function prologue generated with clang and gcc