]> code.delx.au - gnu-emacs/blobdiff - src/unexelf.c
Merge from origin/emacs-25
[gnu-emacs] / src / unexelf.c
index c10c7f21bf2ab774b9a277eacacc070234362b79..551915712fb95c40fa95eb8dee5da289afea39d0 100644 (file)
@@ -1,12 +1,12 @@
-/* Copyright (C) 1985-1988, 1990, 1992, 1999-2015 Free Software
+/* Copyright (C) 1985-1988, 1990, 1992, 1999-2016 Free Software
    Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs 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.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -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++)
@@ -456,29 +461,6 @@ unexec (const char *new_name, const char *old_name)
          || !strcmp (old_section_names + new_shdr->sh_name, ".sdata")
          || !strcmp (old_section_names + new_shdr->sh_name, ".lit4")
          || !strcmp (old_section_names + new_shdr->sh_name, ".lit8")
-         /* The conditional bit below was in Oliva's original code
-            (1999-08-25) and seems to have been dropped by mistake
-            subsequently.  It prevents a crash at startup under X in
-            `IRIX64 6.5 6.5.17m', whether compiled on that release or
-            an earlier one.  It causes no trouble on the other ELF
-            platforms I could test (Irix 6.5.15m, Solaris 8, Debian
-            Potato x86, Debian Woody SPARC); however, it's reported
-            to cause crashes under some version of GNU/Linux.  It's
-            not yet clear what's changed in that Irix version to
-            cause the problem, or why the fix sometimes fails under
-            GNU/Linux.  There's probably no good reason to have
-            something Irix-specific here, but this will have to do
-            for now.  IRIX6_5 is the most specific macro we have to
-            test.  -- fx 2002-10-01
-
-            The issue _looks_ as though it's gone away on 6.5.18m,
-            but maybe it's still lurking, to be triggered by some
-            change in the binary.  It appears to concern the dynamic
-            loader, but I never got anywhere with an SGI support call
-            seeking clues.  -- fx 2002-11-29.  */
-#ifdef IRIX6_5
-         || !strcmp (old_section_names + new_shdr->sh_name, ".got")
-#endif
          || !strcmp (old_section_names + new_shdr->sh_name, ".sdata1")
          || !strcmp (old_section_names + new_shdr->sh_name, ".data1"))
        src = (caddr_t) old_shdr->sh_addr;
@@ -660,9 +642,6 @@ unexec (const char *new_name, const char *old_name)
              || !strcmp (old_section_names + shdr->sh_name, ".sdata")
              || !strcmp (old_section_names + shdr->sh_name, ".lit4")
              || !strcmp (old_section_names + shdr->sh_name, ".lit8")
-#ifdef IRIX6_5                 /* see above */
-             || !strcmp (old_section_names + shdr->sh_name, ".got")
-#endif
              || !strcmp (old_section_names + shdr->sh_name, ".sdata1")
              || !strcmp (old_section_names + shdr->sh_name, ".data1"))
            {