[LLVMdev] Transition C->bitcode->assembly->object looses frame pointers

Alexander Potapenko ramosian.glider at gmail.com
Tue Apr 5 06:01:13 PDT 2011


Below is an example of using backtrace() obtained from man backtrace
and the test results:

 $ gcc bt.c -o bt-gcc
 $ ./bt-gcc 4
backtrace() returned 4 addresses
./bt-gcc() [0x4007e3]
./bt-gcc() [0x400874]
./bt-gcc() [0x40089b]
./bt-gcc() [0x400894]

 $ llvm-gcc bt.c -o bt-llvm-gcc
 $ ./bt-llvm-gcc 4
backtrace() returned 4 addresses
./bt-llvm-gcc() [0x40074b]
./bt-llvm-gcc() [0x400809]
./bt-llvm-gcc() [0x400837]
./bt-llvm-gcc() [0x400830]

 $ llvm-gcc -fno-omit-frame-pointer -g bt.c -emit-llvm -S -o bt.ll
 $ llc --disable-fp-elim bt.ll -o bt.S
 $ gcc -fno-omit-frame-pointer bt.S -o bt-llc
 $ ./bt-llc 4
backtrace() returned 1 addresses
./bt-llc() [0x4007f0]

 $ cat bt.c
       #include <execinfo.h>
       #include <stdio.h>
       #include <stdlib.h>
       #include <unistd.h>

       void
       myfunc3(void)
       {
           int j, nptrs;
       #define SIZE 100
           void *buffer[100];
           char **strings;

           nptrs = backtrace(buffer, SIZE);
           printf("backtrace() returned %d addresses\n", nptrs);

           /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
              would produce similar output to the following: */

           strings = backtrace_symbols(buffer, nptrs);
           if (strings == NULL) {
               perror("backtrace_symbols");
               exit(EXIT_FAILURE);
           }

           for (j = 0; j < nptrs; j++)
               printf("%s\n", strings[j]);

           free(strings);
       }

       static void   /* "static" means don't export the symbol... */
       myfunc2(void)
       {
           myfunc3();
       }

       void
       myfunc(int ncalls)
       {
           if (ncalls > 1)
               myfunc(ncalls - 1);
           else
               myfunc2();
       }

       int
       main(int argc, char *argv[])
       {
           if (argc != 2) {
               fprintf(stderr, "%s num-calls\n", argv[0]);
               exit(EXIT_FAILURE);
           }

           myfunc(atoi(argv[1]));
           exit(EXIT_SUCCESS);
       }


On Tue, Apr 5, 2011 at 4:49 PM, Alexander Potapenko
<ramosian.glider at gmail.com> wrote:
> Hi James,
>
> We've indeed passed the appropriate (and even excessive) flags to the
> appropriate pipeline parts, that is:
>
>  llvm-gcc -O1 -fno-omit-frame-pointers -g $in -emit-llvm -S -o $name.ll
>  llc --disable-fp-elim $name.ll -o $name.S
>  g++ -fno-omit-frame-pointers -c $name.S
>
> , but that didn't work
>
> Alex
>
> On Tue, Apr 5, 2011 at 4:40 PM, James Molloy <James.Molloy at arm.com> wrote:
>> Hi,
>>
>> The -disable-fp-elim flag must be passed to the part of the compilation process that actually performs that optimisation pass - when you run clang/llvm-gcc in one invocation, obviously it will just be that invocation, but in your first case it would be the llc command. That is where the IR gets lowered, so is where the FP elimination takes place.
>>
>> Pass flags are not, as far as I'm aware, propagated in generated bitcode files - the same flags need to be given to each part of the pipeline.
>>
>> Hope this helps,
>>
>> James
>>
>




More information about the llvm-dev mailing list