Skip to content

[CI][sqlite3][nss] fix missing -lm#50514

Closed
JavierMatosD wants to merge 19 commits into
microsoft:masterfrom
JavierMatosD:fix_nss
Closed

[CI][sqlite3][nss] fix missing -lm#50514
JavierMatosD wants to merge 19 commits into
microsoft:masterfrom
JavierMatosD:fix_nss

Conversation

@JavierMatosD

@JavierMatosD JavierMatosD commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

When nss links libsoftokn3.so against libsqlite3.a, the linker sees unresolved references to all the math symbols that sqlite3 pulled in, because -lm was never passed.

On x64-linux native builds this went undetected because the host runs Ubuntu 24.04 with glibc 2.39, where libm has been merged into libc.so.6 and math symbols are satisfied implicitly. The aarch64 cross-compilation sysroot (gcc-12-aarch64-linux-gnu) uses glibc 2.36, where libm is still a separate library, so the missing -lm is a hard linker error.

Reference: https://developers.redhat.com/articles/2021/12/17/why-glibc-234-removed-libpthread - covers the glibc consolidation effort; libm was completed after 2.34 and fully merged by the time Ubuntu 24.04 shipped glibc 2.39.

@JavierMatosD JavierMatosD changed the title [sqlite3][nss] fix -lm missing from pkg-config Libs for static builds with math/fts5 [CI][sqlite3][nss] fix -lm missing from pkg-config Libs for static builds with math/fts5 Mar 17, 2026
@JavierMatosD

Copy link
Copy Markdown
Contributor Author

I got the same build error in this run. I'm going to bump the nss port version to force a rebuild.

@JavierMatosD JavierMatosD marked this pull request as draft March 17, 2026 18:45
@JavierMatosD JavierMatosD changed the title [CI][sqlite3][nss] fix -lm missing from pkg-config Libs for static builds with math/fts5 [CI][nss] fix -lm missing from pkg-config Libs for static builds with math/fts5 Mar 17, 2026
@JavierMatosD JavierMatosD changed the title [CI][nss] fix -lm missing from pkg-config Libs for static builds with math/fts5 [CI][nss] fix -lm missing Mar 17, 2026
@BillyONeal

Copy link
Copy Markdown
Member

sqlite3 is who is using the math symbols so I think that's who needs -lm in their .pc

@JavierMatosD JavierMatosD changed the title [CI][nss] fix -lm missing [CI][sqlite3][nss] fix -lm missing Mar 17, 2026
Comment thread ports/nss/portfile.cmake Outdated
Comment on lines +199 to +201
# Convert CMake list (semicolons) to space-separated string so the
# entire value stays as one token inside "-Dxxx_libs=..." arguments.
list(JOIN ${out_var} " " ${out_var})

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.

No... This loop is about parsing space-separated pkg-config output into a cmake list. If you can't pass it into cmake arguments, your cmake arguments lack proper quotes. (We do it everywhere in vcpkg ports. e.g. passing FEATURES in test ports.)

Comment thread ports/sqlite3/CMakeLists.txt Outdated
if(HAVE_LIBM)
target_link_libraries(sqlite3-bin PRIVATE m)
endif()
target_link_libraries(sqlite3-bin PRIVATE m)

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.

Start relying on toolchains providing a libm placeholder even if they integrated the math into the C library?

