mailing list of musl libc
 help / color / mirror / code / Atom feed
From: u-uy74@aetey.se
To: musl@lists.openwall.com
Subject: Re: more fun with non-Linux Linux ABI
Date: Mon, 12 Jun 2017 10:30:12 +0200	[thread overview]
Message-ID: <20170612083012.GT30784@example.net> (raw)
In-Reply-To: <20170611215020.GB1627@brightrain.aerifal.cx>

On Sun, Jun 11, 2017 at 05:50:20PM -0400, Rich Felker wrote:
> On Sun, Jun 11, 2017 at 08:01:58PM +0200, u-uy74@aetey.se wrote:
> > FWIIW: when running under Linux ABI on FreeBSD
> > in musl-linked programs the child processes segfault right after a
> > vfork(), before doing anything else:
> 
> My first guess is that this is a FreeBSD bug...

I agree.

> > Remarkably this apparently does not affect glibc-based builds
> > (I have not tested right now but otherwise it would have been known).
> > Wonder what makes the difference.
> 
> Is it possible that FreeBSD's Linux syscall emulation uses the
> userspace stack to store some state during syscalls? For example maybe

I am not sufficiently familiar with the FreeBSD internals to tell this.
The linux_fork() and linux_vfork() functions are about 30 lines each
and the only difference is

--- fork
+++ vfork
 ...
         struct fork_req fr;
 ...
         bzero(&fr, sizeof(fr));
-        fr.fr_flags = RFFDG | RFPROC | RFSTOPPED;
+        fr.fr_flags = RFFDG | RFPROC | RFMEM | RFPPWAIT | RFSTOPPED;
         fr.fr_procp = &p2;
         if ((error = fork1(td, &fr)) != 0)
                 return (error);
 ...

I guess the musl vs glibc difference can happen if the latter implements
vfork() in terms of clone() (?)

linux_clone() has a much larger implementation in FreeBSD than
linux_vfork() which could explain why the one works and the other
does not.

> > Otherwise a simple workaround would be an option to make vfork()
> > a fork() synonym while building musl. (I do the this at applications
> > build time instead, which helps.)
> > 
> > Such an option would most probably result in a pretty small performance
> > impact on modern (native) Linux.
> 
> It's actually a pretty large impact; recent (4.x+ IIRC) versions of
> GNU makes are considerably slower because they dropped use of vfork
> and switched to fork rather than making it use posix_spawn like it
> should.

Thanks, good to know. Then I have to live with this impact on Linux
or convince the FreeBSD team to fix linux_vfork().

Rune



  reply	other threads:[~2017-06-12  8:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-11 18:01 u-uy74
2017-06-11 21:50 ` Rich Felker
2017-06-12  8:30   ` u-uy74 [this message]
2017-06-12 15:29   ` Bobby Powers
2017-06-15  0:15     ` 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=20170612083012.GT30784@example.net \
    --to=u-uy74@aetey.se \
    --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).