Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in missing endianess functions for Apple targets #1130

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

palmerc
Copy link

@palmerc palmerc commented Dec 19, 2024

Apple SDKs indeed have the endian.h headers, but they do not contain these functions and therefore will error out when doing a cmake build. Remove the conditional HAVE_ENDIAN check or remove the conditional check for Apple compatibility? I chose to remove the conditional check for Apple compatibility.

@botovq
Copy link
Contributor

botovq commented Dec 19, 2024

Thanks. Something similar came up here #1025 but this sort of got stuck since nobody could tell me what the correct approach was. Can you tell me if this is good enough to build on iOS as well, i.e., does this address the issue in #1025?

@palmerc
Copy link
Author

palmerc commented Dec 19, 2024

I am building macOS, iPhoneOS and iPhoneSimulator in a single shot. It is the same issue as appears in 1025

@palmerc
Copy link
Author

palmerc commented Dec 19, 2024

A better approach might be to check for the individual functions, but it is sort of an all-or-nothing affair since none of these functions appear in AppleVerse

@botovq
Copy link
Contributor

botovq commented Dec 19, 2024

This endian.h compat thing is just such an unbelievable mess :)

We copied this from openiked, which has always had this HAVE_ENDIAN_H define.

Is it aversion of this Endian.h which is picked up due to case-insensitivity of the file system on macOS (I assume that's still the case)?

All that said, I am inclined to merge this. I will do so in a couple of days.

@palmerc
Copy link
Author

palmerc commented Dec 20, 2024

All of the current SDKs have these endian files:

% find . -name Endian.h    
./usr/include/Endian.h

% find . -name endian.h
./usr/include/c++/v1/__bit/endian.h
./usr/include/machine/endian.h
./usr/include/arm/endian.h

In cmake you could go with:

// check_symbol_exists(<symbol> <files> <variable>)
check_symbol_exists(be16toh endian.h HAVE_BE16TOH)

@palmerc
Copy link
Author

palmerc commented Dec 20, 2024

I had failed to update the comment at the bottom of the block to match, but I've done that now.

@botovq
Copy link
Contributor

botovq commented Dec 20, 2024

Thanks. I was hoping we could avoid doing in this super fine grained manner, but yes, it's probably cleaner than what we have now... It's just surprising that I can't find a ready-made solution that covers all our needs. It feels like it should exist...

@palmerc
Copy link
Author

palmerc commented Dec 20, 2024

What if I just switched the check to this:

if(NOT APPLE AND NOT WIN32)
	check_include_files(endian.h HAVE_ENDIAN_H)
	if(HAVE_ENDIAN_H)
		add_definitions(-DHAVE_ENDIAN_H)
	endif()
endif()

@botovq
Copy link
Contributor

botovq commented Dec 20, 2024

I'm pretty sure that the previous diff was better. This logic introduces an unexpected difference between the CMake and automake builds which will likely bite us down the road.

I'd like to merge the previous version and next time an issue shows up we'll have to sit down and do the grunt work of solving this "the right way."

@palmerc
Copy link
Author

palmerc commented Dec 20, 2024

Doesn't the other formulation leave windows builds broken? In endian.h, right after the equivalent Apple bit there is similar code defining non-existent functions with the expectation that endian.h does not exist. I can't answer whether or not windows machines have endian.h or not, nor whether they are missing these #defines.

#if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
#include <winsock2.h>

#define be16toh(x) ntohs((x))
#define htobe16(x) htons((x))
#define le32toh(x) (x)
#define be32toh(x) ntohl((x))
#define htole32(x) (x)
#define htobe32(x) ntohl((x))
#define be64toh(x) ntohll((x))

#if !defined(ntohll)
#define ntohll(x)                                                              \
  ((1 == htonl(1))                                                             \
       ? (x)                                                                   \
       : ((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32))
#endif
#if !defined(htonll)
#define htonll(x)                                                              \
  ((1 == ntohl(1))                                                             \
       ? (x)                                                                   \
       : ((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32))
#endif

#define htobe64(x) ntohll((x))
#define htole64(x) (x)
#define le64toh(x) (x)
#endif /* _WIN32 && !HAVE_ENDIAN_H */

@palmerc
Copy link
Author

palmerc commented Dec 20, 2024

In any case, the original version works for Apple and that is what matters to me :)

@palmerc
Copy link
Author

palmerc commented Dec 26, 2024

Did you need anything else for this MR?

@botovq botovq merged commit 2cb875e into libressl:master Dec 26, 2024
48 checks passed
@botovq
Copy link
Contributor

botovq commented Dec 26, 2024

No, it's all good. Merged now, thanks.

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.

2 participants