This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Make the replacement mempcpy a function


This way we don't have to evaluate the 'n' argument twice. We now need
to link libeu.a into some tests, though. The system.h include was
accidentally dropped from elfcompress.c and findtextrel.c, but is
actually necessary when mempcpy is only available from libeu.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 ChangeLog         |  4 ++++
 configure.ac      |  1 +
 lib/ChangeLog     |  7 +++++++
 lib/Makefile.am   |  4 ++++
 lib/mempcpy.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/system.h      |  3 +--
 src/ChangeLog     |  5 +++++
 src/elfcompress.c |  1 +
 src/findtextrel.c |  2 +-
 tests/ChangeLog   |  4 ++++
 tests/Makefile.am | 20 ++++++++++----------
 11 files changed, 79 insertions(+), 13 deletions(-)
 create mode 100644 lib/mempcpy.c

diff --git a/ChangeLog b/ChangeLog
index 48185c3..15b36dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-17  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* configure.ac: Define HAVE_MEMPCPY if mempcpy is available.
+
 2017-02-15  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* configure.ac: Add check for mempcpy.
diff --git a/configure.ac b/configure.ac
index 3c35dac..303bf4d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -288,6 +288,7 @@ AC_CHECK_DECLS([powerof2],[],[],[#include <sys/param.h>])
 AC_CHECK_DECLS([mempcpy],[],[],
                [#define _GNU_SOURCE
                 #include <string.h>])
+AM_CONDITIONAL(HAVE_MEMPCPY, [test "x$ac_cv_have_decl_mempcpy" = "xyes"])
 
 AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl
 AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])])
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 84290f7..dcd20e1 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,10 @@
+2017-02-17  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* system.h: Make mempcpy a function.
+	* mempcpy.c: New file.
+	* Makefile.am (libeu_a_SOURCES): Add mempcpy.c if mempcpy is not
+	available from libc.
+
 2017-02-16  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7a65eb9..63738fd 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -41,6 +41,10 @@ noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
 		 md5.h sha1.h eu-config.h color.h printversion.h
 EXTRA_DIST = dynamicsizehash.c
 
+if !HAVE_MEMPCPY
+libeu_a_SOURCES += mempcpy.c
+endif
+
 if !GPROF
 xmalloc_CFLAGS = -ffunction-sections
 endif
diff --git a/lib/mempcpy.c b/lib/mempcpy.c
new file mode 100644
index 0000000..aff8d54
--- /dev/null
+++ b/lib/mempcpy.c
@@ -0,0 +1,41 @@
+/* Implementation of mempcpy, using memcpy
+   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/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "system.h"
+#include <string.h>
+
+void *
+mempcpy(void *dest, const void *src, size_t n)
+{
+    return (char *) memcpy (dest, src, n) + n;
+}
+
diff --git a/lib/system.h b/lib/system.h
index 2d05702..6ddbb2d 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -68,8 +68,7 @@
 #endif
 
 #if !HAVE_DECL_MEMPCPY
-#define mempcpy(dest, src, n) \
-    ((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
+void *mempcpy(void *dest, const void *src, size_t n);
 #endif
 
 /* A special gettext function we use if the strings are too short.  */
diff --git a/src/ChangeLog b/src/ChangeLog
index 0601198..d26169b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-17  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* elfcompress.c: Include system.h.
+	* findtextrel.c: Likewise.
+
 2017-02-16  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* addr2line.c: Include printversion.h
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 8e0d5c5..cf85820 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -36,6 +36,7 @@
 #include <gelf.h>
 #include "libeu.h"
 #include "printversion.h"
+#include "system.h"
 
 /* Name and version of program.  */
 ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
diff --git a/src/findtextrel.c b/src/findtextrel.c
index 8f1e239..5382abd 100644
--- a/src/findtextrel.c
+++ b/src/findtextrel.c
@@ -37,7 +37,7 @@
 #include <unistd.h>
 
 #include <printversion.h>
-
+#include <system.h>
 
 struct segments
 {
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 222bb6e..7b15ec5 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-15  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* Makefile.am: Link asm tests and elfstrmerge against libeu.a.
+
 2017-02-13  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* Makefile.am: Add test for unwinding with frame pointers on aarch64
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d120ed9..1dc85f9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -432,15 +432,15 @@ funcretval_LDADD = $(libdw) $(argp_LDADD)
 allregs_LDADD = $(libdw) $(argp_LDADD)
 find_prologues_LDADD = $(libdw) $(argp_LDADD)
 #show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf)
-asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst3_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst4_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst5_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst6_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
-asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) -ldl
+asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst3_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst4_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst5_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst6_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst7_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst8_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
+asm_tst9_LDADD = $(libasm) $(libebl) $(libelf) $(libdw) $(libeu) -ldl
 dwflmodtest_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD) -ldl
 rdwrmmap_LDADD = $(libelf)
 dwfl_bug_addr_overflow_LDADD = $(libdw) $(libebl) $(libelf) -ldl
@@ -488,7 +488,7 @@ elfstrtab_LDADD = $(libelf)
 dwfl_proc_attach_LDADD = $(libdw)
 dwfl_proc_attach_LDFLAGS = -pthread $(AM_LDFLAGS)
 elfshphehdr_LDADD =$(libelf)
-elfstrmerge_LDADD = $(libdw) $(libelf)
+elfstrmerge_LDADD = $(libdw) $(libelf) $(libeu)
 dwelfgnucompressed_LDADD = $(libelf) $(libdw)
 elfgetchdr_LDADD = $(libelf) $(libdw)
 elfgetzdata_LDADD = $(libelf)
-- 
2.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]