LIBADD woes, trying to build wpa out of tree

From: Marcin Cieslak <saper_at_saper.info>
Date: Fri, 12 Jan 2024 01:15:34 UTC
Hello,

here is what I am trying to do (amd64 -CURRENT from 24 Dec 2023, 488e8a7faca5):

I want to build a local copy of /usr/src/contrib/wpa to test my changes
and would like to keep /usr/src /usr/obj from my -CURRENT as they were
after the buildworld.

The code seems to compile fine, the linking stage fails because
the linker does not know how to find libraries - LDADD given
seem to be incomplete, as are .depend files.
An example of a linking stage failure is at the end of this email.

Here is how I try to achieve the out of tree build in a quick and dirty way:

/usr/src/usr.sbin/wpa gets copied to /big/sw/hostap/build
/usr/src/share/mk/src.opts.mk gets copied to /big/sw/hostap/build
/big/sw/hostap/build/site.src.opt.mk is this:

MK_OPENSSL=yes
MK_WPA_SUPPLICANT_EAPOL=yes
MK_EXAMPLES=yes
MK_INET6=yes
BINDIR=/usr/local/sbin
#WPA_DISTDIR=/big/sw/hostap
WPA_DISTDIR=/usr/src/contrib/wpa

make depend looks like this:

Script started on Fri Jan 12 01:39:14 2024
Command: make -m /big/sw/hostap/build -m /usr/share/mk depend
===> src (depend)
===> src/ap (depend)
===> src/common (depend)
===> src/crypto (depend)
===> src/drivers (depend)
===> src/eap_common (depend)
===> src/eap_peer (depend)
===> src/eap_server (depend)
===> src/eapol_auth (depend)
===> src/eapol_supp (depend)
===> src/l2_packet (depend)
===> src/radius (depend)
===> src/rsn_supp (depend)
===> src/tls (depend)
===> src/utils (depend)
===> src/wps (depend)
===> wpa_supplicant (depend)
echo wpa_supplicant.full: /usr/lib/libc.a  >> .depend
===> wpa_cli (depend)
echo wpa_cli.full: /usr/lib/libc.a  >> .depend
===> wpa_passphrase (depend)
echo wpa_passphrase.full: /usr/lib/libc.a  >> .depend
===> hostapd (depend)
echo hostapd.full: /usr/lib/libc.a  >> .depend
===> hostapd_cli (depend)
echo hostapd_cli.full: /usr/lib/libc.a  >> .depend

Command exit status: 0
Script done on Fri Jan 12 01:39:15 2024

When building world however, this is how the dependency
generation for wpa_supplicant.full looks like:

echo wpa_supplicant.full: /big/obj/usr/src/amd64.amd64/tmp/usr/lib/libc.a /big/obj/usr/src/amd64.amd64/tmp/usr/lib/libssl.a /big/obj/usr/src/amd64.amd64/tmp/usr/lib/libcrypto.a /big/obj/usr/src/amd64.amd64/tmp/usr/lib/libpcap.a /big/obj/usr/src/amd64.amd64/tmp/usr/lib/libutil.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/drivers/libwpadrivers_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/eapol_supp/libwpaeapol_supp_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/eap_server/libwpaeap_server_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/eap_peer/libwpaeap_peer_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/eap_common/libwpaeap_common_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/l2_packet/libwpal2_packet_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/rsn_supp/libwparsn_supp_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/tls/libwpatls_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/wps/libwpawps_pie.a /big/obj/usr/src/amd64.amd64/usr.s!
 bin/wpa/src/common/libwpacommon_pie..a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/crypto/libwpacrypto_pie.a /big/obj/usr/src/amd64.amd64/usr.sbin/wpa/src/utils/libwpautils_pie.a >> .depend

My MAKEOBJDIRPREFIX=/big/obj for both make world and the attempt to rebuild wpa.

I am not surprised by libc.a being taken from the installed base, but all other libraries
referenced are not found.

I can see a warning in <bsd.libnames.mk> that says:

> Converting out-of-tree build LIBADDs into LDADD.  This is not fully supported.

I guess this is for something else (I do not get this warning), but somewhat related.

How can I get this working to allow me to experiment with the code?




Finally, an example a linker failure, looks like linker options are not set properly at all:

Script started on Fri Jan 12 01:05:58 2024
Command: make -m /big/sw/hostap/build -m /usr/share/mk
===> src (all)
===> src/ap (all)

(~3645 successful compilation lines deleted)

cc  -O2 -pipe   -I/big/sw/hostap/build/wpa_supplicant -I/usr/src/contrib/wpa/hostapd -I/usr/src/contrib/wpa/src -I/usr/src/contrib/wpa/src/ap -I/usr/src/contrib/wpa/src/common -I/usr/src/contrib/wpa/src/crypto -I/usr/src/contrib/wpa/src/drivers -I/usr/src/contrib/wpa/src/eap_common -I/usr/src/contrib/wpa/src/eap_peer -I/usr/src/contrib/wpa/src/eap_server -I/usr/src/contrib/wpa/src/eapol_auth -I/usr/src/contrib/wpa/src/eapol_supp -I/usr/src/contrib/wpa/src/l2_packet -I/usr/src/contrib/wpa/src/radius -I/usr/src/contrib/wpa/src/rsn_supp -I/usr/src/contrib/wpa/src/tls -I/usr/src/contrib/wpa/src/utils -I/usr/src/contrib/wpa/src/wps -DCONFIG_DRIVER_BSD -DCONFIG_DRIVER_WIRED -DCONFIG_DRIVER_RADIUS_ACL -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -DCONFIG_IEEE80211AC -DCONFIG_IEEE80211N -DCONFIG_IEEE80211R -DCONFIG_IEEE80211W -DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\" -DCONFIG_DEBUG_SYSLOG -DPKCS12_FUNCS -DCONFIG_GAS -DCONFIG_PEERKEY -DCONFIG_PRIVSEP -DCONFIG_SMARTCARD -DCONFIG_TDL!
 S -DCONFIG_TERMINATE_ONLASTIF -DCONFIG_TLS=openssl -DCONFIG_MATCH_IFACE -DCONFIG_PTKSA_CACHE -DEAP_SERVER -DEAP_SERVER_GTC -DEAP_SERVER_IDENTITY -DEAP_SERVER_MD5 -DEAP_SERVER_MSCHAPV2 -DEAP_SERVER_PEAP -DEAP_SERVER_TLS -DEAP_SERVER_TTLS -DEAP_SERVER_WSC -DEAP_TLS_FUNCS -DCONFIG_WNM -DCONFIG_WNM_AP -DCONFIG_MBO -DCONFIG_RSN_PREAUTH -DCONFIG_WEP -DCONFIG_HS20  -DEAP_GTC  -DEAP_LEAP  -DEAP_MD5  -DEAP_MSCHAPv2  -DEAP_OTP  -DEAP_PEAP  -DEAP_PSK  -DEAP_TLS  -DEAP_TTLS  -DEAP_WSC  -DIEEE8021X_EAPOL  -DCONFIG_INTERWORKING  -DCONFIG_WPS  -DCONFIG_WPS2  -DCONFIG_WPS_UPNP  -DCONFIG_WPS_OOB -DCONFIG_PASN -DCONFIG_SHA256 -DCONFIG_ECC -DEAP_TLS_OPENSSL -DCONFIG_BACKEND_FILE  -DEAP_GTC  -DEAP_LEAP  -DEAP_MD5  -DEAP_MSCHAPv2  -DEAP_OTP  -DEAP_PEAP  -DEAP_PSK  -DEAP_TLS  -DEAP_TTLS  -DEAP_WSC  -DIEEE8021X_EAPOL -I/big/sw/hostap/build/wpa_supplicant -I/usr/src/contrib/wpa/hostapd -I/usr/src/contrib/wpa/src -I/usr/src/contrib/wpa/src/ap -I/usr/src/contrib/wpa/src/common -I/usr/src/contrib/wpa!
 /src/crypto -I/usr/src/contrib/wpa/src/drivers -I/usr/src/cont!
 rib/wpa/src/eap_common -I/usr/src/contrib/wpa/src/eap_peer -I/usr/src/contrib/wpa/src/eap_server -I/usr/src/contrib/wpa/src/eapol_auth -I/usr/src/contrib/wpa/src/eapol_supp -I/usr/src/contrib/wpa/src/l2_packet -I/usr/src/contrib/wpa/src/radius -I/usr/src/contrib/wpa/src/rsn_supp -I/usr/src/contrib/wpa/src/tls -I/usr/src/contrib/wpa/src/utils -I/usr/src/contrib/wpa/src/wps -DCONFIG_DRIVER_BSD -DCONFIG_DRIVER_WIRED -DCONFIG_DRIVER_RADIUS_ACL -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -DCONFIG_IEEE80211AC -DCONFIG_IEEE80211N -DCONFIG_IEEE80211R -DCONFIG_IEEE80211W -DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\" -DCONFIG_DEBUG_SYSLOG -DPKCS12_FUNCS -DCONFIG_GAS -DCONFIG_PEERKEY -DCONFIG_PRIVSEP -DCONFIG_SMARTCARD -DCONFIG_TDLS -DCONFIG_TERMINATE_ONLASTIF -DCONFIG_TLS=openssl -DCONFIG_MATCH_IFACE -DCONFIG_PTKSA_CACHE -DEAP_SERVER -DEAP_SERVER_GTC -DEAP_SERVER_IDENTITY -DEAP_SERVER_MD5 -DEAP_SERVER_MSCHAPV2 -DEAP_SERVER_PEAP -DEAP_SERVER_TLS -DEAP_SERVER_TTLS -DEAP_SERVER_WSC -DEAP!
 _TLS_FUNCS -DCONFIG_WNM -DCONFIG_WNM_AP -DCONFIG_MBO -DCONFIG_RSN_PREAUTH -DCONFIG_WEP -DCONFIG_HS20  -DEAP_GTC  -DEAP_LEAP  -DEAP_MD5  -DEAP_MSCHAPv2  -DEAP_OTP  -DEAP_PEAP  -DEAP_PSK  -DEAP_TLS  -DEAP_TTLS  -DEAP_WSC  -DIEEE8021X_EAPOL  -DCONFIG_INTERWORKING  -DCONFIG_WPS  -DCONFIG_WPS2  -DCONFIG_WPS_UPNP  -DCONFIG_WPS_OOB -DCONFIG_PASN -fPIE -g -gz=zlib -MD  -MF.depend.wps_supplicant.o -MTwps_supplicant.o -std=gnu99 -Wno-format-zero-length -fstack-protector-strong -Wno-pointer-sign -Wdate-time -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-parameter -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Wno-parentheses  -Qunused-arguments     -c /usr/src/contrib/wpa/wpa_supplicant/wps_supplicant.c -o wps_supplicant.o
cc -O2 -pipe -I/big/sw/hostap/build/wpa_supplicant -I/usr/src/contrib/wpa/hostapd -I/usr/src/contrib/wpa/src -I/usr/src/contrib/wpa/src/ap -I/usr/src/contrib/wpa/src/common -I/usr/src/contrib/wpa/src/crypto -I/usr/src/contrib/wpa/src/drivers -I/usr/src/contrib/wpa/src/eap_common -I/usr/src/contrib/wpa/src/eap_peer -I/usr/src/contrib/wpa/src/eap_server -I/usr/src/contrib/wpa/src/eapol_auth -I/usr/src/contrib/wpa/src/eapol_supp -I/usr/src/contrib/wpa/src/l2_packet -I/usr/src/contrib/wpa/src/radius -I/usr/src/contrib/wpa/src/rsn_supp -I/usr/src/contrib/wpa/src/tls -I/usr/src/contrib/wpa/src/utils -I/usr/src/contrib/wpa/src/wps -DCONFIG_DRIVER_BSD -DCONFIG_DRIVER_WIRED -DCONFIG_DRIVER_RADIUS_ACL -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -DCONFIG_IEEE80211AC -DCONFIG_IEEE80211N -DCONFIG_IEEE80211R -DCONFIG_IEEE80211W -DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\" -DCONFIG_DEBUG_SYSLOG -DPKCS12_FUNCS -DCONFIG_GAS -DCONFIG_PEERKEY -DCONFIG_PRIVSEP -DCONFIG_SMARTCARD -DCONFIG_TDLS -!
 DCONFIG_TERMINATE_ONLASTIF -DCONFIG_TLS=openssl -DCONFIG_MATCH_IFACE -DCONFIG_PTKSA_CACHE -DEAP_SERVER -DEAP_SERVER_GTC -DEAP_SERVER_IDENTITY -DEAP_SERVER_MD5 -DEAP_SERVER_MSCHAPV2 -DEAP_SERVER_PEAP -DEAP_SERVER_TLS -DEAP_SERVER_TTLS -DEAP_SERVER_WSC -DEAP_TLS_FUNCS -DCONFIG_WNM -DCONFIG_WNM_AP -DCONFIG_MBO -DCONFIG_RSN_PREAUTH -DCONFIG_WEP -DCONFIG_HS20 -DEAP_GTC -DEAP_LEAP -DEAP_MD5 -DEAP_MSCHAPv2 -DEAP_OTP -DEAP_PEAP -DEAP_PSK -DEAP_TLS -DEAP_TTLS -DEAP_WSC -DIEEE8021X_EAPOL -DCONFIG_INTERWORKING -DCONFIG_WPS -DCONFIG_WPS2 -DCONFIG_WPS_UPNP -DCONFIG_WPS_OOB -DCONFIG_PASN -DCONFIG_SHA256 -DCONFIG_ECC -DEAP_TLS_OPENSSL -DCONFIG_BACKEND_FILE -DEAP_GTC -DEAP_LEAP -DEAP_MD5 -DEAP_MSCHAPv2 -DEAP_OTP -DEAP_PEAP -DEAP_PSK -DEAP_TLS -DEAP_TTLS -DEAP_WSC -DIEEE8021X_EAPOL -I/big/sw/hostap/build/wpa_supplicant -I/usr/src/contrib/wpa/hostapd -I/usr/src/contrib/wpa/src -I/usr/src/contrib/wpa/src/ap -I/usr/src/contrib/wpa/src/common -I/usr/src/contrib/wpa/src/crypto -I/usr/src/contrib!
 /wpa/src/drivers -I/usr/src/contrib/wpa/src/eap_common -I/usr/!
 src/contrib/wpa/src/eap_peer -I/usr/src/contrib/wpa/src/eap_server -I/usr/src/contrib/wpa/src/eapol_auth -I/usr/src/contrib/wpa/src/eapol_supp -I/usr/src/contrib/wpa/src/l2_packet -I/usr/src/contrib/wpa/src/radius -I/usr/src/contrib/wpa/src/rsn_supp -I/usr/src/contrib/wpa/src/tls -I/usr/src/contrib/wpa/src/utils -I/usr/src/contrib/wpa/src/wps -DCONFIG_DRIVER_BSD -DCONFIG_DRIVER_WIRED -DCONFIG_DRIVER_RADIUS_ACL -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -DCONFIG_IEEE80211AC -DCONFIG_IEEE80211N -DCONFIG_IEEE80211R -DCONFIG_IEEE80211W -DTLS_DEFAULT_CIPHERS=\"DEFAULT:!EXP:!LOW\" -DCONFIG_DEBUG_SYSLOG -DPKCS12_FUNCS -DCONFIG_GAS -DCONFIG_PEERKEY -DCONFIG_PRIVSEP -DCONFIG_SMARTCARD -DCONFIG_TDLS -DCONFIG_TERMINATE_ONLASTIF -DCONFIG_TLS=openssl -DCONFIG_MATCH_IFACE -DCONFIG_PTKSA_CACHE -DEAP_SERVER -DEAP_SERVER_GTC -DEAP_SERVER_IDENTITY -DEAP_SERVER_MD5 -DEAP_SERVER_MSCHAPV2 -DEAP_SERVER_PEAP -DEAP_SERVER_TLS -DEAP_SERVER_TTLS -DEAP_SERVER_WSC -DEAP_TLS_FUNCS -DCONFIG_WNM -DCONF!
 IG_WNM_AP -DCONFIG_MBO -DCONFIG_RSN_PREAUTH -DCONFIG_WEP -DCONFIG_HS20 -DEAP_GTC -DEAP_LEAP -DEAP_MD5 -DEAP_MSCHAPv2 -DEAP_OTP -DEAP_PEAP -DEAP_PSK -DEAP_TLS -DEAP_TTLS -DEAP_WSC -DIEEE8021X_EAPOL -DCONFIG_INTERWORKING -DCONFIG_WPS -DCONFIG_WPS2 -DCONFIG_WPS_UPNP -DCONFIG_WPS_OOB -DCONFIG_PASN -fPIE -g -gz=zlib -std=gnu99 -Wno-format-zero-length -fstack-protector-strong -Wno-pointer-sign -Wdate-time -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-parameter -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Wno-parentheses -Qunused-arguments  -Wl,-zrelro -pie    -o wpa_supplicant.full bss.o bssid_ignore.o config.o config_file.o ctrl_iface.o ctrl_iface_unix.o driver_bsd.o eap_register.o events.o gas_query.o main.o mbo.o notify.o op_classes.o offchannel.o robust_a!
 v.o rrm.o scan.o twt.o wmm_ac.o wnm_sta.o wpa_supplicant.o wpas_glue.o !
 pasn_supplicant.o hs20_supplicant.o interworking.o wps_supplicant.o 
