microsoft / microsoft/mimalloc

CMake helper function 'find_link_library' is broken.

Open Beginner friendly
#1,113 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

The current implementation of the custom helper function 'find_link_library' is

function(find_link_library libname outlibname)
  check_linker_flag(C "-l${libname}" mi_has_lib${libname})
  if (mi_has_lib${libname})
    message(VERBOSE "link library: -l${libname}")
    set(${outlibname} ${libname} PARENT_SCOPE)
  else()
    find_library(MI_LIBPATH libname)
    if (MI_LIBPATH)
      message(VERBOSE "link library ${libname} at ${MI_LIBPATH}")
      set(${outlibname} ${MI_LIBPATH} PARENT_SCOPE)
    else()
      message(VERBOSE "link library not found: ${libname}")
      set(${outlibname} "" PARENT_SCOPE)
    endif()
  endif()
endfunction()

As it currently stands, it is 100% broken in the event the linker flag check fails, this is because it passes "libname" instead of "${libname}" to find_library AND will silently abort if MI_LIBPATH is set to a library path already (in a previous call).

To fix this, obviously "libname" -> "${libname}" is required, but one of two solutions can be deployed for the variable situation:

  1. Explicitly set "MI_LIBPATH" to the value "MI_LIBPATH-NOTFOUND" to force find_library to run, this can be a normal variable.
  2. Do what the linker flag check does and append "${libname}" to the test variable: "MI_LIBPATH" -> "MI_LIBPATH${libname}".

Markdown is hiding underscores in the suggested fixes for the MI_LIBPATH variable.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the CMake definition of find_link_library and inspect its fallback path after check_linker_flag fails. Correct the library lookup argument and ensure repeated calls do not reuse a prior result, then configure or build with a missing linker flag to verify the fallback finds the requested library and reports failure correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.