Skip to content

Add check that libnethost contains no LTCG objects - #130937

Merged
elinor-fung merged 2 commits into
dotnet:mainfrom
elinor-fung:nethost-static-lib-ltcg-test
Jul 17, 2026
Merged

elinor-fung merged 2 commits into
dotnet:mainfrom
elinor-fung:nethost-static-lib-ltcg-test

Conversation

@elinor-fung

Copy link
Copy Markdown
Member

We have ended up with LTCG objects in libnethost more than once. Add a CMake linker launcher on the existing nativehost_static test that runs the link and fails the build if MSVC reports "module compiled with /GL found" (similar to the output check in #111651).

cc @dotnet/appmodel @AaronRobinsonMSFT

libnethost is shipped as a static library for external consumption. Objects
compiled with LTCG (/GL) are not native COFF and are rejected by non-MSVC
linkers such as lld-link, so they must never be embedded into it.

Add a CMake linker launcher on the existing nativehost_static test target that
runs the real link and fails the build if MSVC reports "module compiled with
/GL found". nativehost_static is linked with LTCG disabled (so MSVC surfaces the
message) and against hostmisc_public (LTCG disabled) so libnethost is the only
possible source of a /GL object in the link.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 61e02d3c-1880-44e5-9fa0-f9f3b4197ebb
@elinor-fung elinor-fung added this to the 11.0.0 milestone Jul 17, 2026
Copilot AI review requested due to automatic review settings July 17, 2026 00:15
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Pull request overview

This PR adds a build-time verification in the nativehost_static test link step to catch accidental inclusion of LTCG (/GL) objects when building libnethost on MSVC, by wrapping the linker invocation and failing if MSVC emits the “module compiled with /GL found” message.

Changes:

  • Add a CMake linker-launcher script that runs the real link command and fails if MSVC reports LTCG objects were pulled in.
  • Hook the launcher up to nativehost_static on MSVC and disable IPO for that test target to avoid self-inflicted /GL objects.
  • Switch nativehost_static from hostmisc to hostmisc_public (an OBJECT library with IPO disabled) to avoid pulling in LTCG-enabled objects from hostmisc.
Show a summary per file
File Description
src/native/corehost/test/nativehost/run-linker-verify-no-ltcg.cmake New linker launcher that inspects link output for the MSVC /GL restart message and fails the build.
src/native/corehost/test/nativehost/CMakeLists.txt Wires the launcher into nativehost_static on MSVC and adjusts dependencies to avoid LTCG noise from hostmisc.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Co-authored-by: Michal Strehovský <[email protected]>
Co-authored-by: Elinor Fung <[email protected]>
Copilot AI review requested due to automatic review settings July 17, 2026 01:43

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's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

@elinor-fung
elinor-fung merged commit 5245170 into dotnet:main Jul 17, 2026
173 of 177 checks passed
@elinor-fung
elinor-fung deleted the nethost-static-lib-ltcg-test branch July 17, 2026 16:30
@github-project-automation github-project-automation Bot moved this to Done in AppModel Jul 17, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-preview7 Jul 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants