Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22001

MWE among object file compiled with and without `-fPIC`

$
0
0

I was doing some experiment with object file produced by gcc.

While I know, at least superficially, what is the use of position independent code, I was trying to spot it concretely.

I produced this simple code in a file timestwo.c:

 int timestwo(int x) {     return 2 * x; }

which I compiled:

  • gcc -c timestwo.c
  • gcc -c -fPIC timestwo.c -o timestwo_pic.o

then the resulting object files timestwo.o and timestwo_pic.o are bitwise the same. Also with readelf -a I cannot spot any difference.

Can you provide a MWE in which i can see the difference between pic and non-pic code?


Viewing all articles
Browse latest Browse all 22001

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>