-
Notifications
You must be signed in to change notification settings - Fork 707
Open
Description
fn main() {
println!("{:?}", nix::unistd::gethostname());
}
= note: /root/build/release/deps/libnix-fca8cee73dd370df.rlib(nix-fca8cee73dd370df.nix.9961a42b-cgu.2.rcgu.o): In function `nix::sys::memfd::memfd_create::hbef039c9926ba4f0':
nix.9961a42b-cgu.2:(.text._ZN3nix3sys5memfd12memfd_create17hbef039c9926ba4f0E+0x5): undefined reference to `memfd_create'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
root@f0fca0e971de:~/rc3.1# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)
thombles
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]undefined reference to `memfd_create'[/-][+]nix 0.26 can't work on ubuntu16.04[/+]asomers commentedon Jan 17, 2023
According to the online man pages, that function should be available in Ubuntu 16.04. Could you please do
objdump -T /lib/x86_64-linux-gnu/libc.so.6 | grep memfd
and paste the results?https://manpages.ubuntu.com/manpages/xenial/man2/memfd_create.2.html
rise0chen commentedon Jan 18, 2023
It is empty.
You can test it in docker image. https://hub.docker.com/_/ubuntu
rise0chen commentedon Jan 18, 2023
The problem is caused by this commit cf15c2b
asomers commentedon Feb 13, 2023
Even if memfd_create isn't included in your libc, I don't understand why the compile would fail. Normally the Rust linker eliminates unused code, so it's no problem if a symbol like memfd_create is undefined, if you don't use it. Are you using any weird compiler settings? And what version of Rust are you using anyway?
rise0chen commentedon Feb 21, 2023
You can test this code in ubuntu:16.04 with docker.
rustc 1.65.0 (897e37553 2022-11-02)
rise0chen commentedon Feb 21, 2023
I have updated to the latest stable rust. It also can't work.
stable-x86_64-unknown-linux-gnu updated - rustc 1.67.1 (d5a82bbd2 2023-02-07) (from rustc 1.65.0 (897e37553 2022-11-02))
jszwedko commentedon Feb 21, 2023
We are seeing this as well for https://github.com/vectordotdev/vector when building on CentOS 7 which has:
We build on CentOS 7 specifically to link against an older libc version for broader platform support.
asomers commentedon Feb 21, 2023
Ubuntu 16.04 is EoL. Is CentOS 7?
jszwedko commentedon Feb 21, 2023
I don't think Ubuntu 16.04 is EoL. It seems to be supported through April of 2026 (see https://ubuntu.com/about/release-cycle).
CentOS 7 appears to be supported through 2024-06-30 (see https://wiki.centos.org/About/Product).
asomers commentedon Feb 21, 2023
But only in Expanded Security Maintenance, it seems.
Anyway, I can reproduce your problem only if I use
RUSTFLAGS=-C link-dead-code
. I think your linker probably has different default behavior. If you pass--as-needed
to the linker, I think it will fix your problem.jszwedko commentedon Feb 22, 2023
Thanks for the tip! I tried
--as-needed
, but am still seeing the same error. For reference, we are usingld
as the linker:To reproduce, you can checkout https://github.com/vectordotdev/vector at
2b28408eae2b3c43a9e88d701e57fc50cd25fad7
and runcargo build --no-default-features --features target-x86_64-unknown-linux-gnu
.Would it be useful for me to bisect
nix
down to the commit that introduces the issue? Or do you already have an idea of what the change is?20 remaining items