microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.17k stars 6.39k forks source link

[libspatialite] build failure with -fsanitize=address #31630

Closed reid-p closed 3 months ago

reid-p commented 1 year ago

Operating system

Windows 10

Compiler

MSVC

Steps to reproduce the behavior

Add the following to triplet

set(VCPKG_CXX_FLAGS /fsanitize=address)
set(VCPKG_C_FLAGS /fsanitize=address)

then run:
vcpkg install libspatialite

which then fails during nmake link step.

Failure logs

CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:134 (message): Command failed: "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/nmake.exe" /NOLOGO /G /U /F makefile.vc all install INSTALLDIR=C:\Dev\vcpkg-emit\packages\libspatialite_x64-windows-asan\debug /W "CL_FLAGS= /IC:/Dev/vcpkg-emit/installed/x64-windows-asan/debug/../include /IC:/Dev/vcpkg-emit/installed/x64-windows-asan/debug/../include/libxml2 /DLIBXML_STATIC" INST_DIR=C:\\Dev\\vcpkg-emit\\packages\\libspatialite_x64-windows-asan\debug "LIBS_ALL=/LIBPATH:C:/Dev/vcpkg-emit/installed/x64-windows-asan/debug/lib /libpath:C:/Dev/vcpkg-emit/installed/x64-windows-asan/debug/lib geos_c.lib geos.lib libxml2.lib proj_d.lib ole32.lib shell32.lib tiffd.lib jpeg.lib lzma.lib libcurl-d.lib winmm.lib ws2_32.lib advapi32.lib crypt32.lib bcrypt.lib sqlite3.lib zlibd.lib freexl.lib charset.lib iconv.lib iconv.lib charset.lib" LINK_FLAGS=/debug Working Directory: C:/Dev/vcpkg-emit/buildtrees/libspatialite/x64-windows-asan-dbg See logs for more information: C:\Dev\vcpkg-emit\buildtrees\libspatialite\install-x64-windows-asan-dbg-out.log C:\Dev\vcpkg-emit\buildtrees\libspatialite\install-x64-windows-asan-dbg-err.log

Call Stack (most recent call first): scripts/cmake/vcpkg_build_nmake.cmake:158 (vcpkg_execute_build_process) scripts/cmake/vcpkg_install_nmake.cmake:52 (vcpkg_build_nmake) ports/libspatialite/portfile.cmake:85 (vcpkg_install_nmake)

