-/* 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
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;
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
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++)