@JavierMatosD JavierMatosD changed the title [CI][sqlite3][nss] fix -lm missing [CI][sqlite3][nss][spatialite-tools] fix missing -lm Mar 18, 2026
Comment thread ports/nss/portfile.cmake
Comment on lines 160 to 200
x_vcpkg_pkgconfig_get_modules(PREFIX PC_NSPR MODULES nspr CFLAGS LIBS)
x_vcpkg_pkgconfig_get_modules(PREFIX PC_SQLITE MODULES sqlite3 CFLAGS LIBS)
x_vcpkg_pkgconfig_get_modules(PREFIX PC_ZLIB MODULES zlib CFLAGS LIBS)
# Produce absolute include dirs and library dirs filepaths.
# Manually managing MSVC syntax because gyp converts foo.lib as if it were a relative path.
foreach(key IN ITEMS NSPR_CFLAGS_RELEASE SQLITE_CFLAGS_RELEASE ZLIB_CFLAGS_RELEASE)
separate_arguments(cflags UNIX_COMMAND "${PC_${key}}")
string(REPLACE "CFLAGS_RELEASE" "INCLUDE_DIRS" out_var "${key}")
set(${out_var} "")
foreach(item IN LISTS cflags)
if(item MATCHES "^-I(.*)")
cmake_path(SET dir NORMALIZE "${CMAKE_MATCH_1}")
if(CMAKE_HOST_WIN32)
cygpath_u(dir "${dir}")
else()
endif()
list(APPEND ${out_var} "${dir}")
endif()
endforeach()
list(JOIN ${key}_INCLUDE_DIRS ":" ${key}_INCLUDE_DIRS)
endforeach()
foreach(out_var IN ITEMS NSPR_LIBS_RELEASE NSPR_LIBS_DEBUG SQLITE_LIBS_RELEASE SQLITE_LIBS_DEBUG ZLIB_LIBS_RELEASE ZLIB_LIBS_DEBUG)
separate_arguments(libs UNIX_COMMAND "${PC_${out_var}}")
set(${out_var} "")
foreach(item IN LISTS libs)
if(item MATCHES "^-L(.*)")
cmake_path(SET dir NORMALIZE "${CMAKE_MATCH_1}")
if(CMAKE_HOST_WIN32)
cygpath_u(dir "${dir}")
endif()
if(VCPKG_DETECTED_MSVC)
list(APPEND ${out_var} "-LIBPATH:${dir}")
string(APPEND ${out_var} " -LIBPATH:${dir}")
else()
list(APPEND ${out_var} "-L${dir}")
string(APPEND ${out_var} " -L${dir}")
endif()
elseif(item MATCHES "^-l(.*)")
list(APPEND ${out_var} "${item}")
string(APPEND ${out_var} " ${item}")
endif()
endforeach()
string(STRIP "${${out_var}}" ${out_var})
endforeach()

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.

This seems to implement for LIBS what ports could delegate to x_vcpkg_pkgconfig_get_modules by USE_MSVC_SYNTAX_ON_WINDOWS.
(But I see that CFLAGS is really processed differently.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

gyp mishandles MSVC-style .lib paths (e.g. ..\sqlite\sqlite3.lib) as
relative paths from the build directory. The manual loop correctly
produces Unix-style -L/-l flags on all platforms, which gyp expects.

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.

Oh, this is one of the ports which use a vendored configure script as glue to nss/build.sh.

@JavierMatosD JavierMatosD marked this pull request as ready for review March 19, 2026 13:06
@JavierMatosD JavierMatosD changed the title [CI][sqlite3][nss][spatialite-tools] fix missing -lm [CI][sqlite3][nss][spatialite-tools][sdl3-mixer] fix missing -lm Mar 19, 2026

@dg0yt dg0yt 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.

Title still says "spatialite-tools" but it is no longer touched by this PR.
sqlite3 could be a separate PR. I still disagree with (proliferating) unchecked use of libm.
sdl3-mixer is an independent change, too.

endforeach()

if(SQLITE_ENABLE_FTS5 OR SQLITE_ENABLE_MATH_FUNCTIONS)
find_library(HAVE_LIBM m)

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.

IIRC the problem with find_library(HAVE_LIBM m) is that CMake searchs for a file in a set of paths which do not include CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That seems to work in JavierMatosD#4

@vicroms

vicroms commented Mar 23, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@JavierMatosD JavierMatosD changed the title [CI][sqlite3][nss][spatialite-tools][sdl3-mixer] fix missing -lm [CI][sqlite3][nss] fix missing -lm Mar 25, 2026
@BillyONeal

Copy link
Copy Markdown
Member

What do you think of JavierMatosD#4 ?

@vicroms vicroms marked this pull request as draft April 2, 2026 19:49
@dg0yt dg0yt mentioned this pull request Apr 24, 2026
13 tasks
@dg0yt

dg0yt commented May 6, 2026

Copy link
Copy Markdown
Contributor

Please finish this PR. The sqlite3 issue is getting a blocker, in particular with sqlite3.

Either always link m on `UNIX. (Many packages do that. Toolchains do the right thing.)
Or use find_library with implicit link libraries. (Some packages/ports. This is how most toolchains do the right thing.)
Or use check_library_exists. (Or better don't. You would need to know a symbol to test for, and some targets may put that symbol in libc.)

IOW I agree with the proposed changes to sqlite3 as is.

@BillyONeal

BillyONeal commented May 7, 2026

Copy link
Copy Markdown
Member

@dg0yt It's unlikely that this will be finished; Javier is no longer at Microsoft.

EDIT: I suppose I could resurrect it myself...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants