public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Cross compiled GCC wrongly builds dynamic executables
@ 2016-08-19 20:36 Alastair Hughes
  2016-08-19 20:48 ` H.J. Lu
  0 siblings, 1 reply; 6+ messages in thread
From: Alastair Hughes @ 2016-08-19 20:36 UTC (permalink / raw)
  To: gcc-help; +Cc: hjl.tools

Hi all!

I am cross compiling GCC to produce a compiler to run on the target machine (ie --build="${_local_triplet}" --host="${_target_triplet}" --target="${_target_triplet}"). The target system is a simple *statically linked* musl-libc based system.
After a recent upgrade to binutils 2.27, the cross compiled cc1 and cc1plus executables where generated as *dynamically linked*, due to a combination of the -rdynamic flag to GCC during the build, and a recent change in binutils (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bf89386a862ace008f0152bca8bddf996d3993c8, https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=9c1d7a087682074d585253ad38719ec2363eb2b7 - the first commit being problematic).

I am unsure as to whether this is an issue with the GCC build, something that I have configured, or a bug in binutils. Why is -rdynamic being passed when building cc1 and cc1plus? Is that what should be happening, a bug, or a problem with how I have configured GCC?

I've also CC'd the committer in case he can explain.

Regards,
Alastair Hughes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cross compiled GCC wrongly builds dynamic executables
  2016-08-19 20:36 Cross compiled GCC wrongly builds dynamic executables Alastair Hughes
@ 2016-08-19 20:48 ` H.J. Lu
  2016-08-20  7:46   ` Alastair Hughes
  0 siblings, 1 reply; 6+ messages in thread
From: H.J. Lu @ 2016-08-19 20:48 UTC (permalink / raw)
  To: Alastair Hughes; +Cc: gcc-help

On Fri, Aug 19, 2016 at 1:35 PM, Alastair Hughes
<hobbitalastair@yandex.com> wrote:
> Hi all!
>
> I am cross compiling GCC to produce a compiler to run on the target machine (ie --build="${_local_triplet}" --host="${_target_triplet}" --target="${_target_triplet}"). The target system is a simple *statically linked* musl-libc based system.
> After a recent upgrade to binutils 2.27, the cross compiled cc1 and cc1plus executables where generated as *dynamically linked*, due to a combination of the -rdynamic flag to GCC during the build, and a recent change in binutils (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bf89386a862ace008f0152bca8bddf996d3993c8, https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=9c1d7a087682074d585253ad38719ec2363eb2b7 - the first commit being problematic).
>
> I am unsure as to whether this is an issue with the GCC build, something that I have configured, or a bug in binutils. Why is -rdynamic being passed when building cc1 and cc1plus? Is that what should be happening, a bug, or a problem with how I have configured GCC?
>
> I've also CC'd the committer in case he can explain.
>

It is for GCC plugin.  Does your compiler support GCC plugin?
If not, you should configure your GCC with --disable-plugin.

-- 
H.J.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:Cross compiled GCC wrongly builds dynamic executables
  2016-08-19 20:48 ` H.J. Lu
@ 2016-08-20  7:46   ` Alastair Hughes
  2016-08-20 10:00     ` Cross " Andrew Haley
  2016-08-22 15:40     ` H.J. Lu
  0 siblings, 2 replies; 6+ messages in thread
From: Alastair Hughes @ 2016-08-20  7:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-help

> On Fri, Aug 19, 2016 at 1:35 PM, Alastair Hughes
> <hobbitalastair@yandex.com> wrote:
> 
>> Hi all!
>>
>> I am cross compiling GCC to produce a compiler to run on the target machine (ie --build="${_local_triplet}" --host="${_target_triplet}" --target="${_target_triplet}"). The target system is a simple *statically linked* musl-libc based system.
>> After a recent upgrade to binutils 2.27, the cross compiled cc1 and cc1plus executables where generated as *dynamically linked*, due to a combination of the -rdynamic flag to GCC during the build, and a recent change in binutils (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bf89386a862ace008f0152bca8bddf996d3993c8, https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=9c1d7a087682074d585253ad38719ec2363eb2b7 - the first commit being problematic).
>>
>> I am unsure as to whether this is an issue with the GCC build, something that I have configured, or a bug in binutils. Why is -rdynamic being passed when building cc1 and cc1plus? Is that what should be happening, a bug, or a problem with how I have configured GCC?
>>
>> I've also CC'd the committer in case he can explain.
> 
> It is for GCC plugin. Does your compiler support GCC plugin?
> If not, you should configure your GCC with --disable-plugin.
> 
> --
> H.J.

No, there is no dynamic linker on the target - your suggestion works, thanks.

I'm a bit surprised that the ld creates dynamically linked executables in the first place, since they cannot ever run at runtime (missing the dynamic loader) and there is no dynamic libraries to link against. What is the use case for that? Is there some way to stop ld from ever creating dynamically linked executables?

Alastair Hughes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cross compiled GCC wrongly builds dynamic executables
  2016-08-20  7:46   ` Alastair Hughes