ld: error: undefined symbol: os_zalloc
>>> referenced by bss.c:49 (/usr/src/contrib/wpa/wpa_supplicant/bss.c:49)
>>>               bss.o:(wpa_bss_anqp_alloc)
>>> referenced by bss.c:69 (/usr/src/contrib/wpa/wpa_supplicant/bss.c:69)
>>>               bss.o:(wpa_bss_anqp_unshare_alloc)
>>> referenced by bss.c:49 (/usr/src/contrib/wpa/wpa_supplicant/bss.c:49)
>>>               bss.o:(wpa_bss_anqp_unshare_alloc)
>>> referenced 81 more times

ld: error: undefined symbol: wpabuf_dup
>>> referenced by bss.c:76 (/usr/src/contrib/wpa/wpa_supplicant/bss.c:76)
>>>               bss.o:(wpa_bss_anqp_unshare_alloc)
>>> referenced by bss.c:77 (/usr/src/contrib/wpa/wpa_supplicant/bss.c:77)
>>>               bss.o:(wpa_bss_anqp_unshare_alloc)
>>> referenced by bss.c:78 (/usr/src/contrib/wpa/wpa_supplicant/bss.c:78)
>>>               bss.o:(wpa_bss_anqp_unshare_alloc)
>>> referenced 17 more times

(152 lines with similar errors deleted)

ld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[1]: stopped in /big/sw/hostap/build/wpa_supplicant
*** Error code 1

Stop.
make: stopped in /big/sw/hostap/build

Command exit status: 1
Script done on Fri Jan 12 01:08:43 2024