Skip to content

Commit

Permalink
llvm-project: link against jemalloc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nickdesaulniers committed Jul 1, 2022
1 parent ba5054b commit caf65d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions llvm-project/Dockerfile.epoch3
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RUN wget --no-verbose https://git.kernel.org/torvalds/t/linux-5.18-rc6.tar.gz
RUN wget --no-verbose https://musl.libc.org/releases/musl-1.2.3.tar.gz
RUN wget --no-verbose https://zlib.net/zlib-1.2.12.tar.gz
RUN wget --no-verbose https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.1/llvm-project-14.0.1.src.tar.xz
RUN wget --no-verbose https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2

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

### Jemalloc
COPY --from=source jemalloc-5.3.0.tar.bz2 .
RUN tar xf jemalloc-5.3.0.tar.bz2
ARG JEMALLOC_DIR=jemalloc-5.3.0/build
RUN mkdir -p ${JEMALLOC_DIR}
RUN cd ${JEMALLOC_DIR} && \
CC=clang AR=llvm-ar NM=llvm-nm CPPFLAGS=${SYSROOT} LDFLAGS=${SYSROOT} \
../configure --disable-libdl --prefix=/usr
RUN apk add make
RUN make -C ${JEMALLOC_DIR} -j$(nproc) build_lib_static
RUN make -C ${JEMALLOC_DIR} -j$(nproc) DESTDIR=/sysroot install_lib_static
RUN apk del make

### LLVM
COPY --from=source llvm-project-14.0.1.src.tar.xz .
RUN tar xf llvm-project-14.0.1.src.tar.xz && \
Expand Down
2 changes: 1 addition & 1 deletion llvm-project/stage3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(CMAKE_CXX_FLAGS "--sysroot=/sysroot" CACHE STRING "")
set(CMAKE_C_FLAGS "--sysroot=/sysroot" CACHE STRING "")

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

# The compiler builtins are necessary.
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
Expand Down

0 comments on commit caf65d1

Please sign in to comment.