On Thu, 2021-04-22 at 10:17 -0500, Peng Yu via Gcc-help wrote: > Hi, > > As written on Wikipedia, PIC and PIE seems to be synonymous. > > "In computing, position-independent code[1] (PIC[1]) or > position-independent executable (PIE)[2] is ..." > > https://dev.gentoo.org/~vapier/crt.txt > > But according to the above page, they seem to be different. Could > anybody explain what is the difference between them? > -fPIE generates code for position-independent executable (i. e., "main" program), -fPIC generates code for shared libraries. Use -fPIE for libraries breaks semantic interposition (some programs require it, and it's also very useful in debugging). Using -fPIC for an executable makes the compiler *lose* some opportunities to optimize the code (some optimizations are perfectly well for main program, but breaking semantic interposition in libraries). I have some code showing the semantic interposition breakage by misusing -fPIE for a lib: https://linux.xidian.edu.cn/git/xry111/pie_vs_pic -- Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University