mailing list of musl libc
 help / color / mirror / code / Atom feed
From: stephen Turner <stephen.n.turner@gmail.com>
To: musl@lists.openwall.com
Subject: Re: GNU Emacs LD_PRELOAD build hack
Date: Tue, 3 Feb 2015 07:21:38 -0500	[thread overview]
Message-ID: <CAA7aPHhVBQrD8CZWjApQhQEG9sB1q1m+JzrymZom=c6dbQJpUQ@mail.gmail.com> (raw)
In-Reply-To: <20150203035407.GA14795@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 2814 bytes --]

On Feb 2, 2015 10:54 PM, "Rich Felker" <dalias@libc.org> wrote:
>
> Background: GNU Emacs' build process depends on the ability of the
> build-stage binary (temacs) to "dump" itself to a new executable file
> containing preloaded lisp objects/state in its .data segment. This
> process is highly non-portable even in principle; in practice, the big
> issue is where malloc allocations end up. They need to all be
> contiguous just above the .data/.bss in the original binary so that
> they can become part of the .data mapping. Against musl's malloc, this
> has two major ways it can fail:
>
> 1. musl uses mmap for large allocations (roughly, > 128-256k) and has
>    no mechanism for obtaining such large objects from the main
>    brk-based heap or even requesting such (whereas glibc has mallopt
>    and/or an environment variable to control the mmap threshold, and
>    emacs cheats and uses that to control glibc).
>
> 2. musl reclaims the gaps around the edges of writable mappings in the
>    main program and shared libraries and uses them for malloc. If
>    these are in shared libraries, they won't be dumped at all, and if
>    they're in the main program, they actually overlap with .text on
>    disk (the same page is mapped twice; this is the cause of the gaps)
>    and thus the .text, not the heap data, gets written out to disk by
>    the dumper.
>
> Emacs provides its own malloc replacement and tries to use it by
> default, but this has to be disabled with musl, since replacing malloc
> in dynamic programs doesn't work (and static binaries don't work right
> at all with emacs' dumper because libc state would get included in the
> dump -- state which is "intentionally lost" when it resides in a
> shared library whose state isn't dumped).
>
> The right solution: As I discussed on the emacs-devel list nearly a
> year ago, the right solution is to get rid of the non-portable code in
> emacs, dumping the lisp heap and its data (rather than the whole
> program) to a file and either mmapping it at runtime (and possibly
> relocating pointers in it, if the new location it's loaded at differs)
> or converting it to a C source file that's compiled and linked and for
> which the (static or dynamic) linker can perform relocations at
> link/load time. This solution also solves a number of other serious
> issues related to the dumper, including its incompatibility with PIE
> binaries.
>
> Unfortunately, the right solution requires a significant overhaul by
> someone with expertise in emacs internals, and it's not practical in
> the short term. Meanwhile, we have users wanting emacs on musl-based
> distros (myself included).
>
> So, here's an alternate solution.

I think there was a guy on the toybox list working on editors and might
have a emacs for you. Onefang comes to mind.

[-- Attachment #2: Type: text/html, Size: 3383 bytes --]

  reply	other threads:[~2015-02-03 12:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03  3:54 Rich Felker
2015-02-03 12:21 ` stephen Turner [this message]
2015-02-05  5:22 ` 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='CAA7aPHhVBQrD8CZWjApQhQEG9sB1q1m+JzrymZom=c6dbQJpUQ@mail.gmail.com' \
    --to=stephen.n.turner@gmail.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).