Fixes for musl and FreeBSD#236
Open
250MHz wants to merge 8 commits into
Open
Conversation
By scoping OpenSSL as INTERFACE, libbsl_crypto lacks the OpenSSL symbols. OpenSSL should be PRIVATE since CryptoInterface.c uses OpenSSL types, but the public headers do not. test_CryptoInterface relies on OpenSSL symbols indirectly from libbsl_crypto (via libbsl_mock_bpa, which gets them via the SC libs). Since we're making OpenSSL privately scoped, add OpenSSL::Crypto as a dependency of test_CryptoInterface. libbsl_crypto only uses M*LIB types internally, so M*LIB should be scoped as PRIVATE not PUBLIC. libbsl_cose_sc uses M*LIB headers in its public API, so list M*LIB as a dependency.
Slightly more portable than #!/bin/bash
valgrind-devel installed by pkg or ports on FreeBSD installs libraries and headers, etc., into /usr/local/include/. Using pkg-config to get the right directory doesn't work because Valgrind's .pc file's includedir appends "/valgrind", so CryptoInterface.c including <valgrind/memcheck.h> doesn't work. Instead, get the directory of valgrind/memcheck.h with find_path.
When _POSIX_C_SOURCE is defined on FreeBSD, gettimeofday() is hidden. gettimeofday() was marked obsolescent in POSIX Issue 7 and removed in Issue 8. The APPLICATION USAGE section [1] recommends clock_gettime() instead, so prefer that over gettimeofday() if it's available. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html
FreeBSD needs explicit linkage to use POSIX threads. Building libbsl_mock_bpa fails because pthread_create is an undefined reference. So link libbsl_mock_bpa with Threads::Threads.
FreeBSD's <arpa/inet.h> doesn't make all the symbols from <netinet/in.h> visible, and <netinet/in.h> doesn't make all the symbols from <sys/socket.h> visible. So explicitly include these headers on the files that need those symbols.
Issue 8 says: "The fseek() and fseeko() functions can be used to set the file position beyond the current buffer length. It is implementation-defined whether this extends the buffer to the new length" [1]. agent.c relies on this behavior to pre-allocate BTSD size. This works on glibc, but not on musl or FreeBSD. Writing to move the position to a value larger than the current length will bump the buffer length up, so do that instead. But while glibc uses the size_t pointer to report the size of the buffer [2], FreeBSD follows POSIX in making the variable pointed to by the size_t pointer contain the smaller of the current position and the current buffer length [3]. We can't rely on MockBPA_BTSD_Data_s.size being the buffer length, so introduce the MockBPA_BTSD_Data_s.cap member to track the size of the buffer. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/open_memstream.html [2]: https://manned.org/man.b13f60d3/arch/open_memstream [3]: https://manned.org/man.64840208/freebsd-15.0/open_memstream
test_CryptoInterface has memory leaks on FreeBSD. test_encrypt has an empty plaintext_in as one of its values. In this case, strlen() returns 0, so BSL_TestUtils_FlatReader passes size 0 to fmemopen(). POSIX allows different behavior when the buffer size is 0 [1]. Since glibc 2.22, a zero size successfully creates a stream [2]. On FreeBSD, a zero size returns NULL [3]. test_encrypt calls BSL_SeqReader_Destroy, which calls the deinit function of the reader which is BSL_TestUtils_ReadBTSD_Deinit. This function returns early if either obj or obj->file are NULL, without calling fclose(obj->file) and BSL_free(obj), and since obj->file is NULL on FreeBSD, memory leaks are reported. Fix this by separating the check of obj and obj->file. Always free obj if obj is not null. The same pattern happens for BSL_TestUtils_WriteBTSD_Deinit, so apply the fix there as well. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fmemopen.html [2]: https://manned.org/man.c445d9bf/arch/fmemopen#head10 [3]: https://manned.org/man.7779899a/freebsd-15.0/fmemopen#head6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm currently fixing ION's configuration and usage of BSL. Since ION also tries to support musl and FreeBSD, I wanted to also test out my changes on those platforms but ran into some problems. After a day of debugging, here's patches that makes BSL build successfully for me with
./build.sh checkpassing.Some concerns:
_POSIX_C_SOURCEas200809L, maybe it's not even worth keepinggettimeofday()around in commit 3e52805 (HostInterface: Use clock_gettime if available, 2026-07-11)?