mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Linking musl with ld.gold
Date: Wed, 7 May 2014 23:01:03 -0400	[thread overview]
Message-ID: <20140508030102.GF26358@brightrain.aerifal.cx> (raw)
In-Reply-To: <SNT146-W57DA20C05E7DE2C6A6AE3DA8490@phx.gbl>

On Thu, May 08, 2014 at 03:08:41AM +0100, Stephen Thomas wrote:
> > On Wed, May 07, 2014 at 01:04:43PM +0300, Timo Teras wrote:
> > > On Wed, 7 May 2014 10:04:24 +0100
> > > Stephen Thomas <scjthm@live.com> wrote:
> > > 
> > > > > only the object files with referenced symbols are linked from an
> > > > > archive
> > > > > 
> > > > > so only a.o with the given main.o because of the symbol f
> > > > > 
> > > > > now if you make some reference in main.c such that b.o should
> > > > > be included but main still returns 0 that would be a bug
> > > > > 
> > > > > eg. add a void g(void){} to b.c and call it from main.c  
> > > > 
> > > > Ok, thanks for that info. It appears that there is a problem in gcc
> > > > 4.9 and not 4.8.3.
> > > 
> > > Is perhaps -ffunction-sections and/or -fdata-sections added
> > > automatically? Those would break musl like experienced.
> > 
> > They should not break musl; if they do, it's a compiler bug. The
> > strong symbol that overrides the weak symbol elsewhere is not unused
> > and available for garbage collection because it's referenced.
> > 
> > I suspect your claim is just wrong, since IIRC people have
> > successfully used these options with musl.
> 
> I will raise an issue with the gcc team (but I don't really want to
> build from git, as it takes too long). I am not saying that the
> library doesn't work, I am merely saying that there was a bug where
> stdout was not being flushed, and this in my opinion was due to the
> weak symbol in fflush not being overridden. I did run that single
> test case on the two different builds and the result was different.
> This was on two clean buildroot branches based on uclibc.

My reply to Timo was not in doubt that you observed such an issue, but
rather expressing doubt about his possible explanation. I don't think
it has anything to do with -ffunction-sections or -fdata-sections.

> I don't understand what you mean by garbage collection. Basically,

Those two options are meant to be used with the linker option
--gc-sections, which performs garbage collection to remove any
sections which are not referenced.

> if I understand this correctly, there is a weak symbol defined in
> fflush.c for the purpose of allowing this file to run without the an
> implementation that initialises the real symbol with the internal
> implementation of stdout (which is just basically a manufactured
> wrapper around file descriptor number 1). This is good as far as
> unit testing goes, doesn't use #defines but the linker -- good
> stuff. However, when I noticed was that the prompt on busybox using
> musl was not appearing until after a new line was entered, I added a
> discovered that the value of the pointer was 0 (NULL). If you still
> suspect that my claim is wrong, then I believe you are saying that

I'm just saying Timo's claim about the mechanism of what you observed
is probably wrong. The way the 'magic' with weak symbols work is that
the weak definition satisfies the reference, so that the linker does
not need to pull in additional object files to satisfy it. But once an
additional file which has a strong definition is pulled in (as a
result of another undefined symbol reference), the strong definition
is _referenced_ (because it overrides any weak definitions) and thus
its section is not a legal candidate for garbage collection via
--gc-sections.

> this is not the case. It would be nice if someone who has gcc 4.9
> installed could run either run the test or check that busybox is
> working.

The bug is almost surely in the linker, not gcc, unless it's a matter
of gcc passing bad options to the linker. You can add -v to the gcc
command line for linking to see exactly how it invokes the linker.

Rich


  reply	other threads:[~2014-05-08  3:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-06  9:07 Stephen Thomas
2014-05-06 10:14 ` Szabolcs Nagy
2014-05-06 21:11   ` Stephen Thomas
2014-05-06 23:18     ` Szabolcs Nagy
2014-05-07  9:04       ` Stephen Thomas
2014-05-07 10:04         ` Timo Teras
2014-05-08  0:03           ` Stephen Thomas
2014-05-08  1:06           ` Rich Felker
2014-05-08  2:08             ` Stephen Thomas
2014-05-08  3:01               ` Rich Felker [this message]
2014-05-08  5:11             ` Timo Teras
2014-05-08  5:18               ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140508030102.GF26358@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).