This is the mail archive of the
mailing list for the GCC project.
Re: Adding static-PIE support to binutils
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Rich Felker <dalias at libc dot org>
- Cc: Binutils <binutils at sourceware dot org>, gcc at gcc dot gnu dot org
- Date: Mon, 17 Aug 2015 22:29:41 -0700
- Subject: Re: Adding static-PIE support to binutils
- Authentication-results: sourceware.org; auth=none
- References: <20150624041847 dot GA26414 at brightrain dot aerifal dot cx>
> So far, I've been prototyping static PIE support by having GCC pass
> the following options to ld instead of -static -pie:
> -static -shared -Bsymbolic
> This partly works, but since ld does not know it's producing a main
> executable, it misses important details, including the ability to link
> initial-exec and local-exec model TLS code correctly, as well as
> various linking optimizations. So I think the right way forward is
> making ld accept -static and -pie together to do the right thing.
For the uses you have in mind, -static and -pie together make perfect
sense, but I'd argue that the output file in that case ought to be
ET_EXEC, since it will be in fact a standalone binary to be loaded
directly by the kernel. Not only would you want to omit the .interp
section (actually the PT_INTERP segment), but you also have no need
for the PT_DYNAMIC segment (.dynamic section).
The only thing you need over a standard ET_EXEC file is the dynamic
relocations, with linker-generated symbols bracketing the start and
end of the relocations so that your custom startup code can find them.
It should be reasonably easy to arrange for these.