Subject: bug#48789: 28.0.50; Emacs does not build with musl

From: akater <[email-masked]>
Date: Wed, 02 Jun 2021 11:26:18 +0000

(sectioned with Org markup if you want it)

* General information
The following is not a solution, just FYI:

Observing compiler (GCC 10.2.0) warnings and errors, on 2021-05-11 I
managed to build Emacs 28 with musl after reverting commits dealing with
two features,

an older one:

621bb79b7044dcc277386eb7338c0eb1e08c29c7 "New debugging command 'malloc-info'"

and a newer one --- everything related to lib-src/seccomp-filter.c

I provide the list of related commits but I likely made mistakes while
reverting so I don't attach the patch itself; the list is for
completenes.

I did not try to build Emacs 28 since, so commits newer than 2021-05-11
are not taken into account.  I will try if necessary.

Even though I did manage to build Emacs 28 with musl, my build is
extremely unreliable, regular crashes occur.  This might be due to my
lousy reverting, or due to an interference from native-comp feature, or
the neccesity to recompile third-party Elisp packages, or all at once.
Unfortunately, it so happened that I started using a musl system exactly
when native-comp is out.

Unable to use Emacs 28 here, I use Emacs 27.2 now which builds and works
totally fine with musl.

Below are: relevant commits and system configuration, for both 27.2 and 28.0.

* Commits for seccomp-filter
Here's the list of commits related to seccomp-filter that I (likely
incompetently) reverted, which allowed for Emacs 28 musl build:

Revert "Add a helper binary to create a basic Secure Computing filter."
This reverts commit 1060289f51ee1bf269bb45940892eb272d35af97

Revert "* lib-src/Makefile.in (clean): Tidy up seccomp-filter files."
This reverts commit aa354dd55b213b86ee8e3aa0365a6ad915838458.
Revert "Don't use symbolic links in the test resource directory."
This reverts commit a2842a11728336fc8110eedb5176ecfbe71bbc79.
Revert "Ensure that argument to 'verify' is a constant expression."
This reverts commit aaf6b6bf80805d18180e1c16350e9473716f5915.
Revert "Seccomp filter: deal with arch_prctl(ARCH_CET_STATUS, ...)."
This reverts commit 27af0a3dc8b6b45879904bbc5d54b0677f84a5ff.
Revert "Fix Seccomp filter on CentOS 8.3 (Bug#47828)."
This reverts commit 2822246b5d8154d0166e17ffd28a1d85b57d68aa.
Revert "Attempt to print some debugging information on Seccomp failures."
This reverts commit 568ce6826fa0aaa4d5dc95880cbdc0965dc07521.
Revert "* lib-src/seccomp-filter.c: Add missing headers."
This reverts commit 104c5e3d57705cd4bd291b61d7f165def602ab5c.
Revert "Generate Seccomp filters only if we have the necessary constants."
This reverts commit 17d20bb3cbb233ed0d94c3f1f9f3db768f526223.
Revert "* src/emacs.c (load_seccomp): Consistently check for nonzero result"
This reverts commit d37f0f3ac34f09830a881280131980f875d075d3.
Revert "Add a variant of the Seccomp filter file that allows 'execve'."
This reverts commit c8d542fd593f06b85d4b7b712378a4f84ec4d2b3.
Revert "* lib-src/seccomp-filter.c (main): Also allow O_NOFOLLOW."
This reverts commit cf0701eff0f3b06e0324be07f7810cbaf261f7f3.
Revert "Seccomp filter: allow reading the current time (Bug#47708)."
This reverts commit ea5ea09244b762008bba509d8c58bad5835fb949.
Revert "Use pkg-config to check for libseccomp."
This reverts commit 725fc96b706c57ef8ceca5e7d82b175d9a72e845.
Revert "Remove SCMP_FLTATR_CTL_LOG attribute from Seccomp filter."
This reverts commit d06c54db1b3504caed8673216a72b117d0692351.
Revert "Only attempt to generate seccomp filter files on x86-64 systems."
This reverts commit 9dc26d4a8add5b3f2a5fce7907af4f9673ae82c0.
Revert "* lib-src/seccomp-filter.c: Print trailing newline."
This reverts commit 553783628892a5363aacf58ce238969cb60a1c3a.
Revert "Also check for needed seccomp macros."
This reverts commit 25937821bc445235d984c4db8cb18dfbacd6a4ff.
Revert "* src/emacs.c (load_seccomp): Add a useful assertion."
This reverts commit 2db03e3e53af3ce5c87f64d163ab2be96aee2c0f.
Revert "* src/emacs.c (load_seccomp): Fix condition."
This reverts commit 496a46b32db9a3c32a846b8a3c872891303a1ec4.
Revert "Add a helper binary to create a basic Secure Computing filter."
This reverts commit 1060289f51ee1bf269bb45940892eb272d35af97.