NMAKE : fatal error U1077: 'link /debug /dll /out:spatialite.dll /implib:spatialite_i.lib src\gaiaaux\gg_sqlaux.obj src\gaiaaux\gg_utf8.obj src\gaiaexif\gaia_exif.obj src\gaiageo\gg_advanced.obj src\gaiageo\gg_endian.obj src\gaiageo\gg_ewkt.obj src\gaiageo\gg_geodesic.obj src\gaiageo\gg_geoJSON.obj src\gaiageo\gg_geometries.obj src\gaiageo\gg_geoscvt.obj src\gaiageo\gg_gml.obj src\gaiageo\gg_kml.obj src\gaiageo\gg_relations.obj src\gaiageo\gg_shape.obj src\gaiageo\gg_transform.obj src\gaiageo\gg_vanuatu.obj src\gaiageo\gg_wkb.obj src\gaiageo\gg_wkt.obj src\gaiageo\gg_extras.obj src\gaiageo\gg_xml.obj src\gaiageo\gg_voronoj.obj src\gaiageo\gg_matrix.obj src\gaiageo\gg_relations_ext.obj src\gaiageo\gg_rttopo.obj src/connection_cache/alloc_cache.obj src/connection_cache/gg_sequence.obj src\spatialite\mbrcache.obj src\shapefiles\shapefiles.obj src\spatialite\spatialite.obj src\spatialite\virtualdbf.obj src\spatialite\virtualfdo.obj src\spatialite\virtualnetwork.obj src\spatialite\virtualshape.obj src\spatialite\virtualspatialindex.obj src\spatialite\statistics.obj src\spatialite\metatables.obj src\spatialite\virtualXL.obj src\spatialite\extra_tables.obj src\spatialite\virtualxpath.obj src\spatialite\virtualbbox.obj src\spatialite\spatialite_init.obj src\spatialite\se_helpers.obj src\spatialite\srid_aux.obj src\spatialite\table_cloner.obj src\spatialite\virtualelementary.obj src\spatialite\virtualgeojson.obj src\spatialite\virtualrouting.obj src\spatialite\create_routing.obj src\spatialite\dbobj_scopes.obj src\spatialite\pause.obj src\wfs\wfs_in.obj src\srsinit\srs_init.obj src\spatialite\virtualgpkg.obj src\dxf\dxf_parser.obj src\dxf\dxf_loader.obj src\dxf\dxf_writer.obj src\dxf\dxf_load_distinct.obj src\dxf\dxf_load_mixed.obj src\shapefiles\validator.obj src\md5\md5.obj src\md5\gaia_md5.obj src\srsinit\epsg_inlined_00.obj src\srsinit\epsg_inlined_01.obj src\srsinit\epsg_inlined_02.obj src\srsinit\epsg_inlined_03.obj src\srsinit\epsg_inlined_04.obj src\srsinit\epsg_inlined_05.obj src\srsinit\epsg_inlined_06.obj src\srsinit\epsg_inlined_07.obj src\srsinit\epsg_inlined_08.obj src\srsinit\epsg_inlined_09.obj src\srsinit\epsg_inlined_10.obj src\srsinit\epsg_inlined_11.obj src\srsinit\epsg_inlined_12.obj src\srsinit\epsg_inlined_13.obj src\srsinit\epsg_inlined_14.obj src\srsinit\epsg_inlined_15.obj src\srsinit\epsg_inlined_16.obj src\srsinit\epsg_inlined_17.obj src\srsinit\epsg_inlined_18.obj src\srsinit\epsg_inlined_19.obj src\srsinit\epsg_inlined_20.obj src\srsinit\epsg_inlined_21.obj src\srsinit\epsg_inlined_22.obj src\srsinit\epsg_inlined_23.obj src\srsinit\epsg_inlined_24.obj src\srsinit\epsg_inlined_25.obj src\srsinit\epsg_inlined_26.obj src\srsinit\epsg_inlined_27.obj src\srsinit\epsg_inlined_28.obj src\srsinit\epsg_inlined_29.obj src\srsinit\epsg_inlined_30.obj src\srsinit\epsg_inlined_31.obj src\srsinit\epsg_inlined_32.obj src\srsinit\epsg_inlined_33.obj src\srsinit\epsg_inlined_34.obj src\srsinit\epsg_inlined_35.obj src\srsinit\epsg_inlined_36.obj src\srsinit\epsg_inlined_37.obj src\srsinit\epsg_inlined_38.obj src\srsinit\epsg_inlined_39.obj src\srsinit\epsg_inlined_40.obj src\srsinit\epsg_inlined_41.obj src\srsinit\epsg_inlined_42.obj src\srsinit\epsg_inlined_43.obj src\srsinit\epsg_inlined_44.obj src\srsinit\epsg_inlined_45.obj src\srsinit\epsg_inlined_46.obj src\srsinit\epsg_inlined_47.obj src\srsinit\epsg_inlined_48.obj src\srsinit\epsg_inlined_49.obj src\srsinit\epsg_inlined_50.obj src\srsinit\epsg_inlined_51.obj src\srsinit\epsg_inlined_52.obj src\srsinit\epsg_inlined_53.obj src\srsinit\epsg_inlined_54.obj src\srsinit\epsg_inlined_55.obj src\srsinit\epsg_inlined_56.obj src\srsinit\epsg_inlined_57.obj src\srsinit\epsg_inlined_58.obj src\srsinit\epsg_inlined_59.obj src\srsinit\epsg_inlined_extra.obj src\srsinit\epsg_inlined_prussian.obj src\srsinit\epsg_inlined_wgs84_00.obj src\srsinit\epsg_inlined_wgs84_01.obj src\versioninfo\version.obj src\virtualtext\virtualtext.obj src\cutter\gaia_cutter.obj src\spatialite\virtualknn.obj src\control_points\gaia_control_points.obj src\control_points\grass_crs3d.obj src\control_points\grass_georef_tps.obj src\control_points\grass_georef.obj src\stored_procedures\stored_procedures.obj src\geopackage\gaia_cvt_gpkg.obj src\geopackage\gpkgAddGeometryColumn.obj src\geopackage\gpkg_add_geometry_triggers.obj src\geopackage\gpkg_add_spatial_index.obj src\geopackage\gpkg_add_tile_triggers.obj src\geopackage\gpkgBinary.obj src\geopackage\gpkgCreateBaseTables.obj src\geopackage\gpkgCreateTilesTable.obj src\geopackage\gpkgCreateTilesZoomLevel.obj src\geopackage\gpkgGetImageType.obj src\geopackage\gpkg_get_normal_row.obj src\geopackage\gpkg_get_normal_zoom.obj src\geopackage\gpkgInsertEpsgSRID.obj src\geopackage\gpkgMakePoint.obj src\topology\gaia_auxnet.obj src\topology\gaia_auxtopo.obj src\topology\gaia_auxtopo_table.obj src\topology\gaia_netstmts.obj src\topology\gaia_network.obj src\topology\gaia_topology.obj src\topology\gaia_topostmts.obj src\topology\lwn_network.obj src\topology\net_callbacks.obj src\topology\topo_callbacks.obj /LIBPATH:C:/Dev/vcpkg-emit/installed/x64-windows-asan/debug/lib /libpath:C:/Dev/vcpkg-emit/installed/x64-windows-asan/debug/lib geos_c.lib geos.lib libxml2.lib proj_d.lib ole32.lib shell32.lib tiffd.lib jpeg.lib lzma.lib libcurl-d.lib winmm.lib ws2_32.lib advapi32.lib crypt32.lib bcrypt.lib sqlite3.lib zlibd.lib freexl.lib charset.lib iconv.lib iconv.lib charset.lib' : return code '0x486' Stop.

