https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117992
--- Comment #13 from Xi Ruoyao <xry111 at gcc dot gnu.org> --- Some messy things: - Among -r, -pie, -no-pie, -static-pie, and -shared, only the last one specified is effective. (I.e. -r -pie -no-pie -static-pie -shared -pie is just -pie). - But -static is different and much more messy: - Both "-static -no-pie" and "-static -pie" are just -static - "-static -r" is just -r - "-static -static-pie" and "-static -shared" produce static PIE or shared library (so they are not same as just -static), but I get "/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a (PIE|shared) object". (So these combinations seems just not working unless -nostdlib???) To me we should really try to make things less messy. But it has to wait for stage 1. For now, with -fhardened -Whardened: - If -r is effective, we shouldn't pass the link hardening option and we shouldn't warn. - Otherwise, if either -static-pie or -shared is effective, we should pass -z relro -z now and we shouldn't warn. - Otherwise, if -static, or -no-pie is effective, we should pass -z relro -z now, and warn about lacking ASLR. - Otherwise, we should pass -z relro -z now, enable -pie (if not enabled yet), and not warn. One remaining question: is -z now meaningful for static executable and static PIE? Should we leave it out for static executable and static PIE?