@ 2016-08-20 10:00     ` Andrew Haley
  2016-08-22 15:40     ` H.J. Lu
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2016-08-20 10:00 UTC (permalink / raw)
  To: gcc-help

On 20/08/16 08:46, Alastair Hughes wrote:

> No, there is no dynamic linker on the target - your suggestion
> works, thanks.
> 
> I'm a bit surprised that the ld creates dynamically linked
> executables in the first place, since they cannot ever run at
> runtime (missing the dynamic loader) and there is no dynamic
> libraries to link against. What is the use case for that? Is there
> some way to stop ld from ever creating dynamically linked
> executables?

I'm surprised too.  ld will usually only link against dynamic
libraries which it finds at link time.

Andrew.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cross compiled GCC wrongly builds dynamic executables
  2016-08-20  7:46   ` Alastair Hughes
  2016-08-20 10:00     ` Cross " Andrew Haley
@ 2016-08-22 15:40     ` H.J. Lu
  2016-08-23 21:27       ` Alastair Hughes
  1 sibling, 1 reply; 6+ messages in thread
From: H.J. Lu @ 2016-08-22 15:40 UTC (permalink / raw)
  To: Alastair Hughes; +Cc: gcc-help

On Sat, Aug 20, 2016 at 12:46 AM, Alastair Hughes
<hobbitalastair@yandex.com> wrote:
>> On Fri, Aug 19, 2016 at 1:35 PM, Alastair Hughes
>> <hobbitalastair@yandex.com> wrote:
>>
>>> Hi all!
>>>
>>> I am cross compiling GCC to produce a compiler to run on the target machine (ie --build="${_local_triplet}" --host="${_target_triplet}" --target="${_target_triplet}"). The target system is a simple *statically linked* musl-libc based system.
>>> After a recent upgrade to binutils 2.27, the cross compiled cc1 and cc1plus executables where generated as *dynamically linked*, due to a combination of the -rdynamic flag to GCC during the build, and a recent change in binutils (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bf89386a862ace008f0152bca8bddf996d3993c8, https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=9c1d7a087682074d585253ad38719ec2363eb2b7 - the first commit being problematic).
>>>
>>> I am unsure as to whether this is an issue with the GCC build, something that I have configured, or a bug in binutils. Why is -rdynamic being passed when building cc1 and cc1plus? Is that what should be happening, a bug, or a problem with how I have configured GCC?
>>>
>>> I've also CC'd the committer in case he can explain.
>>
>> It is for GCC plugin. Does your compiler support GCC plugin?
>> If not, you should configure your GCC with --disable-plugin.
>>
>> --
>> H.J.
>
> No, there is no dynamic linker on the target - your suggestion works, thanks.
>
> I'm a bit surprised that the ld creates dynamically linked executables in the first place, since they cannot ever run at runtime (missing the dynamic loader) and there is no dynamic libraries to link against. What is the use case for that? Is there some way to stop ld from ever creating dynamically linked executables?
>
> Alastair Hughes

For Linux/x86 target, there are

#define GNU_USER_TARGET_LINK_SPEC                                  \
                  "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
                   %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
                   %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \
  %{shared:-shared} \
  %{!shared: \
    %{!static: \
      %{rdynamic:-export-dynamic} \
      %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
      %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
      %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
    %{static:-static}}"

It assumes that -static is used to create static executable, in which
case -rdynamic is ignored.  Apparently, in your case, -static isn't used
when creating static executable.  Please double check if your target
is properly supported by GCC.


-- 
H.J.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:Cross compiled GCC wrongly builds dynamic executables
  2016-08-22 15:40     ` H.J. Lu
@ 2016-08-23 21:27       ` Alastair Hughes
  0 siblings, 0 replies; 6+ messages in thread
From: Alastair Hughes @ 2016-08-23 21:27 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-help

<snip>

> It assumes that -static is used to create static executable, in which
> case -rdynamic is ignored. Apparently, in your case, -static isn't used
> when creating static executable. Please double check if your target
> is properly supported by GCC.
> 
> --
> H.J.

Right, so this is working as intended; thanks for your help!

Alastair Hughes

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-08-23 21:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-19 20:36 Cross compiled GCC wrongly builds dynamic executables Alastair Hughes
2016-08-19 20:48 ` H.J. Lu
2016-08-20  7:46   ` Alastair Hughes
2016-08-20 10:00     ` Cross " Andrew Haley
2016-08-22 15:40     ` H.J. Lu
2016-08-23 21:27       ` Alastair Hughes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).