Additional context

The problem can be replicated from the MSVC command line if -INCREMENTAL linking is enabled. vcpkg is setting this flag via a LINK environment variable. LINK : warning LNK4300: ignoring '/INCREMENTAL' because input module contains ASAN metadata

This seems to result in some link crash.

The following are set from the vcpkg scripts when nmake is run CL=-nologo -DWIN32 -D_WINDOWS -W3 -utf-8 -MP -fsanitize=address -D_DEBUG -MTd -Z7 -Ob0 -Od -RTC1 LINK=-machine:x64 -nologo -debug -INCREMENTAL

I've tried overriding this with: set(VCPKG_LINKER_FLAGS /INCREMENTAL:NO)

But this gives an environemtn of LINK=-machine:x64 -nologo -INCREMENTAL:NO -debug -INCREMENTAL

And the last -INCREMENTAL option get used.

I can't find where the "-debug -INCREMENTAL" are set by the vcpkg build system to override / disable the -INCREMENTAL for this build. grepping for INCREMENTAL hasn't got me to anything useful. The variable first seems to appear in the generated: cmake-vars-.cmake.log file that the vcpkg nmake stuff pulls in. This is generated from the "-- Getting CMake variables for " step from vcpkg_configure_cmake function.

Any help on how to disable "-INCREMENTAL" for debug build would be appreciated. So far this is the only package I've had trouble build with the santizer enabled.

dg0yt commented 1 year ago

Any help on how to disable "-INCREMENTAL" for debug build would be appreciated.

AFAICT the flag comes directly from CMake's Modules/Platform/Windows-MSVC.cmake where it becomes part of CMAKE_<LANG>_LINKER_FLAGS_DEBUG_INIT. Note that this is not in C/CXX flags. Try overriding VCPKG_LINKER_FLAGS or VCPKG_LINKER_FLAGS_DEBUG - these variables are appended to the linker flags in scripts/toolchains/windows.cmake.

reid-p commented 1 year ago

Yeap I tried those flags.

I've tried overriding this with: set(VCPKG_LINKER_FLAGS /INCREMENTAL:NO) and set(VCPKG_LINKER_FLAGS_DEBUG /INCREMENTAL:NO)

But this gives an environmemt of LINK=-machine:x64 -nologo -INCREMENTAL:NO -debug -INCREMENTAL

Thanks for the file link. I can't see a path there to disable it from vcpkg. But I should at least be able to hack things for a build.

JonLiu1993 commented 1 year ago

This issue could be reproduced with vcpkg 2023-04-07-bedcba5172f5e4b91caac660ab7afe92c27a9895 and VS2022 17.5.4:

