mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:51:15 +08:00
e755667f94
At least one C library (uclibc-ng) defines some of these only when the compiler is GCC. We might as well test for all three cases and handle any of them being missing. Very similar code exists in libctf and split between elfcpp and gold: fix both. (Also sync up elfcpp with a change made to libctf swap.h a few months ago: since there is no out-of-line definition of the bswap replacements, they should be declared static inline, not just inline, to prevent the linker generating out-of-line references to them.) PR libctf/25120 libctf/ * configure.ac: Check for bswap_16, bswap_32, and bswap_64 decls. * swap.h (bswap_16): Do not assume that presence of <byteswap.h> means this is declared. (bswap_32): Likewise. (bswap_64): Likewise. (bswap_identity_64): Remove, unused. * configure: Regenerated. * config.h.in: Likewise. gold/ * configure.ac: Check for bswap_16, bswap_32, and bswap_64 decls. * configure: Regenerated. * config.h.in: Likewise. elfcpp/ * elfcpp_swap.h (bswap_16): Do not assume that presence of <byteswap.h> means this is declared. Make static inline, matching recent change to libctf, since there is no non-inline definition of these functions. (bswap_32): Likewise. (bswap_64): Likewise.
67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
/* Interface to byteswapping functions.
|
|
Copyright (C) 2006-2020 Free Software Foundation, Inc.
|
|
|
|
This file is part of libctf.
|
|
|
|
libctf is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef _CTF_SWAP_H
|
|
#define _CTF_SWAP_H
|
|
|
|
#include "config.h"
|
|
#include <stdint.h>
|
|
|
|
#ifdef HAVE_BYTESWAP_H
|
|
#include <byteswap.h>
|
|
#endif /* defined(HAVE_BYTESWAP_H) */
|
|
|
|
/* Provide our own versions of the byteswap functions. */
|
|
|
|
#if !HAVE_DECL_BSWAP_16
|
|
static inline uint16_t
|
|
bswap_16 (uint16_t v)
|
|
{
|
|
return ((v >> 8) & 0xff) | ((v & 0xff) << 8);
|
|
}
|
|
#endif /* !HAVE_DECL_BSWAP16 */
|
|
|
|
#if !HAVE_DECL_BSWAP_32
|
|
static inline uint32_t
|
|
bswap_32 (uint32_t v)
|
|
{
|
|
return ( ((v & 0xff000000) >> 24)
|
|
| ((v & 0x00ff0000) >> 8)
|
|
| ((v & 0x0000ff00) << 8)
|
|
| ((v & 0x000000ff) << 24));
|
|
}
|
|
#endif /* !HAVE_DECL_BSWAP32 */
|
|
|
|
#if !HAVE_DECL_BSWAP_64
|
|
static inline uint64_t
|
|
bswap_64 (uint64_t v)
|
|
{
|
|
return ( ((v & 0xff00000000000000ULL) >> 56)
|
|
| ((v & 0x00ff000000000000ULL) >> 40)
|
|
| ((v & 0x0000ff0000000000ULL) >> 24)
|
|
| ((v & 0x000000ff00000000ULL) >> 8)
|
|
| ((v & 0x00000000ff000000ULL) << 8)
|
|
| ((v & 0x0000000000ff0000ULL) << 24)
|
|
| ((v & 0x000000000000ff00ULL) << 40)
|
|
| ((v & 0x00000000000000ffULL) << 56));
|
|
}
|
|
#endif /* !HAVE_DECL_BSWAP64 */
|
|
|
|
#endif /* !defined(_CTF_SWAP_H) */
|