Skip to content

A refused in-memory compilation with -working-directory leaves the process in that directory #267

Open

Description

@SizzleUnrlsd

Summary

A compilation to memory takes a single compilation job. With -working-directory <dir> and arguments that give more than one job, such as a source without -c or -S, the compilation is refused, and the process is left in <dir>. The behaviour is inherited: before #262, every compilation with -working-directory left the process there. compileToModule (#265) has it too.

Observed

A temporary unit test, on macOS arm64 with LLVM 20.1.2. unit.c is in <project>, the process is elsewhere, and the test reads the process's working directory after the call:

compilerlib::compile({"-working-directory", "<project>", "unit.c"}, compilerlib::OutputMode::ToMemory);
compilerlib Call Result The process afterwards
f0a22d9, before #262 compile, to memory fails: in-memory output only supports a single compilation job in <project>
e6d5c6c merged into #265 (be9bd28) compile, to memory fails, same message in <project>
e6d5c6c merged into #265 (be9bd28) compileToModule, same arguments fails, same message in <project>

Cause

Since #262, the process moves only for a compilation with a job that runs as a program of its own, such as the link these arguments ask for, and it moves before the jobs are checked: set_current_path at compiler.cpp L1418-L1427, then validateJobPlan at L1432, which refuses more than one job for an output in memory. No job has run by then.

Before #262, the driver moved the process as it built the compilation, whatever its jobs.

Consequence

A host that compiles to memory from several threads does not expect a compilation that runs no job to move the process. Other compilations of the process then resolve relative paths of the process's own, such as a relative -working-directory, from <dir>.

The CoreTrace stack analyzer always adds -c or -S to its commands, so its compilations have a single job.

Possible fix

Check the job plan before the process moves, so that a compilation refused for its jobs leaves the process where it is.

Found by

The integration of #262 into #265, while checking compileToModule with -working-directory. This is apart from #264, where a compilation goes on after a driver error.

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