Skip to content

Add shared codeql_canonical_path.dll with Go and Kotlin integrations#22104

Closed
Copilot wants to merge 8 commits into
mainfrom
copilot/add-shared-cpp-library
Closed

Add shared codeql_canonical_path.dll with Go and Kotlin integrations#22104
Copilot wants to merge 8 commits into
mainfrom
copilot/add-shared-cpp-library

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Adds a Windows-only shared native C++ library that canonicalizes paths via GetFinalPathNameByHandleW (resolving subst drives, symlinks, junctions, and filename case), with a thread-safe full-path cache matching the C# extractor's CanonicalPathCache strategy. Consumed by the Kotlin and Go extractors, which previously had no equivalent.

Shared C++ library (shared/canonicalize/)

  • canonicalize.h/cpp: Singleton PathCache with std::shared_mutex for concurrent reads, GetFinalPathNameByHandleW-based resolution, std::mt19937 random eviction at capacity (4096 entries), UNC prefix stripping, and parent-directory fallback for non-existent paths
  • canonicalize_jni.cpp: JNI entry point using the UTF-16 API — no encoding round-trip for Java strings
  • BUILD.bazel: cc_binary (DLL + JNI dep), cc_library, and pkg_files targets; all target_compatible_with = ["@platforms//os:windows"]

Kotlin integration (java/kotlin-extractor/)

  • NativeCanonicalizer.java: Loads the DLL from $CODEQL_DIST/tools/win64/ in a static initializer; silently falls back if unavailable (non-Windows or DLL missing)
  • FileUtil.java: tryMakeCanonical() now routes its result through NativeCanonicalizer.resolve() in both the success and IOException-fallback paths

Go integration (go/extractor/canonicalize/)

  • canonicalize_windows.go: Dynamically loads the DLL via syscall.LoadDLL; calls canonicalize_path_u8 and frees with canonicalize_free_u8 (Go cannot call free() directly across DLL boundary)
  • canonicalize_other.go: Identity no-op on non-Windows
  • go/extractor/extractor.go: normalizedPath() calls canonicalize.CanonicalizePath(path) after filepath.EvalSymlinks
  • go/BUILD.bazel: DLL packaged into tools/{CODEQL_PLATFORM} via a new canonicalize-dll codeql_pkg_files target added to the go pack

- Add shared/canonicalize/ C++ DLL that resolves Windows paths via
  GetFinalPathNameByHandleW with a full-path cache (matching C#'s
  CanonicalPathCache strategy).
- Add JNI interface (canonicalize_jni.cpp) for Kotlin/Java consumers.
- Add NativeCanonicalizer.java to kotlin-extractor for loading the DLL
  and exposing a resolve() method.
- Call NativeCanonicalizer.resolve() in FileUtil.tryMakeCanonical().
- Add go/extractor/canonicalize package (Windows + non-Windows impls).
- Use canonicalize.CanonicalizePath() in go extractor normalizedPath().
- Update Bazel build files for all new targets and deps.
Replace std::rand() with std::mt19937 seeded by std::random_device for
less predictable cache eviction. Also use .first from emplace() instead
of structured binding with ignored second element.
Copilot AI changed the title [WIP] Add shared native C++ library for canonicalizing Windows paths Add shared codeql_canonical_path.dll with Go and Kotlin integrations Jul 1, 2026
Copilot AI requested a review from jketema July 1, 2026 13:02
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.

2 participants