+2018-11-17 Mark Wielaard <mark@klomp.org>
+
+ * elf32_updatefile.c (updatemmap): Make sure to call convert
+ function on a properly aligned destination.
+
2018-11-16 Mark Wielaard <mark@klomp.org>
* libebl.h (__elf32_msize): Mark with const attribute.
/* Write changed data structures.
- Copyright (C) 2000-2010, 2014, 2015, 2016 Red Hat, Inc.
+ Copyright (C) 2000-2010, 2014, 2015, 2016, 2018 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2000.
user's section data with the latest one, rather than
crashing. */
- if (unlikely (change_bo))
+ if (unlikely (change_bo
+ && dl->data.d.d_size != 0
+ && dl->data.d.d_type != ELF_T_BYTE))
{
#if EV_NUM != 2
xfct_t fctp;
# define fctp __elf_xfctstom[0][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][dl->data.d.d_type]
#endif
- /* Do the real work. */
- (*fctp) (last_position, dl->data.d.d_buf,
- dl->data.d.d_size, 1);
+ size_t align;
+ align = __libelf_type_align (ELFW(ELFCLASS,LIBELFBITS),
+ dl->data.d.d_type);
+ if ((((uintptr_t) last_position)
+ & (uintptr_t) (align - 1)) == 0)
+ {
+ /* No need to copy, we can convert directly. */
+ (*fctp) (last_position, dl->data.d.d_buf,
+ dl->data.d.d_size, 1);
+ }
+ else
+ {
+ /* We have to do the conversion on properly
+ aligned memory first. */
+ size_t size = dl->data.d.d_size;
+ char *converted = aligned_alloc (align, size);
+ if (converted == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return 1;
+ }
+ (*fctp) (converted, dl->data.d.d_buf, size, 1);
+
+ /* And then write it to the mmapped file. */
+ memcpy (last_position, converted, size);
+ free (converted);
+ }
last_position += dl->data.d.d_size;
}
+2018-11-17 Mark Wielaard <mark@klomp.org>
+
+ * run-strip-version.sh: New test.
+ * testfile-version.bz2: New test file.
+ * Makefile.am (TESTS): Add run-strip-version.sh.
+ (EXTRA_DIST): Add run-strip-version.sh and testfile-version.bz2.
+
2018-11-09 Mark Wielaard <mark@klomp.org>
* run-strip-reloc.sh: Also test testfile-debug-rel-ppc64-z.o
run-reloc-bpf.sh \
run-next-cfi.sh run-next-cfi-self.sh \
run-copyadd-sections.sh run-copymany-sections.sh \
- run-typeiter-many.sh run-strip-test-many.sh
+ run-typeiter-many.sh run-strip-test-many.sh \
+ run-strip-version.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
run-typeiter-many.sh run-strip-test-many.sh \
testfile-debug-rel-ppc64-g.o.bz2 \
testfile-debug-rel-ppc64-z.o.bz2 \
- testfile-debug-rel-ppc64.o.bz2
+ testfile-debug-rel-ppc64.o.bz2 \
+ run-strip-version.sh testfile-version.bz2
if USE_VALGRIND
valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2018 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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 of the License, or
+# (at your option) any later version.
+#
+# 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 a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Generated on s390x with an older gas (2.29.1) that generates
+# badly aligned version notes.
+#
+# = testfile-version.s =
+#
+# .section ".extra"
+# .byte 42
+#
+# .version "Sliding Snow"
+# .version "Hurr durr 3.1"
+#
+# .globl _start
+#_start:
+#
+# gcc -nostartfiles -nodefaultlibs -o testfile-version testfile-version.s
+
+testfiles testfile-version
+tempfiles debug.out elf.out
+
+testrun ${abs_top_builddir}/src/strip -o elf.out -f debug.out \
+ testfile-version
+
+testrun ${abs_top_builddir}/src/elflint --gnu elf.out
+testrun ${abs_top_builddir}/src/elflint --gnu --debug debug.out
+
+testrun_compare ${abs_top_builddir}/src/readelf -n debug.out <<\EOF
+
+Note section [ 1] '.note.gnu.build-id' of 36 bytes at offset 0xb0:
+ Owner Data size Type
+ GNU 20 GNU_BUILD_ID
+ Build ID: d3c84c0b307c06f50a37c6c0f59c82c4cb10720b
+
+Note section [ 3] '.note' of 56 bytes at offset 0xd5:
+ Owner Data size Type
+ Sliding Snow 0 VERSION
+ Hurr durr 3.1 0 VERSION
+EOF
+
+exit 0