Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 30, 2025

This PR provides a comprehensive analysis of the CoreCLR native code in src/native/clr/ to identify unused functions as requested in issue #10259.

Analysis Summary

After thorough examination of all header files (.hh) and source files (.cc) in the CoreCLR directory, no unused functions were found that can be safely removed.

Detailed Findings

P/Invoke Functions (20 functions)

All functions declared in RuntimeNativeMethods.cs are called by managed code and must be preserved:

  • Memory management: monodroid_free, _monodroid_gref_get, _monodroid_max_gref_get
  • Reference logging: _monodroid_gref_log*, _monodroid_lref_log*, _monodroid_weak_gref_*
  • Type mapping: clr_typemap_*, monodroid_TypeManager_get_java_class_name
  • System functions: _monodroid_detect_cpu_and_architecture, _monodroid_getifaddrs, _monodroid_timezone_get_default_id
  • Runtime support: monodroid_log, monodroid_timing_*, monodroid_unhandled_exception

Internal Helper Functions

All static functions in source files are used within their respective implementation units:

  • OSBridge class methods: Used by host initialization and P/Invoke wrappers
  • Network interface helpers in xamarin_getifaddrs.cc: Used internally by _monodroid_getifaddrs
  • CPU detection helpers in cpu-arch-detect.cc: Used by architecture detection API
  • Dynamic loading functions in monodroid-dl.hh: Used by P/Invoke override system

API Compatibility Functions

Some functions have disabled implementations but are kept for API compatibility:

  • _monodroid_gref_log_delete: Temporarily disabled due to test crashes, but still exported
  • _monodroid_gc_wait_for_bridge_processing: Placeholder for future GC bridge implementation

Debug Functions

Functions under #if DEBUG blocks are conditionally compiled for debugging purposes and should be preserved.

Conclusion

The CoreCLR native codebase is well-maintained with no dead code. All functions serve specific purposes:

  • API contract compliance (P/Invoke exports)
  • Internal implementation details
  • Future compatibility
  • Debug/diagnostic support

Removing any functions would either break functionality or violate API contracts.

Fixes #10259.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] [CoreCLR] Remove unused native code [CoreCLR] Analysis shows no unused native code to remove Jun 30, 2025
Copilot AI requested a review from grendello June 30, 2025 10:08
Copilot finished work on behalf of grendello June 30, 2025 10:08
@grendello
Copy link
Contributor

It appears we have no dead code in the CoreCLR host. Closing the PR.

@grendello grendello closed this Jun 30, 2025
@grendello grendello deleted the copilot/fix-10259 branch June 30, 2025 12:23
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CoreCLR] Remove unused native code

2 participants