Skip to content

nix 0.26 can't work on ubuntu16.04 #1972

@rise0chen

Description

@rise0chen
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) 

Activity

changed the title [-]undefined reference to `memfd_create'[/-] [+]nix 0.26 can't work on ubuntu16.04[/+] on Jan 17, 2023
asomers

asomers commented on Jan 17, 2023

@asomers
Member

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

rise0chen commented on Jan 18, 2023

@rise0chen
Author
root@f0fca0e971de:~/rc3.1# objdump -T /lib/x86_64-linux-gnu/libc.so.6 | grep memfd
root@f0fca0e971de:~/rc3.1# 

It is empty.
You can test it in docker image. https://hub.docker.com/_/ubuntu

rise0chen

rise0chen commented on Jan 18, 2023

@rise0chen
Author

The problem is caused by this commit cf15c2b

asomers

asomers commented on Feb 13, 2023

@asomers
Member

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

rise0chen commented on Feb 21, 2023

@rise0chen
Author

You can test this code in ubuntu:16.04 with docker.

rustc 1.65.0 (897e37553 2022-11-02)

rise0chen

rise0chen commented on Feb 21, 2023

@rise0chen
Author

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

jszwedko commented on Feb 21, 2023

@jszwedko

We are seeing this as well for https://github.com/vectordotdev/vector when building on CentOS 7 which has:

$ ldd --version ldd
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

We build on CentOS 7 specifically to link against an older libc version for broader platform support.

asomers

asomers commented on Feb 21, 2023

@asomers
Member

Ubuntu 16.04 is EoL. Is CentOS 7?

jszwedko

jszwedko commented on Feb 21, 2023

@jszwedko

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

asomers commented on Feb 21, 2023

@asomers
Member

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

jszwedko commented on Feb 22, 2023

@jszwedko

Thanks for the tip! I tried --as-needed, but am still seeing the same error. For reference, we are using ld as the linker:

$ ld --version
GNU ld version 2.27-44.base.el7
Copyright (C) 2016 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

To reproduce, you can checkout https://github.com/vectordotdev/vector at 2b28408eae2b3c43a9e88d701e57fc50cd25fad7 and run cargo 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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Ralith@asomers@jszwedko@rise0chen

      Issue actions

        nix 0.26 can't work on ubuntu16.04 · Issue #1972 · nix-rust/nix