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

Non-LFS functions on 32-bit platforms #94173

Closed
vt-alt opened this issue Feb 19, 2022 · 4 comments
Closed

Non-LFS functions on 32-bit platforms #94173

vt-alt opened this issue Feb 19, 2022 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@vt-alt
Copy link

vt-alt commented Feb 19, 2022

As of 1.58.1 rustc compiles with non-LFS functions on 32-bit platforms.

Linux kernel have special 64-bit versions of some important syscalls that 32-bit programs could use if they want to access large files. In C (and glibc) there is transparent function & syscall replacement if program is compiled with -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64.
Example list of functions that should not be used and replaced with their 64-bit versions if LFS is enabled: fallocate fcntl fopen fstat fstatfs ftruncate getrlimit glob globfree lseek lstat mkstemp mmap open openat posix_fadvise posix_fallocate pread pwrite readdir setrlimit stat statfs. For example, instead of openat should be used openat64.

There are related issues:

But their solutions are seems incomplete.

Simplest reproducer:

$ cat main.rs
fn main() {}
$ rustc main.rs
$ nm main |grep 'U open'
         U open64@GLIBC_2.1
         U open@GLIBC_2.0

As you can see there is open present which mean that there is still non-LFS compliant usage.

@vt-alt vt-alt added the C-bug Category: This is a bug. label Feb 19, 2022
mikebenfield pushed a commit to mikebenfield/backtrace-rs that referenced this issue Dec 6, 2022
mmap is a non-LFS function and due to its usage here will appear in
binaries produced by rustc.

This is relevant to rust-lang/rust#94173.
mikebenfield pushed a commit to mikebenfield/backtrace-rs that referenced this issue Dec 6, 2022
mmap is a non-LFS function and due to its usage here will appear in
binaries produced by rustc.

This is relevant to rust-lang/rust#94173.
mikebenfield pushed a commit to mikebenfield/rust that referenced this issue Dec 7, 2022
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their
non-LFS counterparts.

This is relevant to rust-lang#94173.

With these changes (together with rust-lang/backtrace-rs#501), the
simple binaries I produce with rustc seem to have no non-LFS functions,
so maybe rust-lang#94173 is fixed. But I can't be sure if I've missed something
and maybe some non-LFS functions could sneak in somehow.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 14, 2022
Use more LFS functions.

On Linux, use mmap64, open64, openat64, and sendfile64 in place of their non-LFS counterparts.

This is relevant to rust-lang#94173.

With these changes (together with rust-lang/backtrace-rs#501), the simple binaries I produce with rustc seem to have no non-LFS functions, so maybe rust-lang#94173 is fixed. But I can't be sure if I've missed something and maybe some non-LFS functions could sneak in somehow.
mikebenfield pushed a commit to mikebenfield/backtrace-rs that referenced this issue Dec 14, 2022
mmap is a non-LFS function and due to its usage here will appear in
binaries produced by rustc.

This is relevant to rust-lang/rust#94173.
@mochaaP
Copy link
Contributor

mochaaP commented Dec 19, 2022

This currently breaks musl libc builds at the linking stage.

https://github.com/bminor/musl/blob/f47a8cdd250d9163fcfb39bf4e9d813957c0b187/include/sys/mman.h#L144-L147

Please consider target_env = "musl" when using LFS functions.

mochaaP added a commit to mcha-forks/rust that referenced this issue Dec 22, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 24, 2022
mikebenfield pushed a commit to mikebenfield/backtrace-rs that referenced this issue Dec 26, 2022
mmap is a non-LFS function and due to its usage here will appear in
binaries produced by rustc.

This is relevant to rust-lang/rust#94173.
@workingjubilee
Copy link
Member

workingjubilee commented Jun 30, 2023

Before:

nm hello | grep 'mmap'
                 U mmap64@GLIBC_2.2.5
                 U mmap@GLIBC_2.2.5

After #113176:

nm hello | grep 'mmap'
                 U mmap64@GLIBC_2.2.5

That PR brings in rust-lang/backtrace-rs#501 which should be the last subject of concern for Rust binaries, as it should have the correct fix for both glibc and musl. The libc alias shim should serve for addressing the immediate problem for code we emit as part of our bindings, and we can address how we want to update to move with any future libc changes as a separate subject.

Please let me know if we are actually secretly missing something, or reopen this issue if for some reason that PR fails.

@workingjubilee
Copy link
Member

Also as a remark on possible false positives: we will likely still include a reference to open and not open64 on glibc because the getrandom crate, one of our dependencies in std, decided that use of the 32-bit version was acceptable because they only use it to interact with pulling bytes out of a device file and never seek inside it. This neatly solves any issues for musl. If this is mistaken for some other reason it should be opened as a separate issue, likely against their repo.

smaeul pushed a commit to smaeul/rust that referenced this issue Jun 24, 2024
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their
non-LFS counterparts.

This is relevant to rust-lang#94173.

With these changes (together with rust-lang/backtrace-rs#501), the
simple binaries I produce with rustc seem to have no non-LFS functions,
so maybe rust-lang#94173 is fixed. But I can't be sure if I've missed something
and maybe some non-LFS functions could sneak in somehow.
smaeul pushed a commit to smaeul/rust that referenced this issue Jun 24, 2024
smaeul pushed a commit to smaeul/rust that referenced this issue Jun 24, 2024
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their
non-LFS counterparts.

This is relevant to rust-lang#94173.

With these changes (together with rust-lang/backtrace-rs#501), the
simple binaries I produce with rustc seem to have no non-LFS functions,
so maybe rust-lang#94173 is fixed. But I can't be sure if I've missed something
and maybe some non-LFS functions could sneak in somehow.
smaeul pushed a commit to smaeul/rust that referenced this issue Jun 24, 2024
smaeul pushed a commit to smaeul/rust that referenced this issue Jun 24, 2024
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their
non-LFS counterparts.

This is relevant to rust-lang#94173.

With these changes (together with rust-lang/backtrace-rs#501), the
simple binaries I produce with rustc seem to have no non-LFS functions,
so maybe rust-lang#94173 is fixed. But I can't be sure if I've missed something
and maybe some non-LFS functions could sneak in somehow.
smaeul pushed a commit to smaeul/rust that referenced this issue Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants