Skip to content

Commit

Permalink
Put libmd last in relayd's link order
Browse files Browse the repository at this point in the history
libmd and libcrypto define some identical symbols, but they are not
source-compatible since libmd's functions do not have a return value,
while libcrypto's implementations always return 0.  OpenSSL checks these
return values, so when using libmd's implementations, it can fail in
mysterious ways.  Normally it's not a problem since libmd provides weak
symbols so if libmd.so and libcrypto.so are both linked, libcrypto's
implementations will be used.

FreeBSD's net/relayd port changes relayd's link line to statically link
LibreSSL.  It looks like this after patching:

LDADD= -lmd -L${PREFIX}/lib ${LIBEVENT} /usr/local/lib/libssl.a /usr/local/lib/libcrypto.a

When mixing libmd.so with the libcrypto.a archive like this, libmd's
symbols are used by LibreSSL, resulting in strange crashes.  Link
ordering rules are not really well defined when mixing dynamically and
statically linked libraries like this, as far as I know.  Moving libmd
to the end of the link order fixes the problem, so this diff fixes the
problem by doing just that.
  • Loading branch information
markjdb committed Sep 23, 2022
1 parent 6a8d078 commit 7372b73
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/usr.sbin/relayd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../lib/libutil \
-I${.CURDIR}/../../../libevent
CLEANFILES+= y.tab.h

LDADD= -lmd -L${PREFIX}/lib ${LIBEVENT} -lssl -lcrypto
LDADD= -L${PREFIX}/lib ${LIBEVENT} -lssl -lcrypto -lmd
DPADD= ${LIBEVENT} ${LIBSSL} ${LIBCRYPTO}

.include <bsd.prog.mk>

0 comments on commit 7372b73

Please sign in to comment.