public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add replacement endian.h and byteswap.h to libgnu
@ 2017-05-04  8:20 Ulf Hermann
  2017-11-16  8:24 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Ulf Hermann @ 2017-05-04  8:20 UTC (permalink / raw)
  To: elfutils-devel

Some systems don't provide endian.h and byteswap.h. The required
functions are trivial to define using sys/param.h and gcc builtins,
though.

Also, include endian.h in dwelf_scn_gnu_compressed_size.c as that uses
be64toh().

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 ChangeLog                                |  4 ++
 configure.ac                             |  6 +++
 libdwelf/ChangeLog                       |  4 ++
 libdwelf/dwelf_scn_gnu_compressed_size.c |  1 +
 libgnu/ChangeLog                         |  6 +++
 libgnu/Makefile.am                       | 17 +++++++-
 libgnu/byteswap.in.h                     | 38 ++++++++++++++++
 libgnu/endian.in.h                       | 75 ++++++++++++++++++++++++++++++++
 8 files changed, 150 insertions(+), 1 deletion(-)
 create mode 100644 libgnu/ChangeLog
 create mode 100644 libgnu/byteswap.in.h
 create mode 100644 libgnu/endian.in.h

diff --git a/ChangeLog b/ChangeLog
index d43eeb6..01f3197 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-03  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* configure.ac: Check if endian.h and byteswap.h are available.
+
 2017-04-28  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* configure.ac: Determine the binary format we're building natively.
diff --git a/configure.ac b/configure.ac
index a854013..1e6c844 100644
--- a/configure.ac
+++ b/configure.ac
@@ -544,6 +544,12 @@ else
 fi
 AC_SUBST([intl_LDADD])
 
+AC_CHECK_DECLS([BYTE_ORDER], [], [], [[#include <endian.h>]])
+AM_CONDITIONAL(HAVE_ENDIAN_H, [test "x$ac_cv_have_decl_BYTE_ORDER" = "xyes"])
+
+AC_CHECK_DECLS([bswap_32], [], [], [[#include <byteswap.h>]])
+AM_CONDITIONAL(HAVE_BYTESWAP_H, [test "x$ac_cv_have_decl_bswap_32" = "xyes"])
+
 dnl Check if we have <linux/bpf.h> for EM_BPF disassembly.
 AC_CHECK_HEADERS(linux/bpf.h)
 AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"])
diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index a332655..29af410 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-03  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* dwelf_scn_gnu_compressed_size.c: Include endian.h.
+
 2015-10-11  Akihiko Odaki  <akihiko.odaki.4i@stu.hosei.ac.jp>
 
 	* dwelf_strtab.c: Remove sys/param.h include.
diff --git a/libdwelf/dwelf_scn_gnu_compressed_size.c b/libdwelf/dwelf_scn_gnu_compressed_size.c
index d39b702..6bad8af 100644
--- a/libdwelf/dwelf_scn_gnu_compressed_size.c
+++ b/libdwelf/dwelf_scn_gnu_compressed_size.c
@@ -30,6 +30,7 @@
 # include <config.h>
 #endif
 
+#include <endian.h>
 #include "libdwelfP.h"
 #include "libelfP.h"
 
diff --git a/libgnu/ChangeLog b/libgnu/ChangeLog
new file mode 100644
index 0000000..ca38be2
--- /dev/null
+++ b/libgnu/ChangeLog
@@ -0,0 +1,6 @@
+2017-05-03  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* Makefile.am: Make endian.h and byteswap.h available if they don't
+	exist.
+	* byteswap.in.h: New file.
+	* endian.in.h: New file.
diff --git a/libgnu/Makefile.am b/libgnu/Makefile.am
index 0d31e69..37fdb9c 100644
--- a/libgnu/Makefile.am
+++ b/libgnu/Makefile.am
@@ -35,7 +35,22 @@ noinst_LIBRARIES =
 MOSTLYCLEANFILES =
 MOSTLYCLEANDIRS =
 BUILT_SOURCES =
-EXTRA_DIST =
+EXTRA_DIST = endian.in.h byteswap.in.h
 CLEANFILES =
 SUFFIXES =
+
+if !HAVE_ENDIAN_H
+endian.h: endian.in.h
+	$(AM_V_GEN)rm -f $@ && cat $< > $@
+BUILT_SOURCES += endian.h
+MOSTLYCLEANFILES += endian.h
+endif
+
+if !HAVE_BYTESWAP_H
+byteswap.h: byteswap.in.h
+	$(AM_V_GEN)rm -f $@ && cat $< > $@
+BUILT_SOURCES += byteswap.h
+MOSTLYCLEANFILES += byteswap.h
+endif
+
 include gnulib.am
diff --git a/libgnu/byteswap.in.h b/libgnu/byteswap.in.h
new file mode 100644
index 0000000..e7b4f29
--- /dev/null
+++ b/libgnu/byteswap.in.h
@@ -0,0 +1,38 @@
+/* Byteswapping functions for windows
+   Copyright (C) 2017 The Qt Company Ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils 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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef LIB_BYTESWAP_H
+#define LIB_BYTESWAP_H 1
+
+#include <stdlib.h>
+
+#define bswap_16(x) __builtin_bswap16(x)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+
+#endif
diff --git a/libgnu/endian.in.h b/libgnu/endian.in.h
new file mode 100644
index 0000000..c4fa151
--- /dev/null
+++ b/libgnu/endian.in.h
@@ -0,0 +1,75 @@
+/* Endianness related defines for windows
+   Copyright (C) 2017 The Qt Company Ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils 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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef LIB_ENDIAN_H
+#define LIB_ENDIAN_H 1
+
+#include <sys/param.h>
+
+#define __BYTE_ORDER    BYTE_ORDER
+#define __BIG_ENDIAN    BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#define __PDP_ENDIAN    PDP_ENDIAN
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+#define htobe16(x) __builtin_bswap16(x)
+#define htole16(x) (x)
+#define be16toh(x) __builtin_bswap16(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) __builtin_bswap32(x)
+#define htole32(x) (x)
+#define be32toh(x) __builtin_bswap32(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) __builtin_bswap64(x)
+#define htole64(x) (x)
+#define be64toh(x) __builtin_bswap64(x)
+#define le64toh(x) (x)
+
+#elif BYTE_ORDER == BIG_ENDIAN
+
+#define htobe16(x) (x)
+#define htole16(x) __builtin_bswap16(x)
+#define be16toh(x) (x)
+#define le16toh(x) __builtin_bswap16(x)
+
+#define htobe32(x) (x)
+#define htole32(x) __builtin_bswap32(x)
+#define be32toh(x) (x)
+#define le32toh(x) __builtin_bswap32(x)
+
+#define htobe64(x) (x)
+#define htole64(x) __builtin_bswap64(x)
+#define be64toh(x) (x)
+#define le64toh(x) __builtin_bswap64(x)
+
+#endif
+
+#endif // LIB_ENDIAN_H
-- 
2.1.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add replacement endian.h and byteswap.h to libgnu
  2017-05-04  8:20 [PATCH] Add replacement endian.h and byteswap.h to libgnu Ulf Hermann
@ 2017-11-16  8:24 ` Florian Weimer
  2017-11-16  8:54   ` Ulf Hermann
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2017-11-16  8:24 UTC (permalink / raw)
  To: Ulf Hermann; +Cc: elfutils-devel

* Ulf Hermann:

> Some systems don't provide endian.h and byteswap.h. The required
> functions are trivial to define using sys/param.h and gcc builtins,
> though.
>
> Also, include endian.h in dwelf_scn_gnu_compressed_size.c as that uses
> be64toh().

This is still an issue with non-glibc, non-BSD compilation.  The patch
is not ideal, as it depends on a GCC extension, but it's an
improvement for those who use GCC on a platform which does not provide
these functions as part of the C library.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add replacement endian.h and byteswap.h to libgnu
  2017-11-16  8:24 ` Florian Weimer
@ 2017-11-16  8:54   ` Ulf Hermann
  2017-11-16  9:21     ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Ulf Hermann @ 2017-11-16  8:54 UTC (permalink / raw)
  To: Florian Weimer; +Cc: elfutils-devel

>> Some systems don't provide endian.h and byteswap.h. The required
>> functions are trivial to define using sys/param.h and gcc builtins,
>> though.
>>
>> Also, include endian.h in dwelf_scn_gnu_compressed_size.c as that uses
>> be64toh().
> 
> This is still an issue with non-glibc, non-BSD compilation.  The patch
> is not ideal, as it depends on a GCC extension, but it's an
> improvement for those who use GCC on a platform which does not provide
> these functions as part of the C library.

Well, there are a lot of other issues to be fixed if you want to build elfutils on anything non-gcc. We could add a further check for those builtins and sys/param.h and then add a somewhat less trivial version of endian.h and byteswap.h if they are missing. But that would likely involve other compiler extensions or OS-specific headers.

br,
Ulf

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add replacement endian.h and byteswap.h to libgnu
  2017-11-16  8:54   ` Ulf Hermann
@ 2017-11-16  9:21     ` Florian Weimer
  2017-11-16 13:12       ` Mark Wielaard
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2017-11-16  9:21 UTC (permalink / raw)
  To: Ulf Hermann; +Cc: elfutils-devel

* Ulf Hermann:

>>> Some systems don't provide endian.h and byteswap.h. The required
>>> functions are trivial to define using sys/param.h and gcc builtins,
>>> though.
>>>
>>> Also, include endian.h in dwelf_scn_gnu_compressed_size.c as that uses
>>> be64toh().
>> 
>> This is still an issue with non-glibc, non-BSD compilation.  The patch
>> is not ideal, as it depends on a GCC extension, but it's an
>> improvement for those who use GCC on a platform which does not provide
>> these functions as part of the C library.
>
> Well, there are a lot of other issues to be fixed if you want to build
> elfutils on anything non-gcc. We could add a further check for those
> builtins and sys/param.h and then add a somewhat less trivial version
> of endian.h and byteswap.h if they are missing. But that would likely
> involve other compiler extensions or OS-specific headers.

Ah, fair enough.  I mainly wanted to increase awareness of the patch
because it has not been merged yet.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add replacement endian.h and byteswap.h to libgnu
  2017-11-16  9:21     ` Florian Weimer
@ 2017-11-16 13:12       ` Mark Wielaard
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Wielaard @ 2017-11-16 13:12 UTC (permalink / raw)
  To: Florian Weimer, Ulf Hermann; +Cc: elfutils-devel

On Thu, 2017-11-16 at 10:21 +0100, Florian Weimer wrote:
> * Ulf Hermann:
> > Well, there are a lot of other issues to be fixed if you want to build
> > elfutils on anything non-gcc. We could add a further check for those
> > builtins and sys/param.h and then add a somewhat less trivial version
> > of endian.h and byteswap.h if they are missing. But that would likely
> > involve other compiler extensions or OS-specific headers.
> 
> Ah, fair enough.  I mainly wanted to increase awareness of the patch
> because it has not been merged yet.

Yeah, sorry for dropping some of these older patches. I admit they
aren't really on my radar anymore. So please do ping them if you want
to get them integrated. But I believe we never fully finished the
discussion about whether or not to adopt gnulib for things like this.
Which I think is a better idea than having to maintain our own
versions.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-16 13:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-04  8:20 [PATCH] Add replacement endian.h and byteswap.h to libgnu Ulf Hermann
2017-11-16  8:24 ` Florian Weimer
2017-11-16  8:54   ` Ulf Hermann
2017-11-16  9:21     ` Florian Weimer
2017-11-16 13:12       ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).