This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Cary Coutant <ccoutant at google dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Tue, 14 Jan 2014 11:14:00 -0800
- Subject: Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Authentication-results: sourceware.org; auth=none
- References: <20140110142001 dot GA6035 at intel dot com> <20140111001259 dot GE5390 at bubble dot grove dot modra dot org> <CAMe9rOo0UtpbdT69cnkK4fZD5pmzQnuX2wMCkBy3GuSLGcmcow at mail dot gmail dot com> <CAHACq4opdALo+T=dvM_PT2M36H+feAqpF6Gsf0sPZy-g=bg8SA at mail dot gmail dot com> <20140114003945 dot GM5390 at bubble dot grove dot modra dot org> <CAHACq4oq4KjUqc8GTgA6onRBQBxyvfxDcQn6OmCC7mrRu04_Aw at mail dot gmail dot com>
On Tue, Jan 14, 2014 at 10:35 AM, Cary Coutant <ccoutant@google.com> wrote:
>
>> I see no reason why "-static -pie" should not work. "-static" does
>> *not* specify the type of output directly. "-static" chooses input
>> objects. "-pie" affects output. The two options are logically
>> orthogonal. You ought to be able to build a PIE that doesn't use any
>> shared libraries! If it doesn't work, then we have a bug elsewhere.
>
> Well, in gold, -Bstatic -pie is fine -- that asks to build a PIE with
> just archive libraries, but the output is still going to be an ET_DYN.
> In practice, at least in the ELF world, PIE binaries are dynamic even
> if they have no dependencies on shared libraries.
"-static -pie" may work with linker. But it doesn't work with
GCC driver:
*link:
%{!static:--eh-frame-hdr} %{!mandroid|tno-android-ld:%{m32|mx32:;:-m
elf_x86_64} %{m32:-m elf_i386}
%{mx32:-m elf32_x86_64} %{shared:-shared} %{!shared:
%{!static: %{rdynamic:-export-dynamic}
%{m32:-dynamic-linker
%{muclibc:/lib/ld-uClibc.so.0;:%{mbionic:/system/bin/linker;:/lib/ld-linux.so.2}}}
%{m32|mx32:;:-dynamic-linker
%{muclibc:/lib/ld64-uClibc.so.0;:%{mbionic:/system/bin/linker64;:/lib64/ld-linux-x86-64.so.2}}}
%{mx32:-dynamic-linker
%{muclibc:/lib/ldx32-uClibc.so.0;:%{mbionic:/system/bin/linkerx32;:/libx32/ld-linux-x32.so.2}}}}
%{static:-static}};:%{m32|mx32:;:-m elf_x86_64}
%{m32:-m elf_i386} %{mx32:-m elf32_x86_64}
%{shared:-shared} %{!shared: %{!static:
%{rdynamic:-export-dynamic} %{m32:-dynamic-linker
%{muclibc:/lib/ld-uClibc.so.0;:%{mbionic:/system/bin/linker;:/lib/ld-linux.so.2}}}
%{m32|mx32:;:-dynamic-linker
%{muclibc:/lib/ld64-uClibc.so.0;:%{mbionic:/system/bin/linker64;:/lib64/ld-linux-x86-64.so.2}}}
%{mx32:-dynamic-linker
%{muclibc:/lib/ldx32-uClibc.so.0;:%{mbionic:/system/bin/linkerx32;:/libx32/ld-linux-x32.so.2}}}}
%{static:-static}} %{shared: -Bsymbolic}}
When there is -static, -dynamic-linker won't passed to ld. -static,
-shared, -pie should be mutually exclusive for GCC driver.
> Based on what you've said, I'm inclined to agree with you about Gnu
> ld, though. As long as ld doesn't get into any internal inconsistency
> if given seemingly conflicting options (e.g., if "-static -dynamic"
> always means "-dynamic"), there seems to be little reason to add the
> checking. I guess it's a matter of whether that's more likely to be a
> mistake that needs a diagnostic, or a convenience where LDFLAGS can
> override a setting hardcoded into the Makefile.
I checked in a patch to avoid bfd linker crash.
--
H.J.
- References:
- PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static
- Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static