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
    
    

all-types.c (1.03 KB)

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.

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 ?

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 ?

No, here it's still -O0. However it makes no sense to compare the size
of unoptimized code.

If a reason is needed: It makes no sense, because it's not something the
maintainers care about. Small size is not -O0 is about.

You might as well compare how compressible the clang output is compared
to g++. "zip compresses clang output better than gcc, but 7z compresses
gcc output better than clang."

Arnt

Hello

I am trying to run following dejaGNU testcases on Clang compiled output.

/* Inlined inline function must have abstract DIE /
/
{ dg-do compile } /
/
{ dg-options “-O2 -gdwarf-2 -dA -fpreprocessed” } /
/
{ dg-final { scan-assembler “3.*DW_AT_inline” } } */
#1 “test.h”
inline int t()
{
}
int q()
{
t();
}

The testcase fails because, DW_AT_inline is not present in assembly output. Could anyone let me know why DW_AT_inline is not emitted ?
I am aware that Clang uses C99 mode by default.

oops. please ignore my previous mesg about DW_AT_line. I shall raise it under a seperate heading seperately.