1

Is there a way of configuring the emacs build to produce an executable that does not use dump/unexec functionality?

I'm trying to compile emacs with ASAN, clang and gcc's address sanitizer, enabled.

However, ASAN is an invasive compiler plugin and it's disturbing Emacs' unexec/dump functionality.

I'm using the following script to compile a "debug Emacs" from a release tarball.

#!/bin/bash

oldpwd="$(pwd)"

echo "${make_args[@]}"

tar -xvf "$oldpwd"/emacs-26.1.tar.xz

mkdir -p "$oldpwd"/out

(
        cd ./emacs-26.1
        ./configure --prefix="$oldpwd"/out
        make 'CC=gcc' 'CFLAGS=-O0 -fsanitize=address -g' 'LDFLAGS=-lpthread -lasan'
        make install
)

I get the following stack trace while building emacs. The stripped-down interpreter temacs works fine, but crashes when it tries to dump its state.

==28019==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fffef4c899e bp 0x7fffffffca90 sp 0x7fffffffca70 T0)
    #0 0x7fffef4c899d in malloc_set_state (/lib64/libc.so.6+0x8599d)
    #1 0x83c053 in malloc_initialize_hook ~/Downloads/emacs-26.1/src/alloc.c:164
    #2 0x7fffef4c7d0e in ptmalloc_init.part.7 (/lib64/libc.so.6+0x84d0e)
    #3 0x7fffef4c81dc in malloc_hook_ini (/lib64/libc.so.6+0x851dc)
    #4 0x7fffef4c69ba in malloc_get_state (/lib64/libc.so.6+0x839ba)
    #5 0x83c077 in alloc_unexec_pre ~/Downloads/emacs-26.1/src/alloc.c:190
    #6 0x7349a0 in Fdump_emacs ~/Downloads/emacs-26.1/src/emacs.c:2218
    #7 0x88c739 in eval_sub ~/Downloads/emacs-26.1/src/eval.c:2237

As far as I can tell, the offending line is in alloc.c

      if (malloc_set_state (malloc_state_ptr) != 0)
        emacs_abort ();
# ifndef XMALLOC_OVERRUN_CHECK
      alloc_unexec_post ();
# endif
    }

Where malloc_state_ptr doesn't acquire a sensible value when -fsanitize=address is enabled. I'm not sure why the normal path works, but I don't have enough familiarity with the Emacs source to figure it out.

Greg Nisbet
  • 857
  • 5
  • 19

1 Answers1

2

Is there a way of configuring the emacs build to produce an executable that does not use dump/unexec functionality?

Yes, the configure script has un-advertised support for inhibiting dumping:

env CANNOT_DUMP=yes ./configure

Of course you still have access to src/temacs after compiling Emacs normally (i.e. without using CANNOT_DUMP), and temacs is a fully-functional un-dumped emacs executable, so depending on the situation you might be able to use that directly. (See also https://emacs.stackexchange.com/a/16521/454 ).

phils
  • 48,657
  • 3
  • 76
  • 115
  • 1
    I can confirm that setting `CANNOT_DUMP=yes` at `configure` time does work and produces an `emacs` without the dumping feature. Also the resulting emacs appears to work with `ASAN` enabled as well. – Greg Nisbet Aug 02 '18 at 22:29