* Emacs configuration
I'm using Gentoo, with musl profile ~default/linux/amd64/17.0/musl/hardened~.
** 27.2

Configured using:
 'configure --prefix=/usr --build=x86_64-gentoo-linux-musl
 --host=x86_64-gentoo-linux-musl --mandir=/usr/share/man
 --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
 --localstatedir=/var/lib --disable-silent-rules
 --docdir=/usr/share/doc/emacs-27.2
 --htmldir=/usr/share/doc/emacs-27.2/html --libdir=/usr/lib
 --program-suffix=-emacs-27 --includedir=/usr/include/emacs-27
 --infodir=/usr/share/info/emacs-27 --localstatedir=/var
 --enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
 --without-compress-install --without-hesiod --without-pop
 --with-file-notification=no --with-pdumper --disable-acl --without-dbus
 --with-modules --without-gameuser --with-libgmp --without-gpm
 --with-json --without-kerberos --without-kerberos5 --without-lcms2
 --with-xml2 --without-mailutils --without-selinux --with-gnutls
 --without-libsystemd --with-threads --without-wide-int --with-zlib
 --with-sound=no --without-x --without-ns --with-dumping=pdumper
 'CFLAGS=-march=native -O2 -pipe' CPPFLAGS= 'LDFLAGS=-Wl,-O1
 -Wl,--as-needed''

Configured features:
GNUTLS LIBXML2 ZLIB MODULES THREADS JSON PDUMPER GMP

Important settings:
  value of $LANG: C.UTF8
  locale-coding-system: utf-8-unix

Memory information:
((conses 16 2211161 291586)
 (symbols 48 57073 2)
 (strings 32 259188 12930)
 (string-bytes 1 7862427)
 (vectors 16 109477)
 (vector-slots 8 1620006 88906)
 (floats 8 1626 870)
 (intervals 56 115451 4407)
 (buffers 1000 81))

** 28.0
The revision is ec574a72f7198d9793b466f33382fff397ac4ce1

Configured using:
 'configure --prefix=/usr --build=x86_64-gentoo-linux-musl
 --host=x86_64-gentoo-linux-musl --mandir=/usr/share/man
 --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
 --localstatedir=/var/lib --disable-silent-rules
 --docdir=/usr/share/doc/emacs-28.0.9999
 --htmldir=/usr/share/doc/emacs-28.0.9999/html --libdir=/usr/lib
 --program-suffix=-emacs-28-vcs --includedir=/usr/include/emacs-28-vcs
 --infodir=/usr/share/info/emacs-28-vcs --localstatedir=/var
 --enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
 --without-compress-install --without-hesiod --without-pop
 --with-file-notification=no --with-pdumper --disable-acl
 --disable-link-time-optimization --without-dbus --with-modules
 --without-gameuser --with-libgmp --without-gpm --with-json
 --without-kerberos --without-kerberos5 --without-lcms2 --with-xml2
 --without-mailutils --without-selinux --with-gnutls
 --without-libsystemd --with-threads --without-native-compilation
 --without-wide-int --with-zlib --with-sound=no --without-imagemagick
 --without-x --without-ns --with-dumping=pdumper 'CFLAGS=-march=native
 -O2 -pipe' CPPFLAGS= 'LDFLAGS=-Wl,-O1 -Wl,--as-needed''

Configured features:
GMP GNUTLS JSON LIBXML2 MODULES PDUMPER SECCOMP THREADS ZLIB

Important settings:
  value of $LANG: C.UTF8
  locale-coding-system: utf-8-unix

Memory information:
((conses 16 409599 310905)
 (symbols 48 41434 3)
 (strings 32 163330 24933)
 (string-bytes 1 5104681)
 (vectors 16 68170)
 (vector-slots 8 715297 489605)
 (floats 8 393 1947)
 (intervals 56 1099 72)
 (buffers 992 13))