Skip to content

cmake: reposition ws2_32 to make binutils ld work again - #827

Merged
vszakats merged 1 commit into
libssh2:masterfrom
vszakats:cmake-binutils-ld-refix
Mar 8, 2023
Merged

vszakats merged 1 commit into
libssh2:masterfrom
vszakats:cmake-binutils-ld-refix

Conversation

@vszakats

@vszakats vszakats commented Mar 8, 2023 •

Copy link
Copy Markdown
Member

This restores socket libs to their pre-regression positions.

Without this, ld doesn't find ws2_32 symbols when referenced from TLS libs.

Regression from 31fb886

@vszakats
vszakats force-pushed the cmake-binutils-ld-refix branch from cfe660a to d01d387 Compare March 8, 2023 16:06
@vszakats vszakats changed the title cmake: reposition ws2_32 to make binutils ld work cmake: reposition ws2_32 to make binutils ld work again Mar 8, 2023
This restores socket libs to their pre-regression positions.

Without this, `ld` doesn't find `ws2_32` symbols when referenced
from TLS libs.

Regression from 31fb886
@vszakats
vszakats force-pushed the cmake-binutils-ld-refix branch from d01d387 to 2616ebb Compare March 8, 2023 17:52
@vszakats vszakats changed the title cmake: reposition ws2_32 to make binutils ld work again cmake: reposition ws2_32 to make binutils ld work again Mar 8, 2023
@vszakats
vszakats merged commit 33b6d5f into libssh2:master Mar 8, 2023
@vszakats
vszakats deleted the cmake-binutils-ld-refix branch March 8, 2023 23:41
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
This restores socket libs to their pre-regression positions.

Without this, `ld` doesn't find `ws2_32` symbols when referenced
from TLS libs.

Regression from 31fb886
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jul 13, 2025
The `libssh2.pc` generator logic automatically adds `-lws2_32` while
parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard
the duplicate.

This change introduces a change in the position of `ws2_32` within
the lib list.

This order might in cases by significant, but:

- libssh2 no longer links against `libssl`, which was the library
  also referencing `ws2_32` and breaking picky binutils `ld` linker
  when not passed in strict dependency order.
  Ref: c84745e libssh2#1128

- since switching to INTERFACE targets, cmake messes up the lib order
  anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did
  not seem to cause an issue so far.
  Ref: df0563a libssh2#1535

Ref: 33b6d5f libssh2#827
Ref: 31fb886 libssh2#811
vszakats added a commit that referenced this pull request Jul 13, 2025
The `libssh2.pc` generator logic automatically adds `-lws2_32` while
parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard
the duplicate.

This patch introduces a change in the position of `ws2_32` within
the lib list advertised via `libssh2.pc` for static builds.

This order might in cases by significant, but:

- libssh2 no longer links against `libssl`, which was the library
  also referencing `ws2_32` and breaking picky binutils `ld` linker
  when not passed in strict dependency order.
  Ref: c84745e #1128

- since switching to INTERFACE targets, cmake messes up the lib order
  anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did
  not seem to cause an issue so far.
  Ref: df0563a #1535

For these reasons it seems unlikely this position change could break
Windows OpenSSL static gcc/ld builds relying on `libssh2.pc` for their
lib list. It least no more than it was before this patch.

Turns out these theories don't stand in practice and the order is broken
possibly by introducing INTERFACE targets, with or without this patch.
`libcrypto` (tested with LibreSSL) is in fact depending on `ws2_32`, and
the `bcrypt` dependency is also causing breakage with picky binutils ld.
I may try addressing it in a separate PR.

Ref: 33b6d5f #827
Ref: 31fb886 #811

Closes #1619
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.

1 participant