Skip to content

Embed debug info in host object libraries to avoid LNK4099#130933

Open
elinor-fung wants to merge 1 commit into
dotnet:mainfrom
elinor-fung:host-embed-debuginfo-lnk4099
Open

Embed debug info in host object libraries to avoid LNK4099#130933
elinor-fung wants to merge 1 commit into
dotnet:mainfrom
elinor-fung:host-embed-debuginfo-lnk4099

Conversation

@elinor-fung

Copy link
Copy Markdown
Member

The object libraries embedded into the shipped libnethost.lib and libhostfxr.lib were referencing a vc140.pdb. Consumers linking these static libraries get LNK4099 warnings.

Compile these object libraries with embedded debug info (/Z7) instead. This matches what we do for NativeAOT Runtime.GC.* and for the cDAC descriptor.

cc @dotnet/appmodel @AaronRobinsonMSFT

Fixes #116527

The object libraries embedded into the shipped libnethost.lib and
libhostfxr.lib (minipal_objects, hostmisc_c, hostmisc_public) were
compiled with /Zi, so their objects reference a build-time vc140.pdb
that is not shipped. Consumers linking these static libraries get
LNK4099 warnings ("cannot use debug info ... vc140.pdb: no such file").

Compile these object libraries with embedded debug info (/Z7) instead,
so the debug info travels inside the objects and no external PDB path is
referenced. COMPILE_PDB_NAME/INTERPROCEDURAL_OPTIMIZATION on the final
libnethost/libhostfxr targets don't propagate to linked object
libraries, so the setting must be applied to each object library.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 45e02cdb-c6a2-4e6a-b749-379d4f1600b5
@elinor-fung elinor-fung added this to the 11.0.0 milestone Jul 16, 2026
Copilot AI review requested due to automatic review settings July 16, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

# Embed debug info in the object files (/Z7). CMake does not assign a compile
# PDB to OBJECT libraries, so the objects archived into the shipped libhostfxr
# would otherwise reference an absent vc140.pdb, producing LNK4099 for consumers.
set_target_properties(hostmisc_public PROPERTIES MSVC_DEBUG_INFORMATION_FORMAT Embedded)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the official way to do this? All the other places seem to pass /Z7 instead of this approach. Not sure which way is better, but it would be nice if they all looked the same.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you be able to update the others? Perhaps in a follow up PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

MSVC_DEBUG_INFORMATION_FORMAT was introduced in cmake 3.25. Our minimum is 3.26 now, so we can use it. I'll update the others in a follow-up

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 8 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.
Some pipeline(s) encountered errors during trigger evaluation.

Copilot AI added a commit that referenced this pull request Jul 16, 2026
Per #130933 (comment),
update places using /Z7 directly to use the CMake MSVC_DEBUG_INFORMATION_FORMAT
target property (introduced in CMake 3.25; our minimum is now 3.26).

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libnethost.lib contains references to nonexistent PDB file

3 participants