This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR ld/16428: Disallow -shared/-pie, -shared/-static, -pie/-static


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]