Navigation Menu

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

librhash/byte_order.h: Consult also compiler's predefined macros. #25

Closed
wants to merge 1 commit into from
Closed

librhash/byte_order.h: Consult also compiler's predefined macros. #25

wants to merge 1 commit into from

Conversation

przemoc
Copy link
Contributor

@przemoc przemoc commented Nov 18, 2016

Recently I created patch for Alpine Linux's aports to include rhash in its repository, because I find this tool very useful. Unfortunately building on aarch64 (64-bit ARM architecture) failed, but I don't have access to such hardware, so I couldn't check it earlier.

Investigating build logs made me realize that byte_order.h has too much hardcoded stuff, yet it fails work on "unknown" platforms with non-glibc libc implementations. I think that ultimately this header should be rewritten, but w/o having access to all the platforms to retest it there, I didn't go that way. Instead I simply added another way to check endianness that depends on compiler's provided macros (at least gcc and clang provide them), that are usually used by <endian.h> anyway.

After successfully building and running tests/test_rhash.sh on aarch64 (kudos to @clandmeter who has access to such hardware and was kind enough to do builds and run test), the patch has been added to Alpine Linux repository in testing/rhash and therefore rhash is available in edge's testing repository for now.

Now I would like to upstream the improvement.

Commit message

byte_order.h includes <endian.h> only if glibc is used (i.e. __GLIBC__ is defined), but there are other libc implementation that also provide endian.h, like musl libc for instance. Generally it's much better and
cleaner to check feature test macros than check for particular implementation (and that is also why musl libc doesn't define __MUSL__). Unfortunately I am not aware of feature test macro guaranteeing endian.h availability.

The simple solution is to add checking for compiler's pre-defined macros (__BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_LITTLE_ENDIAN__) after checking macros coming from system headers, i.e. <endian.h> in this case (__BYTE_ORDER, __BIG_ENDIAN, __LITTLE_ENDIAN).

That way we can better support new architectures w/o hardcoding their endianness, which is especially useful if they support both.

byte_order.h includes <endian.h> only if glibc is used (i.e. __GLIBC__
is defined), but there are other libc implementation that also provide
endian.h, like musl libc for instance.  Generally it's much better and
cleaner to check feature test macros than check for particular
implementation (and that is also why musl libc doesn't define __MUSL__).
Unfortunately I am not aware of feature test macro guaranteeing endian.h
availability.

The simple solution is to add checking for compiler's pre-defined macros
(__BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_LITTLE_ENDIAN__) after
checking macros coming from system headers, i.e. <endian.h> in this case
(__BYTE_ORDER, __BIG_ENDIAN, __LITTLE_ENDIAN).

That way we can better support new architectures w/o hardcoding their
endianness, which is especially useful if they support both.
@rhash
Copy link
Owner

rhash commented Jul 10, 2017

merged into main tree as 7e4a509

@rhash rhash closed this Jul 19, 2017
@rhash rhash added the done The issue is fixed/applied/implemented label Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done The issue is fixed/applied/implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants