Skip to content

ld.cxx: res and rc variables were accidentally swapped. Unswap them#34

Merged
scheibelp merged 2 commits into
spack:mainfrom
johnwparent:patch-res-rc-mixup
May 7, 2026
Merged

ld.cxx: res and rc variables were accidentally swapped. Unswap them#34
scheibelp merged 2 commits into
spack:mainfrom
johnwparent:patch-res-rc-mixup

Conversation

@johnwparent
Copy link
Copy Markdown
Collaborator

@johnwparent johnwparent commented May 6, 2026

We accidentally set res_file_name to use the rc base name and vis versa, which caused the wrong file to be cleaned at the wrong time, resulting in linker failures.

Further, we changed the generated res files to be produced in a temp dir vs the cwd, and added cleanup for these objects in a previous PR.
The cleanup for the RC file is file (resource compiler drops the handle seemingly immediately), but the cleanup for the resource file itself (.res) seems subject to a race condition where the linker allows the OS to cleanup the resource file handle, which is racey with our immediate clean attempt.
Instead, compose the resource file into its own class, and when that class goes out of scope, clean the resource file then and only then. If we still can't clean it for whatever reason, give a warning to stdout vs crashing the program with an exception.

Signed-off-by: John Parent <john.parent@kitware.com>
Comment thread src/ld.cxx
Copy link
Copy Markdown
Member

@scheibelp scheibelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional change makes sense, but I think the debugging output should be removed before merging.

It seems like the linker is allowing the OS to cleanup the handle to the resource file we create to inject the Spack stage path into a given dll
This means our cleanup is racey. Ensure it happens and is not racey using raii, falling back to a stderr warning message if we fail to clean vs an exception.

Signed-off-by: John Parent <john.parent@kitware.com>
@scheibelp scheibelp merged commit 6eb5ad0 into spack:main May 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants