From patchwork Mon May 4 12:24:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Herrendoerfer" X-Patchwork-Id: 26843 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id D9200B7063 for ; Mon, 4 May 2009 21:57:07 +1000 (EST) Received: by ozlabs.org (Postfix) id E3A89DE3A5; Mon, 4 May 2009 21:56:13 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id E186EDE3A4 for ; Mon, 4 May 2009 21:56:13 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from mtagate3.de.ibm.com (mtagate3.de.ibm.com [195.212.29.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mtagate3.de.ibm.com", Issuer "Equifax" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id A5F06DE362 for ; Mon, 4 May 2009 21:56:09 +1000 (EST) Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate3.de.ibm.com (8.14.3/8.13.8) with ESMTP id n44Bu5pO145462 for ; Mon, 4 May 2009 11:56:05 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n44Bu4bW4133046 for ; Mon, 4 May 2009 13:56:05 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n44Bu4VV031039 for ; Mon, 4 May 2009 13:56:04 +0200 Received: from [9.152.224.35] (dyn-9-152-224-35.boeblingen.de.ibm.com [9.152.224.35]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n44Bu4M7031029 for ; Mon, 4 May 2009 13:56:04 +0200 From: "D. Herrendoerfer" To: cbe-oss-dev@ozlabs.org Date: Mon, 04 May 2009 21:24:48 +0900 Message-Id: <1241439888.3901.10.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.8.3 (2.8.3-2.fc6) Subject: [Cbe-oss-dev] [PATCH]libspe2: Respect PF_OVERLAY flag X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org There is a bug in the libspe2 elf loader that prevents it from correctly loading overlay segments. This was brought up by Ulrich Weigand. Here is the Bug description: spebase/elf_loader.c contains a routine "overlay" that attempts to determine whether a PT_LOAD segment represents an overlay that is not supposed to be loader. However, caller of overlay always passes in a prev_ph argument of NULL, causing overlay to always return 0. This causes all PT_LOAD segments to be loaded, regardless of whether or not they are overlay segments. This causes unnecessary loads to be performed. In addition, if the linker has designated one segment as "overlay init", i.e. pre-loaded contents of the overlay buffer, the ELF loader does not reliably ensure that the overlay init segment is the one that's present after load. The proper identification of overlay segments should use the PF_OVERLAY p_flags bit that the linker sets to indicate PT_LOAD segments that should not be loaded. The following patch fixed this bug. Signed-off-by: D.Herrendoerfer Index: libspe2/spebase/elf_loader.c =================================================================== --- libspe2/spebase/elf_loader.c (revision 136) +++ libspe2/spebase/elf_loader.c (working copy) @@ -33,6 +33,10 @@ #include "elf_loader.h" #include "spebase.h" +#ifndef PF_OVERLAY +#define PF_OVERLAY (1 << 27) +#endif + #ifdef DEBUG static void display_debug_output(Elf32_Ehdr *elf_start, Elf32_Shdr *sh); #endif /*DEBUG*/ @@ -153,20 +157,6 @@ _base_spe_parse_isolated_elf(spe_program return 0; } -static int -overlay(Elf32_Phdr *ph, Elf32_Phdr *prev_ph) -{ - /* - * If our ph segment virtual address fits within that of the - * previous ph, this is an overlay. - */ - if (prev_ph && (ph->p_vaddr >= prev_ph->p_vaddr) && - (ph->p_vaddr < (prev_ph->p_vaddr + prev_ph->p_memsz))) - return 1; - else - return 0; -} - static void copy_to_ld_buffer(spe_program_handle_t *handle, void *buffer, Elf32_Phdr *ph, Elf32_Off toe_addr, long toe_size) @@ -242,7 +232,7 @@ _base_spe_load_spe_elf (spe_program_hand { Elf32_Ehdr *ehdr; Elf32_Phdr *phdr; - Elf32_Phdr *ph, *prev_ph; + Elf32_Phdr *ph; Elf32_Shdr *shdr; Elf32_Shdr *sh; @@ -303,10 +293,10 @@ _base_spe_load_spe_elf (spe_program_hand * Load all PT_LOAD segments onto the SPE local store buffer. */ DEBUG_PRINTF("Segments: 0x%x\n", ehdr->e_phnum); - for (ph = phdr, prev_ph = NULL; ph < &phdr[ehdr->e_phnum]; ++ph) { + for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph) { switch (ph->p_type) { case PT_LOAD: - if (!overlay(ph, prev_ph)) { + if (!(ph->p_flags & PF_OVERLAY)) { if (ph->p_filesz < ph->p_memsz) { DEBUG_PRINTF("padding loaded image with zeros:\n"); DEBUG_PRINTF("start: 0x%04x\n", ph->p_vaddr + ph->p_filesz);