cl : Command line warning D9025 : overriding '/W4' with '/W3'
cl : Command line warning D9025 : overriding '/W4' with '/W3'
cl : Command line warning D9025 : overriding '/W4' with '/W3'
cl : Command line warning D9025 : overriding '/W4' with '/W3'
NMAKE : fatal error U1077: 'link /debug /dll /out:spatialite.dll  /implib:spatialite_i.lib src\gaiaaux\gg_sqlaux.obj src\gaiaaux\gg_utf8.obj  src\gaiaexif\gaia_exif.obj src\gaiageo\gg_advanced.obj  src\gaiageo\gg_endian.obj src\gaiageo\gg_ewkt.obj  src\gaiageo\gg_geodesic.obj src\gaiageo\gg_geoJSON.obj  src\gaiageo\gg_geometries.obj src\gaiageo\gg_geoscvt.obj  src\gaiageo\gg_gml.obj src\gaiageo\gg_kml.obj  src\gaiageo\gg_relations.obj src\gaiageo\gg_shape.obj  src\gaiageo\gg_transform.obj src\gaiageo\gg_vanuatu.obj  src\gaiageo\gg_wkb.obj src\gaiageo\gg_wkt.obj  src\gaiageo\gg_extras.obj src\gaiageo\gg_xml.obj  src\gaiageo\gg_voronoj.obj src\gaiageo\gg_matrix.obj  src\gaiageo\gg_relations_ext.obj src\gaiageo\gg_rttopo.obj  src/connection_cache/alloc_cache.obj src/connection_cache/gg_sequence.obj  src\spatialite\mbrcache.obj src\shapefiles\shapefiles.obj  src\spatialite\spatialite.obj src\spatialite\virtualdbf.obj  src\spatialite\virtualfdo.obj src\spatialite\virtualnetwork.obj  src\spatialite\virtualshape.obj src\spatialite\virtualspatialindex.obj  src\spatialite\statistics.obj src\spatialite\metatables.obj  src\spatialite\virtualXL.obj src\spatialite\extra_tables.obj  src\spatialite\virtualxpath.obj src\spatialite\virtualbbox.obj  src\spatialite\spatialite_init.obj src\spatialite\se_helpers.obj  src\spatialite\srid_aux.obj src\spatialite\table_cloner.obj  src\spatialite\virtualelementary.obj src\spatialite\virtualgeojson.obj  src\spatialite\virtualrouting.obj src\spatialite\create_routing.obj  src\spatialite\dbobj_scopes.obj src\spatialite\pause.obj  src\wfs\wfs_in.obj src\srsinit\srs_init.obj src\spatialite\virtualgpkg.obj  src\dxf\dxf_parser.obj src\dxf\dxf_loader.obj src\dxf\dxf_writer.obj  src\dxf\dxf_load_distinct.obj src\dxf\dxf_load_mixed.obj  src\shapefiles\validator.obj src\md5\md5.obj src\md5\gaia_md5.obj  src\srsinit\epsg_inlined_00.obj src\srsinit\epsg_inlined_01.obj  src\srsinit\epsg_inlined_02.obj src\srsinit\epsg_inlined_03.obj  src\srsinit\epsg_inlined_04.obj src\srsinit\epsg_inlined_05.obj  src\srsinit\epsg_inlined_06.obj src\srsinit\epsg_inlined_07.obj  src\srsinit\epsg_inlined_08.obj src\srsinit\epsg_inlined_09.obj  src\srsinit\epsg_inlined_10.obj src\srsinit\epsg_inlined_11.obj  src\srsinit\epsg_inlined_12.obj src\srsinit\epsg_inlined_13.obj  src\srsinit\epsg_inlined_14.obj src\srsinit\epsg_inlined_15.obj  src\srsinit\epsg_inlined_16.obj src\srsinit\epsg_inlined_17.obj  src\srsinit\epsg_inlined_18.obj src\srsinit\epsg_inlined_19.obj  src\srsinit\epsg_inlined_20.obj src\srsinit\epsg_inlined_21.obj  src\srsinit\epsg_inlined_22.obj src\srsinit\epsg_inlined_23.obj  src\srsinit\epsg_inlined_24.obj src\srsinit\epsg_inlined_25.obj  src\srsinit\epsg_inlined_26.obj src\srsinit\epsg_inlined_27.obj  src\srsinit\epsg_inlined_28.obj src\srsinit\epsg_inlined_29.obj  src\srsinit\epsg_inlined_30.obj src\srsinit\epsg_inlined_31.obj  src\srsinit\epsg_inlined_32.obj src\srsinit\epsg_inlined_33.obj  src\srsinit\epsg_inlined_34.obj src\srsinit\epsg_inlined_35.obj  src\srsinit\epsg_inlined_36.obj src\srsinit\epsg_inlined_37.obj  src\srsinit\epsg_inlined_38.obj src\srsinit\epsg_inlined_39.obj  src\srsinit\epsg_inlined_40.obj src\srsinit\epsg_inlined_41.obj  src\srsinit\epsg_inlined_42.obj src\srsinit\epsg_inlined_43.obj  src\srsinit\epsg_inlined_44.obj src\srsinit\epsg_inlined_45.obj  src\srsinit\epsg_inlined_46.obj src\srsinit\epsg_inlined_47.obj  src\srsinit\epsg_inlined_48.obj src\srsinit\epsg_inlined_49.obj  src\srsinit\epsg_inlined_50.obj src\srsinit\epsg_inlined_51.obj  src\srsinit\epsg_inlined_52.obj src\srsinit\epsg_inlined_53.obj  src\srsinit\epsg_inlined_54.obj src\srsinit\epsg_inlined_55.obj  src\srsinit\epsg_inlined_56.obj src\srsinit\epsg_inlined_57.obj  src\srsinit\epsg_inlined_58.obj src\srsinit\epsg_inlined_59.obj  src\srsinit\epsg_inlined_extra.obj src\srsinit\epsg_inlined_prussian.obj  src\srsinit\epsg_inlined_wgs84_00.obj src\srsinit\epsg_inlined_wgs84_01.obj  src\versioninfo\version.obj src\virtualtext\virtualtext.obj  src\cutter\gaia_cutter.obj src\spatialite\virtualknn.obj  src\control_points\gaia_control_points.obj  src\control_points\grass_crs3d.obj src\control_points\grass_georef_tps.obj  src\control_points\grass_georef.obj src\stored_procedures\stored_procedures.obj  src\geopackage\gaia_cvt_gpkg.obj  src\geopackage\gpkgAddGeometryColumn.obj  src\geopackage\gpkg_add_geometry_triggers.obj  src\geopackage\gpkg_add_spatial_index.obj  src\geopackage\gpkg_add_tile_triggers.obj  src\geopackage\gpkgBinary.obj  src\geopackage\gpkgCreateBaseTables.obj  src\geopackage\gpkgCreateTilesTable.obj  src\geopackage\gpkgCreateTilesZoomLevel.obj  src\geopackage\gpkgGetImageType.obj  src\geopackage\gpkg_get_normal_row.obj  src\geopackage\gpkg_get_normal_zoom.obj  src\geopackage\gpkgInsertEpsgSRID.obj  src\geopackage\gpkgMakePoint.obj  src\topology\gaia_auxnet.obj src\topology\gaia_auxtopo.obj  src\topology\gaia_auxtopo_table.obj src\topology\gaia_netstmts.obj  src\topology\gaia_network.obj src\topology\gaia_topology.obj  src\topology\gaia_topostmts.obj src\topology\lwn_network.obj  src\topology\net_callbacks.obj src\topology\topo_callbacks.obj  /LIBPATH:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib /libpath:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib geos_c.lib libxml2.lib /libpath:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib /libpath:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib zlibd.lib proj_d.lib /libpath:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib tiffd.lib /libpath:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib /libpath:F:/Feature-test/port-bug/vcpkg/installed/x64-windows/debug/lib jpeg.lib lzma.lib libcurl-d.lib sqlite3.lib zlibd.lib freexl.lib iconv.lib charset.lib iconv.lib charset.lib' : return code '0x493'
Stop.
dg0yt commented 1 year ago

But this gives an environmemt of LINK=-machine:x64 -nologo -INCREMENTAL:NO -debug -INCREMENTAL

Hm, CMake seems to append its default flags after the triplet's flags. It could be quite invasive to solve this in general.

Since you already touch the triplet file, you can use a specific hook:

github-actions[bot] commented 11 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

github-actions[bot] commented 3 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.