From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Schwab Newsgroups: gmane.emacs.bugs Subject: bug#20614: Segmentation fault when building on Power8 Little Endian Date: Sat, 10 Oct 2015 17:44:24 +0200 Message-ID: <874mhy4tk7.fsf@igel.home> References: <555C3E3C.4090700@redhat.com> <5613894B.9070902@redhat.com> <5613B614.4090805@redhat.com> <83egh8xczn.fsf@gnu.org> <5614D522.9080900@redhat.com> <56150F86.2070706@redhat.com> <1486765641.67448157.1444310865021.JavaMail.zimbra@redhat.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1444491925 11868 80.91.229.3 (10 Oct 2015 15:45:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 Oct 2015 15:45:25 +0000 (UTC) Cc: Jaromir Capik , 20614@debbugs.gnu.org To: YAMAMOTO Mitsuharu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Oct 10 17:45:13 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZkwKd-0006OO-Ke for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Oct 2015 17:45:11 +0200 Original-Received: from localhost ([::1]:45274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkwKc-0002LU-6a for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Oct 2015 11:45:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkwKY-0002JQ-R5 for bug-gnu-emacs@gnu.org; Sat, 10 Oct 2015 11:45:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkwKV-00014f-K4 for bug-gnu-emacs@gnu.org; Sat, 10 Oct 2015 11:45:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkwKV-00014b-HQ for bug-gnu-emacs@gnu.org; Sat, 10 Oct 2015 11:45:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZkwKU-0002FM-VL for bug-gnu-emacs@gnu.org; Sat, 10 Oct 2015 11:45:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas Schwab Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Oct 2015 15:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20614 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20614-submit@debbugs.gnu.org id=B20614.14444918708583 (code B ref 20614); Sat, 10 Oct 2015 15:45:02 +0000 Original-Received: (at 20614) by debbugs.gnu.org; 10 Oct 2015 15:44:30 +0000 Original-Received: from localhost ([127.0.0.1]:35533 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZkwJx-0002EM-R6 for submit@debbugs.gnu.org; Sat, 10 Oct 2015 11:44:30 -0400 Original-Received: from mx2.suse.de ([195.135.220.15]:39216) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZkwJv-0002ED-F5 for 20614@debbugs.gnu.org; Sat, 10 Oct 2015 11:44:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Original-Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CCEB4ABF8; Sat, 10 Oct 2015 15:44:24 +0000 (UTC) X-Yow: I'm losing my hair..did it go to ATLANTIC CITY?? In-Reply-To: (YAMAMOTO Mitsuharu's message of "Sat, 10 Oct 2015 10:40:39 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:107509 Archived-At: Please try this patch instead: diff --git a/src/unexelf.c b/src/unexelf.c index 483da6e..2e8b4c7 100644 --- a/src/unexelf.c +++ b/src/unexelf.c @@ -616,6 +616,32 @@ find_section (const char *name, const char *section_names, const char *file_name return -1; } +/* Find the index of the first bss (NOBITS) section, count the number + of bss sections that follow and compute the overall size of these + sections. */ +static int +find_bss_sections (const char *file_name, + ElfW(Ehdr) *old_file_h, ElfW(Shdr) *old_section_h, + ElfW (Word) *size, int *num) +{ + ptrdiff_t idx; + + for (idx = 1; idx < old_file_h->e_shnum; idx++) + if (OLD_SECTION_H (idx).sh_type == SHT_NOBITS) + { + ptrdiff_t idx2 = idx; + + while (OLD_SECTION_H (idx2 + 1).sh_type == SHT_NOBITS) + idx2++; + *size = (OLD_SECTION_H (idx2).sh_addr + OLD_SECTION_H (idx2).sh_size + - OLD_SECTION_H (idx).sh_addr); + *num = idx2 + 1 - idx; + return idx; + } + fatal ("Can't find bss section in %s", file_name); + return -1; +} + /* **************************************************************** * unexec * @@ -652,13 +678,14 @@ unexec (const char *new_name, const char *old_name) ElfW (Addr) old_bss_addr, new_bss_addr; ElfW (Word) old_bss_size, new_data2_size; + int n_bss_sections; ElfW (Off) new_data2_offset; ElfW (Addr) new_data2_addr; ElfW (Off) old_bss_offset; ElfW (Word) new_data2_incr; ptrdiff_t n, nn; - ptrdiff_t old_bss_index, old_sbss_index, old_plt_index; + ptrdiff_t old_bss_index; ptrdiff_t old_data_index, new_data2_index; #if defined _SYSTYPE_SYSV || defined __sgi ptrdiff_t old_mdebug_index; @@ -716,50 +743,12 @@ unexec (const char *new_name, const char *old_name) /* Find the old .bss section. Figure out parameters of the new data2 and bss sections. */ - old_bss_index = find_section (".bss", old_section_names, - old_name, old_file_h, old_section_h, 0); - - old_sbss_index = find_section (".sbss", old_section_names, - old_name, old_file_h, old_section_h, 1); - if (old_sbss_index != -1) - if (OLD_SECTION_H (old_sbss_index).sh_type != SHT_NOBITS) - old_sbss_index = -1; - - /* PowerPC64 has .plt in the BSS section. */ - old_plt_index = find_section (".plt", old_section_names, - old_name, old_file_h, old_section_h, 1); - if (old_plt_index != -1) - if (OLD_SECTION_H (old_plt_index).sh_type != SHT_NOBITS) - old_plt_index = -1; + old_bss_index = find_bss_sections (old_name, old_file_h, old_section_h, + &old_bss_size, &n_bss_sections); - if (old_sbss_index == -1 && old_plt_index == -1) - { - old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; - old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; - old_bss_offset = OLD_SECTION_H (old_bss_index).sh_offset; - new_data2_index = old_bss_index; - } - else if (old_plt_index != -1 - && (old_sbss_index == -1 - || (OLD_SECTION_H (old_sbss_index).sh_addr - > OLD_SECTION_H (old_plt_index).sh_addr))) - { - old_bss_addr = OLD_SECTION_H (old_plt_index).sh_addr; - old_bss_size = OLD_SECTION_H (old_bss_index).sh_size - + OLD_SECTION_H (old_plt_index).sh_size; - if (old_sbss_index != -1) - old_bss_size += OLD_SECTION_H (old_sbss_index).sh_size; - old_bss_offset = OLD_SECTION_H (old_plt_index).sh_offset; - new_data2_index = old_plt_index; - } - else - { - old_bss_addr = OLD_SECTION_H (old_sbss_index).sh_addr; - old_bss_size = OLD_SECTION_H (old_bss_index).sh_size - + OLD_SECTION_H (old_sbss_index).sh_size; - old_bss_offset = OLD_SECTION_H (old_sbss_index).sh_offset; - new_data2_index = old_sbss_index; - } + old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; + old_bss_offset = OLD_SECTION_H (old_bss_index).sh_offset; + new_data2_index = old_bss_index; /* Find the old .data section. Figure out parameters of the new data2 and bss sections. */ @@ -851,20 +840,11 @@ unexec (const char *new_name, const char *old_name) { /* Compute maximum of all requirements for alignment of section. */ ElfW (Word) alignment = (NEW_PROGRAM_H (n)).p_align; - if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) + if (OLD_SECTION_H (old_bss_index).sh_addralign > alignment) alignment = OLD_SECTION_H (old_bss_index).sh_addralign; -#ifdef __sgi - /* According to r02kar@x4u2.desy.de (Karsten Kuenne) - and oliva@gnu.org (Alexandre Oliva), on IRIX 5.2, we - always get "Program segment above .bss" when dumping - when the executable doesn't have an sbss section. */ - if (old_sbss_index != -1) -#endif /* __sgi */ if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz - > (old_sbss_index == -1 - ? old_bss_addr - : round_up (old_bss_addr, alignment))) + > round_up (old_bss_addr, alignment)) fatal ("Program segment above .bss in %s", old_name); if (NEW_PROGRAM_H (n).p_type == PT_LOAD @@ -932,12 +912,10 @@ unexec (const char *new_name, const char *old_name) memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), old_file_h->e_shentsize); - if (n == old_bss_index - /* The new bss and sbss section's size is zero, and its file offset - and virtual address should be off by NEW_DATA2_SIZE. */ - || n == old_sbss_index || n == old_plt_index - ) + if (n >= old_bss_index && n < old_bss_index + n_bss_sections) { + /* The new bss section's size is zero, and its file offset + and virtual address should be off by NEW_DATA2_SIZE. */ /* NN should be `old_s?bss_index + 1' at this point. */ NEW_SECTION_H (nn).sh_offset = new_data2_offset + new_data2_size; NEW_SECTION_H (nn).sh_addr = new_data2_addr + new_data2_size; @@ -998,15 +976,6 @@ temacs: && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) PATCH_INDEX (NEW_SECTION_H (nn).sh_info); - if (old_sbss_index != -1) - if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".sbss")) - { - NEW_SECTION_H (nn).sh_offset = - round_up (NEW_SECTION_H (nn).sh_offset, - NEW_SECTION_H (nn).sh_addralign); - NEW_SECTION_H (nn).sh_type = SHT_PROGBITS; - } - /* Now, start to copy the content of sections. */ if (NEW_SECTION_H (nn).sh_type == SHT_NULL || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) @@ -1226,7 +1195,7 @@ temacs: nn = symp->st_shndx; if (nn > old_bss_index) nn--; - if (nn == old_bss_index) + if (nn >= old_bss_index && nn < old_bss_index + n_bss_sections) memset (new, 0, symp->st_size); else { -- 2.6.1 Andreas. -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."