Skip to content

[Bug]: rust-lld linker output silently zeroed on VirtualBox shared folder (vboxsf) due to MAP_SHARED writes not persisting #860

Description

@Hlipa

Version

7.2.16

Host OS Type

Linux

Host OS name + version

Ubuntu 24.04 LTS

Host Architecture

x86

Guest OS Type

Linux

Guest Architecture

ARM

Guest OS name + version

Ubuntu 26.04 LTS

Component

Storage and Virtual Disks

What happened?

A Rust/Cargo build placed on a VirtualBox shared folder can fail with a misleading generated-file error:

error: couldn't read .../serde_core-.../out/private.rs:
No such file or directory (os error 2)

The missing private.rs is a downstream symptom. The confirmed failure is lower in the stack: rust-lld creates linker output through a writable, shared memory mapping. On the tested vboxsf mount, the relevant system calls all return success, but the data written through MAP_SHARED is not persisted. The resulting executable has the expected length but contains zeros and has no allocated data blocks.

Moving Cargo's target directory to a container-local filesystem such as /tmp avoids the problem.

How can we reproduce this?

Following script works fine in local FS, but it fails when file is created on vboxsf:

#!/usr/bin/env python3
import mmap
import os
import sys
if len(sys.argv) != 2:
    raise SystemExit(f"usage: {sys.argv[0]} OUTPUT_FILE")
path = sys.argv[1]
size = 4096
expected = b"VISIBLE!"
fd = os.open(path, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o644)
os.ftruncate(fd, size)
mapping = mmap.mmap(
    fd,
    size,
    flags=mmap.MAP_SHARED,
    prot=mmap.PROT_READ | mmap.PROT_WRITE,
)
mapping[: len(expected)] = expected
mapping.flush()  # msync(MS_SYNC)
os.fsync(fd)
mapping.close()
os.close(fd)
with open(path, "rb") as stream:
    actual = stream.read(len(expected))
print(f"written: {expected!r}")
print(f"read:    {actual!r}")
assert actual == expected, "MAP_SHARED writes were lost"

Did you upload all of your necessary log files, screenshots, etc.?

  • Yes, I've uploaded all pertinent files to this issue.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions