Skip to content

Commit caf65d1

Browse files
llvm-project: link against jemalloc
The following symbols from musl's malloc implementation were appearing in a perf profile of a kernel build (from stage 5, which isn't landed yet, see #37). Samples: 13M of event 'cycles:ppu', Event count (approx.): 9699067643159 Overhead Shared Object Symbol + 1.72% clang [.] __libc_malloc_impl 0.80% clang [.] __libc_free + 0.67% clang [.] alloc_slot + 0.65% clang [.] get_meta Replace musl's malloc with jemalloc. Fixes #36
1 parent ba5054b commit caf65d1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm-project/Dockerfile.epoch3

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN wget --no-verbose https://git.kernel.org/torvalds/t/linux-5.18-rc6.tar.gz
55
RUN wget --no-verbose https://musl.libc.org/releases/musl-1.2.3.tar.gz
66
RUN wget --no-verbose https://zlib.net/zlib-1.2.12.tar.gz
77
RUN wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.1/llvm-project-14.0.1.src.tar.xz
8+
RUN wget --no-verbose https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
89

910
FROM ${BASE} AS stage2
1011
FROM docker.io/alpine:edge AS stage3
@@ -60,6 +61,19 @@ RUN make -C ${ZLIB_DIR} -j$(nproc)
6061
RUN make -C ${ZLIB_DIR} -j$(nproc) install
6162
RUN apk del make
6263

64+
### Jemalloc
65+
COPY --from=source jemalloc-5.3.0.tar.bz2 .
66+
RUN tar xf jemalloc-5.3.0.tar.bz2
67+
ARG JEMALLOC_DIR=jemalloc-5.3.0/build
68+
RUN mkdir -p ${JEMALLOC_DIR}
69+
RUN cd ${JEMALLOC_DIR} && \
70+
CC=clang AR=llvm-ar NM=llvm-nm CPPFLAGS=${SYSROOT} LDFLAGS=${SYSROOT} \
71+
../configure --disable-libdl --prefix=/usr
72+
RUN apk add make
73+
RUN make -C ${JEMALLOC_DIR} -j$(nproc) build_lib_static
74+
RUN make -C ${JEMALLOC_DIR} -j$(nproc) DESTDIR=/sysroot install_lib_static
75+
RUN apk del make
76+
6377
### LLVM
6478
COPY --from=source llvm-project-14.0.1.src.tar.xz .
6579
RUN tar xf llvm-project-14.0.1.src.tar.xz && \

llvm-project/stage3.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(CMAKE_CXX_FLAGS "--sysroot=/sysroot" CACHE STRING "")
1313
set(CMAKE_C_FLAGS "--sysroot=/sysroot" CACHE STRING "")
1414

1515
# Statically link resulting executable.
16-
set(CMAKE_EXE_LINKER_FLAGS "-static -lc++abi" CACHE STRING "")
16+
set(CMAKE_EXE_LINKER_FLAGS "-static -lc++abi -ljemalloc" CACHE STRING "")
1717

1818
# The compiler builtins are necessary.
1919
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")

0 commit comments

Comments
 (0)