From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IuCnX-00089K-Be for mharc-grub-devel@gnu.org; Mon, 19 Nov 2007 15:00:47 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IuCnV-00087I-Sd for grub-devel@gnu.org; Mon, 19 Nov 2007 15:00:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IuCnU-00085g-7J for grub-devel@gnu.org; Mon, 19 Nov 2007 15:00:45 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IuCnT-00085F-T7 for grub-devel@gnu.org; Mon, 19 Nov 2007 15:00:43 -0500 Received: from mailout09.sul.t-online.de ([194.25.134.84] helo=mailout09.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IuCnT-0003EL-Ai for grub-devel@gnu.org; Mon, 19 Nov 2007 15:00:43 -0500 Received: from fwd26.aul.t-online.de by mailout09.sul.t-online.com with smtp id 1IuCnR-0004jI-01; Mon, 19 Nov 2007 21:00:41 +0100 Received: from [10.3.2.2] (SsF+KBZBghsncc-nsypOi8wmEKiF-8jRe-9DzwMWZD+Rg6zdQFeU2e+xvILWwZRZlB@[217.235.205.150]) by fwd26.aul.t-online.de with esmtp id 1IuCn1-0HSsb20; Mon, 19 Nov 2007 21:00:15 +0100 Message-ID: <4741EB4F.7060402@t-online.de> Date: Mon, 19 Nov 2007 21:00:15 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------040708040406010002090208" X-ID: SsF+KBZBghsncc-nsypOi8wmEKiF-8jRe-9DzwMWZD+Rg6zdQFeU2e+xvILWwZRZlB X-TOI-MSGID: 3f1a9e84-51fa-4c21-876b-5edb19456d2b X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] Load ELF module with bad pc-relative relocation info X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Nov 2007 20:00:46 -0000 This is a multi-part message in MIME format. --------------040708040406010002090208 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch allows to load modules with bad pc-relative relocation info produced by "objcopy -I pe-i386 -O elf32-i386" (See also thread "Building GRUB on platforms without ELF support") Christian 2007-11-19 Christian Franke * kern/i386/dl.c [__CYGWIN__] (fix_pc_rel_relocation): New function to fix bad PC relative relocation produced by objcopy. [__CYGWIN__] (grub_arch_dl_relocate_symbols): Add fix of PC relative relocation. (grub_arch_dl_relocate_symbols): Abort on unknown relocation type. --------------040708040406010002090208 Content-Type: text/x-patch; name="grub2-i386_dl-Cygwin.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-i386_dl-Cygwin.patch" --- grub2.orig/kern/i386/dl.c 2007-07-22 01:32:26.000000000 +0200 +++ grub2/kern/i386/dl.c 2007-11-19 20:50:52.609375000 +0100 @@ -37,6 +37,28 @@ grub_arch_dl_check_header (void *ehdr) return GRUB_ERR_NONE; } +#ifdef __CYGWIN__ +/* Fix PC relative relocation. Objcopy does not adjust +the addent when converting from pe-i386 to elf32-i386. */ +static int +fix_pc_rel_relocation (Elf32_Word *addr) +{ + /* To be safe, check instruction first. */ + const unsigned char * pc = (const unsigned char *)addr - 1; + if (!(*pc == 0xe8/*call*/ || *pc == 0xe9/*jmp*/)) + return grub_error (GRUB_ERR_BAD_MODULE, "unknown pc-relative instruction %02x", *pc); + /* Check and adjust offset. */ + if (*addr != (Elf32_Word)-4) + { + if (*addr != 0) + return grub_error (GRUB_ERR_BAD_MODULE, "invalid pc-relative relocation base %lx", + (long)(*addr)); + *addr = (Elf32_Word)-4; + } + return GRUB_ERR_NONE; +} +#endif + /* Relocate symbols. */ grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) @@ -99,9 +121,17 @@ grub_arch_dl_relocate_symbols (grub_dl_t break; case R_386_PC32: +#ifdef __CYGWIN__ + if (fix_pc_rel_relocation (addr)) + return grub_errno; +#endif *addr += (sym->st_value - (Elf32_Word) seg->addr - rel->r_offset); break; + + default: + return grub_error (GRUB_ERR_BAD_MODULE, "unknown relocation type %x.", + ELF32_R_TYPE (rel->r_info)); } } } --------------040708040406010002090208--