[RESEND PATCH] Makeconfig: Set pie-ccflag to -fPIE by default
Fangrui Song
maskray@google.com
Tue Sep 20 22:02:33 GMT 2022
On 2022-09-20, Wilco Dijkstra wrote:
>Hi Florian,
>
>>> Well if changing the default of fPIC is unacceptable in GCC, adding a
>>> new option should help LLVM too since it could imply more than
>>> -fno-semantic-interposition. A key question is whether we could
>>> require that exported symbols are marked explicitly so that we only
>>> emit GOT and PLT indirections on such exported symbols.
>>
>> -flto with a linker plugin already covers this. I don't think we need
>> anything else. Maybe an LTO mode that only deals with visibility, but
>> otherwise does little cross-TU optimization?
clang -flto={full,thin} respect -fsemantic-interposition.
If -fsemantic-interposition is specified, it disables interprocedural
optimizations (including inlining) for default visibility non-vague external linkage functions.
(
-Ofast unfortunately implies -ffast-math and does crtfastmath.o.
)
Piggybacking -fno-semantic-interposition on -Ofast
>Well it would be great if LTO solved this problem, but unfortunately it can't...
>LTO tells you which symbols are locally defined, but this doesn't help PIC.
>Local definitions with default visibility must still indirect via the GOT/PLT,
>similarly interprocedural optimizations are still blocked.
>
>A LTO-lite option that just deals with visibility and global variable optimization
>(eg. better use of anchors) and other cheap optimizations seems useful indeed.
>
>Cheers,
>Wilco
-fno-semantic-interposition should be sufficient. I think we don't need
another option. We should just the few software to use -fsemantic-interposition so that
the world can be changed.
FreeBSD and quite a few musl-based Linux distributions use Clang as the
system compiler and have verified that -fno-semantic-interposition-like
default (allow interprocedural optimizations for default visibility
non-vague external linkage functions.
I think folks can give
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100937 another request.
Even if the upstream doesn't take it, changing a distro's own spec file
to default to -fno-semantic-interposition isn't that difficult.
Many Linux distributions customize their GCC to do some stuff by default
anyway.
More information about the Libc-alpha
mailing list