Skip to content

[Comgr] test-unit: prefer LLVM-installed gtest over find_package#2618

Open
lamb-j wants to merge 1 commit into
amd-stagingfrom
users/lambj/comgr-gtest-discovery-reorder
Open

[Comgr] test-unit: prefer LLVM-installed gtest over find_package#2618
lamb-j wants to merge 1 commit into
amd-stagingfrom
users/lambj/comgr-gtest-discovery-reorder

Conversation

@lamb-j
Copy link
Copy Markdown
Collaborator

@lamb-j lamb-j commented May 20, 2026

Fixes #2505.

amd/comgr/test-unit/CMakeLists.txt ran find_package(GTest CONFIG) before scanning LLVM_LIBRARY_DIRS. find_package searches CMake's default paths and picks up a system gtest at /usr/local that isn't -fPIC, breaking PIE link of the test binaries on standalone Comgr ASAN builds.

Swap paths #2 and #3 so the NO_DEFAULT_PATH scan of LLVM_LIBRARY_DIRS runs first. New order:

  1. In-tree llvm_gtest target (CI) — unchanged.
  2. LLVM-installed gtest in LLVM_LIBRARY_DIRS (NO_DEFAULT_PATH) — now ahead of find_package, so it can never grab /usr/local.
  3. find_package(GTest CONFIG) — TheRock's path (therock-googletest via CMAKE_PREFIX_PATH), unchanged for superproject builds since TheRock's amd-llvm doesn't ship llvm_gtest.

CMake-only. Standalone Comgr builds need LLVM rebuilt with -DLLVM_INSTALL_GTEST=ON to use path #2.

Reorder the GTest discovery in amd/comgr/test-unit/CMakeLists.txt so the
NO_DEFAULT_PATH find_library scan of LLVM_LIBRARY_DIRS runs before the
unscoped find_package(GTest CONFIG).

The previous order let find_package(GTest CONFIG) intercept first and
pick up a system gtest at /usr/local that wasn't built with -fPIC,
breaking the PIE link of the test-unit binaries when building Comgr
standalone with -DADDRESS_SANITIZER=On against an installed ROCm
(#2505).

The new order keeps every existing path working:

  1. In-tree llvm_gtest target (LLVM monorepo build, e.g. CI) - unchanged
  2. LLVM-installed gtest in LLVM_LIBRARY_DIRS (NO_DEFAULT_PATH) - now
     runs before find_package, so a standalone Comgr build picks the
     LLVM-supplied gtest when LLVM was built with -DLLVM_INSTALL_GTEST=ON
  3. find_package(GTest CONFIG) - still the path TheRock uses to find
     therock-googletest via CMAKE_PREFIX_PATH; no change for superproject
     builds since TheRock's amd-llvm doesn't ship llvm_gtest

No source/test changes; CMake-only.
Copy link
Copy Markdown

@chinmaydd chinmaydd left a comment

Choose a reason for hiding this comment

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

Makes sense. I believe it shouldnt have any impact on Windows builds either, will keep an eye out on the CI

@chinmaydd chinmaydd added the comgr Related to Code Object Manager label May 20, 2026
Copy link
Copy Markdown

@accauble accauble left a comment

Choose a reason for hiding this comment

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

Worked! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comgr Related to Code Object Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: [comgr] Hotswap unit test failing during a build with -DADDRESS_SANITIZER=On

3 participants