Skip to content

stop calling realpath in the compiler #16571

@andrewrk

Description

@andrewrk

realpath is problematic for several reasons:

  1. it is not available for many targets, including WASI and BSDs
  2. it just straight up doesn't work for long file paths, if you have /long1/long2/foo for example where long1 and long2 together exceed MAX_PATH, then the OS will give an error for that path when asked for the realpath.
  3. it fails to respect the lazy nature of symlinks
  4. race conditions with moving files around

Robust software avoids realpath.

/home/andy/dev/zig/lib/std/os.zig:5079:15: error: realpath is forbidden
    if (true) @compileError("realpath is forbidden");
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    init: /home/andy/dev/zig/src/codegen/llvm.zig:802:38
    create: /home/andy/dev/zig/src/codegen/llvm.zig:754:27
    createEmpty: /home/andy/dev/zig/src/link/NvPtx.zig:41:39
    openPath: /home/andy/dev/zig/src/link/NvPtx.zig:63:12
    openPath: /home/andy/dev/zig/src/link.zig:363:41
    update: /home/andy/dev/zig/src/Compilation.zig:2003:38
    updateModule: /home/andy/dev/zig/src/main.zig:3864:17
    cmdBuild: /home/andy/dev/zig/src/main.zig:4510:9
    mainArgs: /home/andy/dev/zig/src/main.zig:285:16
    main: /home/andy/dev/zig/src/main.zig:213:12

Looks like this regressed in #13843.

Maybe we can even add a std lib option to disallow realpath on a per-application basis and then opt into that restriction in the compiler.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions