Bug 13926 - __bswap_64 in bits/byeswap.h only usable by gcc
Summary: __bswap_64 in bits/byeswap.h only usable by gcc
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.15
: P3 minor
Target Milestone: ---
Assignee: Andreas Jaeger
Depends on:
Reported: 2012-03-28 13:43 UTC by Doug Johnson
Modified: 2014-06-25 11:26 UTC (History)
3 users (show)

See Also:
Last reconfirmed: 2012-03-28 00:00:00
fweimer: security-

Proposed patch for bits/byteswap.h (433 bytes, patch)
2012-03-28 13:48 UTC, Doug Johnson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Johnson 2012-03-28 13:43:31 UTC

I've found what I believe is a bug in the bits/byteswap.h file, and the defines that control whether masks/shifts or gcc inline assembly are used to implement the byte swap.  The 16 and 32 bits swaps are compatible with non-gcc compilers, but the 64 bit swap can never be defined for a non-gcc compiler.  See attached patch for what I think the defines should look like (untested patch.)

Comment 1 Doug Johnson 2012-03-28 13:48:21 UTC
Created attachment 6305 [details]
Proposed patch for bits/byteswap.h
Comment 2 Andreas Jaeger 2012-03-28 14:04:56 UTC
Just checked git head:

This patch is needed for i386, x86-64, and the generic version.

s390 seems to do it right.
Comment 3 Rich Felker 2012-03-29 15:15:22 UTC
The inline asm for byte swapping is obsolete and useless anyway. Since at least early gcc 4, gcc already generates the optimal machine code if you just write the byte swap in the most naive possible way with bitshifts and masking. The asm should be thrown out and just replaced with static inline functions.
Comment 4 Andreas Jaeger 2012-04-03 07:18:04 UTC
git commit b1aa60f32d34030b28bca04aeee084cd3bedecfa contains a fix.