mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Joakim Sindholt <opensource@zhasha.com>
To: musl@lists.openwall.com
Subject: Re: implement stdatomic.h library interface
Date: Thu, 23 Jul 2015 18:32:26 +0200	[thread overview]
Message-ID: <66dbe85b.dNq.dMV.23.hGZuqs@mailjet.com> (raw)
In-Reply-To: <1437663872.3270.11.camel@inria.fr>

On Thu, 2015-07-23 at 17:04 +0200, Jens Gustedt wrote:
> Am Donnerstag, den 23.07.2015, 16:42 +0200 schrieb Szabolcs Nagy:
> > * Jens Gustedt <jens.gustedt@inria.fr> [2015-07-23 16:04:14 +0200]:
> > > Am Donnerstag, den 23.07.2015, 15:05 +0200 schrieb Szabolcs Nagy:
> > > > it seems gcc does not pass -latomic automatically to the linker
> > > > which is ugly (i think atomics should work transparently), but
> > > > ppl using atomics will.
> > > 
> > > I think the situation is somewhat comparable to -lm. Other libraries
> > > may implement that as separate .a or .so, we should just integrate it
> > > to the whole, and provide an empty libatomic.[a|so]
> > 
> > i think it's a bit different because -lm is libc and libatomic is
> > compiler runtime now. (and extern linkage behaviour for math functions
> > is more clear than for "generic" atomic functions).
> 
> It is not clear if this is compiler runtime. gcc provides libatomic,
> clang refers to the C library.

compiler-rt provides the fallback symbols:
https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/atomic.c

> In any case, do you think that there would be a problem with the
> approach that I propose. (provided that everybody sticks to the ABI
> ...)
> 
> > > > (there is another problem that gcc libatomic on x86 uses ifunc
> > > > dispatch for some __atomic_*_16 functions which does not work
> > > > with musl now, this can be worked around by rebuilding gcc with
> > > > --disable-gnu-indirect-function.)
> > > 
> > > Can you explain in more detail what is not working?
> > 
> > i mean that on a normal build of gcc >=4.9 libatomic uses
> > the gnu IFUNC feature (runtime dispatch for function symbols
> > based on cpu features at early startup).
> 
> I see how that can cause problems for us.
> 
> But I don't really see how that helps. To be efficient instruction
> based lock-free atomics should be inlined at compile time, no? Or do
> they do lto on that kind of stuff?

The symbols are only used as a fallback, just like with large division
and the like. At least with clang the instructions are directly
inserted. The reason they use ifuncs is to optimize the slow path (dumb
as it sounds).

> > this IFUNC elf extension is not supported by musl now so
> > loading a shared object with such symbols will fail
> > (not sure what happens with static linking) so you have
> > to build a musl specific toolchain now to use libatomic.
> 
> Static linking seems to work fine.

Then you're not hitting the fallback symbols. They will initially be
NULL and you should get SIGSEGV. At least this was the result I saw when
trying to use ifunc resolver in a static binary with musl.

I still don't know why I get caught in the spam filter. This email will
be as delayed as the one I sent hours ago as it needs manual approval. I
apologize if this is antiquated by the time it reaches the list.
-- Joakim






  reply	other threads:[~2015-07-23 16:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23  9:58 Jens Gustedt
2015-07-23 12:14 ` Joakim Sindholt
2015-07-23 22:21   ` Jens Gustedt
2015-07-24 23:18   ` Rich Felker
2015-07-25  6:33     ` Jens Gustedt
2015-07-25  9:17       ` Joakim Sindholt
2015-07-25 12:12         ` Jens Gustedt
2015-07-23 13:05 ` Szabolcs Nagy
2015-07-23 14:04   ` Jens Gustedt
2015-07-23 14:42     ` Szabolcs Nagy
2015-07-23 15:04       ` Jens Gustedt
2015-07-23 16:32         ` Joakim Sindholt [this message]
2015-07-23 17:02           ` Szabolcs Nagy
2015-07-23 22:44           ` Jens Gustedt

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=66dbe85b.dNq.dMV.23.hGZuqs@mailjet.com \
    --to=opensource@zhasha.com \
    --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).