aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-11-16 17:48:08 -0800
committerPaul Eggert2015-11-16 17:48:52 -0800
commitc9fd597a4cffcae873b25381ee8cc755f0debe95 (patch)
tree0c924c1268813c82c6a6863a2da9149efee45772 /src
parent1cdddc1db6243cf90467e5736cc897718267f389 (diff)
downloademacs-c9fd597a4cffcae873b25381ee8cc755f0debe95.tar.gz
emacs-c9fd597a4cffcae873b25381ee8cc755f0debe95.zip
ELF unexec: align section header
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.
Diffstat (limited to 'src')
-rw-r--r--src/unexelf.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/unexelf.c b/src/unexelf.c
index c10c7f21bf2..03e6dafe8ee 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -247,7 +247,7 @@ unexec (const char *new_name, const char *old_name)
247 247
248 ElfW (Phdr) *old_bss_seg, *new_bss_seg; 248 ElfW (Phdr) *old_bss_seg, *new_bss_seg;
249 ElfW (Addr) old_bss_addr, new_bss_addr; 249 ElfW (Addr) old_bss_addr, new_bss_addr;
250 ElfW (Word) old_bss_size, new_data2_size; 250 ElfW (Word) old_bss_size, bss_size_growth, new_data2_size;
251 ElfW (Off) old_bss_offset, new_data2_offset; 251 ElfW (Off) old_bss_offset, new_data2_offset;
252 252
253 ptrdiff_t n; 253 ptrdiff_t n;
@@ -331,7 +331,11 @@ unexec (const char *new_name, const char *old_name)
331 331
332 new_break = sbrk (0); 332 new_break = sbrk (0);
333 new_bss_addr = (ElfW (Addr)) new_break; 333 new_bss_addr = (ElfW (Addr)) new_break;
334 new_data2_size = new_bss_addr - old_bss_addr; 334 bss_size_growth = new_bss_addr - old_bss_addr;
335 new_data2_size = bss_size_growth;
336 new_data2_size += alignof (ElfW (Shdr)) - 1;
337 new_data2_size -= new_data2_size % alignof (ElfW (Shdr));
338
335 new_data2_offset = old_bss_offset; 339 new_data2_offset = old_bss_offset;
336 340
337#ifdef UNEXELF_DEBUG 341#ifdef UNEXELF_DEBUG
@@ -399,7 +403,8 @@ unexec (const char *new_name, const char *old_name)
399 new_bss_seg->p_memsz = new_bss_seg->p_filesz; 403 new_bss_seg->p_memsz = new_bss_seg->p_filesz;
400 404
401 /* Copy over what we have in memory now for the bss area. */ 405 /* Copy over what we have in memory now for the bss area. */
402 memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr, new_data2_size); 406 memcpy (new_base + new_data2_offset, (caddr_t) old_bss_addr,
407 bss_size_growth);
403 408
404 /* Walk through all section headers, copying data and updating. */ 409 /* Walk through all section headers, copying data and updating. */
405 for (n = 1; n < old_file_h->e_shnum; n++) 410 for (n = 1; n < old_file_h->e_shnum; n++)