Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linking against system jemalloc is not working #19

Closed
fbernier opened this issue Jan 1, 2022 · 2 comments
Closed

linking against system jemalloc is not working #19

fbernier opened this issue Jan 1, 2022 · 2 comments

Comments

@fbernier
Copy link

fbernier commented Jan 1, 2022

using JEMALLOC_OVERRIDE=/usr/lib/libjemalloc_pic.a cargo build to build against jemalloc 5.2.1 fails with

   Compiling fs_extra v1.2.0
   Compiling cc v1.0.72
   Compiling libc v0.2.112
   Compiling tikv-jemalloc-sys v0.4.2+5.2.1-patched.2
   Compiling tikv-jemallocator v0.4.1
   Compiling empty-rust v0.1.0 (/home/fbernier/code/empty-rust)
error: linking with `/usr/bin/clang` failed: exit status: 1
  |
  = note: "/usr/bin/clang" "-m64" "/home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o" "/home/fbernier/code/empty-rust/ta
4-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-4fc3313c8ccb1ec0.rlib" "/home/fbernier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustli
b/x86_64-unknown-linux-gnu/lib/libcfg_if-19bf8dffe82b09d4.rlib" "/home/fbernier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib
/liblibc-afc95b1640c4beca.rlib" "/home/fbernier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-aff6658baa87e3d1.rlib"
 "/home/fbernier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-8be8a1689a4f7b48.rlib" "/home/fber
nier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-5284934f66073844.rlib" "-Wl,--end-group" "/home/fbernier/.rustup/t
oolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-2a0b2a4f96acb821.rlib" "-Wl,-Bdynamic" "-lc" "-lm" "-lrt" "-lpthrea
d" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/fbernier/.rustup/toolchains/stable-x86_64-unknown-linux-gn
u/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-
Wl,-znow" "-nodefaultlibs" "--ld-path=/usr/bin/mold"
  = note: mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_mallocx
          mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_calloc
          mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_mallocx
          mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_malloc
          mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_sdallocx
          mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_realloc
          mold: error: undefined symbol: /home/fbernier/code/empty-rust/target/debug/deps/empty_rust-617320318ce0467b.133ezxkakzrmpn1z.rcgu.o: _rjem_rallocx
          clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

This is with mold but it's the same with other linkers. Building with the original jemallocator instead does work.

@BusyJay
Copy link
Member

BusyJay commented Jan 4, 2022

You may wish to check if libjemalloc_pic.a is compiled with the same prefix as tikv-jemalloc-sys, which is use _rjem_ by default. By enabling unprefixed_malloc_on_supported_platforms feature, prefix can be removed completely on Linux and other supported platforms.

@fbernier
Copy link
Author

fbernier commented Jan 4, 2022

Indeed, the jemalloc that ships with debian and arch linux is not prefixed, and using CARGO_FEATURE_UNPREFIXED_MALLOC_ON_SUPPORTED_PLATFORMS=1 compiles properly.

Thanks!

@fbernier fbernier closed this as completed Jan 4, 2022
@fbernier fbernier changed the title static linking is not working linking against system jemalloc is not working Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants