From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14665 invoked by alias); 11 Jan 2012 19:08:39 -0000 Received: (qmail 14656 invoked by uid 22791); 11 Jan 2012 19:08:38 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail1.windriver.com (HELO mail1.windriver.com) (147.11.146.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jan 2012 19:08:22 +0000 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca [147.11.189.40]) by mail1.windriver.com (8.14.3/8.14.3) with ESMTP id q0BJ8Jxh028686 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 11 Jan 2012 11:08:20 -0800 (PST) Received: from Macintosh-5.local (172.25.36.233) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.1.255.0; Wed, 11 Jan 2012 11:08:19 -0800 Message-ID: <4F0DDE22.4060608@windriver.com> Date: Wed, 11 Jan 2012 19:08:00 -0000 From: Mark Hatle User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: CC: Subject: Fix MIPS non-NOBITS after NOBITS in segment error Content-Type: multipart/mixed; boundary="------------050403060805020707050104" X-IsSubscribed: yes Mailing-List: contact prelink-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: prelink-owner@sourceware.org X-SW-Source: 2012-q1/txt/msg00000.txt.bz2 --------------050403060805020707050104 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1620 With recent compilers and linkers it is typical for a MIPS binary to be built with the sections such as: [23] .got PROGBITS 004aafb0 09afb0 00055c 04 WAp 0 $ [24] .sdata PROGBITS 004ab50c 09b50c 000004 00 WAp 0 $ [25] .sbss NOBITS 004ab510 09b510 00003d 00 WAp 0 $ [26] .bss NOBITS 004ab550 09b510 0021cc 00 WA 0 $ [27] .dynstr STRTAB 004bb510 09b510 000b99 00 A 0 $ [28] .gnu.attributes LOOS+ffffff5 00000000 09c0a9 000010 00 0 $ [29] .mdebug.abi32 PROGBITS 004ad71c 09c0b9 000000 00 0 $ [30] .gnu_debuglink PROGBITS 00000000 09c0b9 00000c 00 0 $ [31] .gnu.prelink_undo PROGBITS 00000000 09c0c8 0005bc 01 0 $ When determining if a section is within a segment, simply checking that it fits within the boundaries of that segment is not enough. In the above example, the .mdebug.abi32 fits within the boundaries of the third segment. However with a size of 0 there is nothing for the prelinker to do. The validation that non-NOBITS sections can't come after a PROGBITS fails, because it incorrectly assumes that it is part of the same section as .sbss, and .bss. Using elfutils readelf as a guide, a check was missing in the mapping function that the section had a size > 0. Binutils has a similar check, but it is a bit more specific that the address of a section can not start at the end of a segment. The size > 0 was an easier and more obvious check, which is why it was used. --------------050403060805020707050104 Content-Type: text/plain; x-mac-type=0; x-mac-creator=0; name="prelink_sectoseg.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="prelink_sectoseg.patch" Content-length: 1169 2012-01-04 Mark Hatle * exec.c: Check that a section is larger then 0 bytes when determining the section to segment mapping. This matches the behavior of elfutils - readelf. Otherwise an empty PROGBITS section at the end of a segment will cause a failure. diff --git a/trunk/src/exec.c b/trunk/src/exec.c index 7c8f38f..cf38b72 100644 --- a/trunk/src/exec.c +++ b/trunk/src/exec.c @@ -500,7 +500,8 @@ error_out: int sfirst = 0, slast = 0, last = 0; for (j = 1; j < dso->ehdr.e_shnum; ++j) - if (dso->shdr[j].sh_addr >= dso->phdr[i].p_vaddr + if (dso->shdr[j].sh_size > 0 + && dso->shdr[j].sh_addr >= dso->phdr[i].p_vaddr && dso->shdr[j].sh_addr + dso->shdr[j].sh_size <= dso->phdr[i].p_vaddr + dso->phdr[i].p_memsz) { @@ -572,7 +573,8 @@ error_out: } for (j = 1; j < dso->ehdr.e_shnum; ++j) - if (dso->shdr[j].sh_addr >= dso->phdr[i].p_vaddr + if (dso->shdr[j].sh_size > 0 + && dso->shdr[j].sh_addr >= dso->phdr[i].p_vaddr && dso->shdr[j].sh_addr + dso->shdr[j].sh_size <= dso->phdr[i].p_vaddr + dso->phdr[i].p_memsz) { --------------050403060805020707050104--