openssl: 1.1.1 fails to build with MUSL libc due to missing linux/mman.h

Building OpenSSL 1.1.1 against MUSL libc fails to find the linux/mman.h header:

$ curl -L https://www.openssl.org/source/openssl-1.1.1.tar.gz | tar --strip-components=1 -xzf -
$ export CC=musl-gcc
$ ./Configure --prefix=$OPENSSL_DIR linux-x86_64 no-shared no-async no-engine
$ make
[...]
musl-gcc  -I. -Icrypto/include -Iinclude -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/openssl/ssl\"" -DENGINESDIR="\"/openssl/lib/engines-1.1\"" -DNDEBUG  -MMD -MF crypto/mem_sec.d.tmp -MT crypto/mem_sec.o -c -o crypto/mem_sec.o crypto/mem_sec.c
crypto/mem_sec.c:37:27: fatal error: linux/mman.h: No such file or directory
 #   include <linux/mman.h>
                           ^
compilation terminated.
CC="musl-gcc" /usr/bin/perl crypto/modes/asm/aesni-gcm-x86_64.pl elf crypto/modes/aesni-gcm-x86_64.s
Makefile:3816: recipe for target 'crypto/mem_sec.o' failed
make[1]: *** [crypto/mem_sec.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/tmp/openssl_build'
Makefile:171: recipe for target 'all' failed
make: *** [all] Error 2

The same build setup does work with 1.1.0. This is using the musl-tools package on Debian Stretch.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

On alpine I do an apk add linux-headers

I found a workaround on ubuntu, without needing to disable secure memory!

I added -static -idirafter /usr/include/ -idirafter /usr/include/x86_64-linux-gnu/ to my musl-gcc command.

For reference, here’s the complete set of steps I used to build openssl against musl in a github actions ubuntu CI runner:

sudo apt-get update
sudo apt-get install -y musl-dev musl-tools linux-headers-$(uname -r)

sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/x86_64-linux-musl/asm && ln -s /usr/include/asm-generic /usr/include/x86_64-linux-musl/asm-generic && ln -s /usr/include/linux /usr/include/x86_64-linux-musl/linux
sudo mkdir /musl
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1f.tar.gz
tar zxf OpenSSL_1_1_1f.tar.gz 
cd openssl-OpenSSL_1_1_1f/
CC="musl-gcc -fPIE -pie -static -idirafter /usr/include/ -idirafter /usr/include/x86_64-linux-gnu/" ./Configure no-shared no-async --prefix=/musl --openssldir=/musl/ssl linux-x86_64
make depend
make -j$(nproc)
sudo make install

this compiled the openssl libraries and makes all the files available in the /musl directory.

To make user of it as a dependency on another build (ie the rust openssl-sys create), i added the following env vars to that build:

PKG_CONFIG_ALLOW_CROSS=1
OPENSSL_STATIC=true
OPENSSL_DIR=/musl

Hope someone else finds this useful

If your build pipeline for Linux runs under the Arch Linux OS, you can install kernel-headers-musl. This works for me, and is better in that we keep the secure memory feature.