Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is -no-pie used for?

I was working on Ubuntu 17.10 with GPROF for some testing with C files, and when I execute with gprof the file generated (gmon.out), compiling and linking with -pg option, I got an empty flat and call graph.

However, I found that this is a GCC bug, and I would have to compile and link the file with -no-pie option.

  • Compile:

    gcc -c main.c file-1.c file-2.c -pg [-no-pie]
    
  • Link:

    gcc -o test main.o file-1.o file-2.o -pg [-no-pie]
    

I have the GCC 7.2 version.

How does this option work and why the graphs are empty if I don't use that option?

like image 419
SGodoy Avatar asked Dec 12 '17 17:12

SGodoy


1 Answers

That flag is telling gcc not to make a position independent executable (PIE). PIE is a precodition to enable address space layout randomization (ASLR). ASLR is a security feature where the kernel loads the binary and dependencies into a random location of virtual memory each time it's run.

like image 188
Paul Avatar answered Sep 21 '22 15:09

Paul