unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Alan Modra <amodra@gmail.com>
Cc: 20614@debbugs.gnu.org
Subject: bug#20614: alignment problem with recent Emacs unexelf.c changes
Date: Mon, 16 Nov 2015 17:59:25 -0800	[thread overview]
Message-ID: <564A89FD.6080206@cs.ucla.edu> (raw)
In-Reply-To: <555C3E3C.4090700@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 343 bytes --]

I ran into a porting problem when using Emacs's recent unexelf.c changes in a 
picky build using GCC’s -fsanitize=undefined option. The attached patch worked 
for me, so I installed it into emacs-25. Alan, could you please check and/or 
improve this patch, and/or think about whether there might be similar problems 
elsewhere? Thanks.

[-- Attachment #2: 0001-ELF-unexec-align-section-header.txt --]
[-- Type: text/plain, Size: 2038 bytes --]

From 0b3f6f7f182f3363fc499e52b27649e05c1ad381 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 16 Nov 2015 17:48:08 -0800
Subject: [PATCH] ELF unexec: align section header
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This ports the recent unexelf.c changes to Fedora x86-64
when configured with GCC’s -fsanitize=undefined option.
* src/unexelf.c (unexec): Align new_data2_size to a multiple
of ElfW (Shdr)’s alignment, so that NEW_SECTION_H returns a
pointer aligned appropriately for its type.
---
 src/unexelf.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/unexelf.c b/src/unexelf.c
index c10c7f2..03e6daf 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -247,7 +247,7 @@ unexec (const char *new_name, const char *old_name)
 
   ElfW (Phdr) *old_bss_seg, *new_bss_seg;
   ElfW (Addr) old_bss_addr, new_bss_addr;
-  ElfW (Word) old_bss_size, new_data2_size;
+  ElfW (Word) old_bss_size, bss_size_growth, new_data2_size;
   ElfW (Off) old_bss_offset, new_data2_offset;
 
   ptrdiff_t n;
@@ -331,7 +331,11 @@ unexec (const char *new_name, const char *old_name)
 
   new_break = sbrk (0);
   new_bss_addr = (ElfW (Addr)) new_break;
-  new_data2_size = new_bss_addr - old_bss_addr;
+  bss_size_growth = new_bss_addr - old_bss_addr;
+  new_data2_size = bss_size_growth;
+  new_data2_size += alignof (ElfW (Shdr)) - 1;
+  new_data2_size -= new_data2_size % alignof (ElfW (Shdr));
+
   new_data2_offset = old_bss_offset;
 
 #ifdef UNEXELF_DEBUG
@@ -399,7 +403,8 @@ unexec (const char *new_name, const char *old_name)
   new_bss_seg->p_memsz = new_bss_seg->p_filesz;
 
   /* Copy over what we have in memory now for the bss area. */
-  memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr, new_data2_size);
+  memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr,
+	  bss_size_growth);
 
   /* Walk through all section headers, copying data and updating.  */
   for (n = 1; n < old_file_h->e_shnum; n++)
-- 
2.1.0


  parent reply	other threads:[~2015-11-17  1:59 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20  7:56 bug#20614: Segmentation fault when building on Power8 Little Endian Petr Hracek
2015-05-20 14:45 ` Eli Zaretskii
2015-05-20 16:12 ` Glenn Morris
2015-05-21 12:55   ` Petr Hracek
2015-07-13 11:27     ` Petr Hracek
2015-07-13 13:16       ` Andreas Schwab
2015-07-14  7:52         ` Petr Hracek
2015-07-14  8:14           ` Andreas Schwab
2015-09-16 11:28           ` Petr Hracek
2015-09-22 10:17             ` Petr Hracek
2015-09-23  8:06               ` Petr Hracek
2015-09-23  9:34                 ` Eli Zaretskii
2015-09-23 11:00                   ` Petr Hracek
2015-09-23 11:14                     ` Eli Zaretskii
2015-09-23 12:11                       ` Petr Hracek
2015-09-23 12:23                         ` Eli Zaretskii
2015-09-24 11:04                           ` Petr Hracek
2015-09-24 15:32                             ` Eli Zaretskii
2015-09-24 17:56                               ` Petr Hracek
2015-09-26  7:58                                 ` Eli Zaretskii
2015-09-30 10:39                                   ` Petr Hracek
2015-10-01  7:43                                     ` Eli Zaretskii
2015-10-01  8:46                                       ` Petr Hracek
2015-10-01 11:44                                       ` Petr Hracek
2015-10-01 11:53                                       ` Petr Hracek
2015-10-01 12:22                                         ` Eli Zaretskii
2015-10-01 14:05                                           ` Petr Hracek
2015-10-01 16:01                                             ` Eli Zaretskii
2015-10-02  8:36                                               ` Petr Hracek
2015-10-02  8:49                                                 ` Eli Zaretskii
2015-10-02 12:58                                                   ` Petr Hracek
2015-10-02 13:46                                                     ` Eli Zaretskii
2015-10-05  7:40                                                       ` Petr Hracek
2015-10-05  8:27                                                         ` Eli Zaretskii
2015-10-05  9:16                                                           ` Petr Hracek
2015-10-05  9:39                                                             ` Eli Zaretskii
2015-10-05 11:23                                                               ` Petr Hracek
2015-10-05 11:40                                                                 ` Eli Zaretskii
2015-10-05 14:07                                                                   ` Petr Hracek
2015-10-05 16:52                                                                     ` Eli Zaretskii
2015-10-06  8:41                                                                       ` Petr Hracek
2015-10-06 11:52                                                                         ` Petr Hracek
2015-10-06 14:55                                                                           ` Eli Zaretskii
2015-10-07  8:17                                                                             ` Petr Hracek
2015-10-07 10:56                                                                               ` YAMAMOTO Mitsuharu
2015-10-07 12:26                                                                                 ` Petr Hracek
2015-10-08  0:54                                                                                   ` YAMAMOTO Mitsuharu
2015-10-08 13:27                                                                                     ` Jaromir Capik
2015-10-10  1:40                                                                                       ` YAMAMOTO Mitsuharu
2015-10-10 15:44                                                                                         ` Andreas Schwab
2015-10-13  7:30                                                                                           ` Petr Hracek
2015-10-13  8:30                                                                                             ` Andreas Schwab
2015-10-16 15:24                                                                                               ` Jaromir Capik
2015-10-19  7:20                                                                                                 ` Andreas Schwab
2015-09-23 12:10                   ` Petr Hracek
2015-09-23 12:21                     ` Eli Zaretskii
2015-09-23 13:10                       ` Petr Hracek
2015-09-23 13:38                       ` Petr Hracek
2015-09-23 13:57                         ` Eli Zaretskii
2015-09-23 17:25                           ` Glenn Morris
2015-09-23 17:47               ` Glenn Morris
2015-09-29  8:15                 ` Florian Weimer
2015-07-13 12:17   ` bug#20614: Segmentation fault when building on Power8 Little Endian (ppc64le) Petr Hracek
2015-11-17  1:59 ` Paul Eggert [this message]
2015-11-17  9:03   ` bug#20614: alignment problem with recent Emacs unexelf.c changes Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=564A89FD.6080206@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=20614@debbugs.gnu.org \
    --cc=amodra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).