Skip to content

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

Merged
elinor-fung merged 1 commit into
dotnet:mainfrom
elinor-fung:host-embed-debuginfo-lnk4099
Jul 20, 2026
Merged

Embed debug info in host object libraries to avoid LNK4099#130933
elinor-fung merged 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.

Comment thread src/native/corehost/hostmisc/CMakeLists.txt
@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.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "82aa71ce7a53ac714aacf4328f25e12ebb87110b",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "e0e5f8304a80337e9d9ce2f8696dce994b8335a8",
  "last_reviewed_commit": "82aa71ce7a53ac714aacf4328f25e12ebb87110b",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "e0e5f8304a80337e9d9ce2f8696dce994b8335a8",
  "last_recorded_worker_run_id": "29685649080",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "82aa71ce7a53ac714aacf4328f25e12ebb87110b",
      "review_id": 4730701015
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: The object libraries (minipal_objects, hostmisc_public, hostmisc_c) archived into the shipped static libraries libnethost.lib and libhostfxr.lib referenced an external vc140.pdb. Because CMake does not assign a compile PDB to OBJECT libraries, consumers who link these static libraries get LNK4099 warnings for the absent PDB. This fixes #116527.

Approach: Set MSVC_DEBUG_INFORMATION_FORMAT Embedded (i.e. /Z7) on the three affected targets under an if (MSVC) guard, so debug info is embedded directly in the object files instead of referencing an external PDB. This mirrors the existing precedent in NativeAOT (src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt) and the cDAC descriptor, as noted in the PR description.

Summary: The change is minimal, correctly scoped to MSVC only, and well-commented explaining the rationale. The MSVC_DEBUG_INFORMATION_FORMAT abstract property is honored here because the repo sets CMAKE_MSVC_DEBUG_INFORMATION_FORMAT globally in eng/native/configurecompiler.cmake (activating CMP0141), and the minimum CMake version (3.26) supports the property. Embedded only affects the static/object outputs' debug format and does not regress the normal PDB generation for the final shared libraries, which are separate link targets. The three targets modified are exactly those documented as being archived into the shipped static libraries. No correctness, portability, or maintainability concerns. LGTM.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 41.3 AIC · ⌖ 14.4 AIC · ⊞ 10K

@elinor-fung

Copy link
Copy Markdown
Member Author

/ba-g failures were #130961

@elinor-fung

Copy link
Copy Markdown
Member Author

@dotnet-policy-service rerun

@elinor-fung
elinor-fung merged commit d7c897e into dotnet:main Jul 20, 2026
182 of 186 checks passed
@elinor-fung
elinor-fung deleted the host-embed-debuginfo-lnk4099 branch July 20, 2026 17:44
elinor-fung added a commit that referenced this pull request Jul 22, 2026
Follow-up to #130933: convert the `/Z7` compile options on the CoreCLR
cDAC data descriptor and NativeAOT GC OBJECT libraries to the
`MSVC_DEBUG_INFORMATION_FORMAT Embedded` target property. The property
(added in CMake 3.25) is usable now that the repo minimum is 3.26.

Also remove setting `COMPILE_PDB_NAME` for the cDAC descriptor, since it
is embedded rather than a separate PDB.
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