Good God KK, put on your big boy pants. Do you really think the boys in JP will give Faulkner the boot? Maybe you have visions of a three guitar band (AKA Iron Maiden)? Not gonna happen. You sound like a little girl complaining that she can't participate in a tea party. Someone take your Barbie? 0 allen_pagent 10 · Oct 18, 2021 04:36 PM · report · ↑reply
@damienmg this is caused by gcc 6 on debian which enable -pie by default (whether you pass -pie or not). This is different then gcc-5 behavior. To fix this we need to pass -no-pie explicitly or stop using -r.
I believe I figured it out. As part of the GCC 6 release notes, they mention a new gcc compile time option --enable-default-pie which enables pie by default. Apparently it's a more secure default.
Passing -no-pie to the failing GCC command fixes this issue so I suspect the gcc binary shipped with stretch was compiled with --enable-default-pie.
Name:
Anonymous2024-12-10 14:45
gcc main.c -o main -no-pie
Name:
Anonymous2024-12-10 14:45
Difference between "-fno-pie" and "-no-pie" Asked 2 years, 1 month ago Modified 1 year, 7 months ago Viewed 4k times 6
I don't find any useful information on the differences between "-fno-pie" and "-no-pie". Are they gcc flags or ld flags? Are they both necessary or not?
I found a piece of makefile that uses these lines:
CC = @gcc -fno-pie -no-pie LD = @gcc -fno-pie -no-pie
So it uses gcc for linking instead of a direct call to ld but I don't understand the differences between the flags and if they are both necessary to compiling and linking stage
gccldcompiler-flagslinker-flags
Share Improve this question Follow asked Nov 3, 2022 at 8:42 Francesco's user avatar Francesco 64066 silver badges2929 bronze badges Add a comment 1 Answer Sorted by: 5
TLDR; -fno-pie is a "code generation option" while -no-pie is a "linker option". You need both.
-fno-pie tell GCC that you don't want to make a PIE. If you are not making a PIE you are making either a shared object (using -shared) or an ordinary executable. Ordinary executables are loaded below the 4GiB and at a fixed address, furthermore their symbols cannot be interposed so -fno-pie tell GCC that can translate an expression like &foo in something like mov eax, OFFSET FLAT foo. It doesn't have to use the GOT since the symbols are not interposed and it doesn't have to use RIP-relative addressing since a 32-bit address fits in the 32-bit immediate/displacement of x86-64 instructions.
Check out what -fpie/-fno-pie do in terms of assembly instructions.
An instruction like mov eax, OFFSET FLAT foo creates a R_X86_64_32 relocation, this relocation is used in 64-bit programs when the compiler is sure that an address will always fit 32 bits (i.e. is below 4GiB). However -fno-pie doesn't stop GCC from passing -pie to the linker. So the linker sees a R_X86_64_32 relocation and is still instructed to make a PIE executable. The relocation promises that the address will be below 4GiB but the -pie flag promises that the executable is meant to be loaded anywhere, including above 4GiB. These contrast each other and the linker is required to check this stalemate and produce an error.
To tell the linker that indeed you did not want to link a PIE executable, you need to pass -no-pie to GCC.
You can pass -v to GCC while compiling a file to see what options are passed to collect2 (a wrapper to the linker). Regardless of the presence of -fno-pie, -pie is still passed to collect2. Adding -no-pie to GCC will suppress -pie in the collect2 command line.
Note: Older distributions built GCC without defaulting to -fpie -pie. Share Improve this answer Follow edited May 6, 2023 at 15:33 answered Apr 13, 2023 at 18:39 Margaret Bloom's user avatar Margaret Bloom 43.9k55 gold badges8787 silver badges128128 bronze badges
It might be more clear to say that -fpie is a "code generation option" (like most -f options are), and -pie is a "linking option" (does not affect generated assembly, just passed through by the compiler driver to the linker). – amonakov Commented May 5, 2023 at 13:02 Based on TLDR; what I need is CC = @gcc -fno-pie and LD = @gcc -no-pie, isn't it? So I don't need both in the 2 script lines – Francesco Commented Aug 30, 2023 at 6:34