{"id":3955,"url":"https://patchwork.libcamera.org/api/1.1/patches/3955/?format=json","web_url":"https://patchwork.libcamera.org/patch/3955/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200605150858.116564-2-email@uajain.com>","date":"2020-06-05T15:09:15","name":"[libcamera-devel,v2,1/2] libcamera: ipa_module: Share code to find section header of ELF header","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"dc6ebacc8d724c77100732f8d2855944c9f9256e","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3955/mbox/","series":[{"id":960,"url":"https://patchwork.libcamera.org/api/1.1/series/960/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=960","date":"2020-06-05T15:09:14","name":"Fix implicit sign-extension","version":2,"mbox":"https://patchwork.libcamera.org/series/960/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3955/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3955/checks/","tags":{},"headers":{"Return-Path":"<bounces+15657259-5c31-libcamera-devel=lists.libcamera.org@em7280.uajain.com>","Received":["from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 36E92603C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 17:09:17 +0200 (CEST)","by filterdrecv-p3mdw1-6f5df8956d-kv7d9 with SMTP id\n\tfilterdrecv-p3mdw1-6f5df8956d-kv7d9-18-5EDA601B-BE\n\t2020-06-05 15:09:15.822666942 +0000 UTC m=+154531.627509264","from mail.uajain.com (unknown)\n\tby ismtpd0001p1hnd1.sendgrid.net (SG) with ESMTP\n\tid LG82QwtEQbe3u7aRRDM7Jw Fri, 05 Jun 2020 15:09:15.363 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=uajain.com\n\theader.i=@uajain.com header.b=\"e7lGb34b\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=5URSrVwfItFKLaIVPc0Od4f5rDegonIvdwSZWkaMtwQ=;\n\tb=e7lGb34bkyKhvVSeleYsZUbaDJGVqLDU0W9BEzzyS2ZHAqnwbnHi+icw96EebPdQLW9H\n\tF+zY+ruvtcUiKHsuwPwK8Ta63ER4w/dDQ12Y+U1DPNjNvek/lc3+4Fwf0oem5zS7L/h6Ke\n\tvWsmC6IWY/HtLWNrDtN45NIibyO0rhb6s=","From":"Umang Jain <email@uajain.com>","Date":"Fri, 05 Jun 2020 15:09:15 +0000 (UTC)","Message-Id":"<20200605150858.116564-2-email@uajain.com>","In-Reply-To":"<20200605150858.116564-1-email@uajain.com>","References":"<20200605150858.116564-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcQ/i1ji5k4eTSSnQ1oTeZ4rVORBi2+GzXl6lq1M8d1q8gY7dYCQcM1ji7xSIbstvM4si/OMaU2pcr7gdFwP8GdbYPBJLEH3wVW245GwRx9/o3nsqum/7vPRKSFYGRbpM3ZeS/J2je18jF9hfnWF65dkrfFyc5fRqdm5tRAc4eNDkmcoCHrKJXnvusZWeMf5xOa8mBgJN4JBVx8iTmJ3AJrg==","To":"laurent.pinchart@ideasonboard.com, libcamera-devel@lists.libcamera.org","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=us-ascii","Subject":"[libcamera-devel] [PATCH v2 1/2] libcamera: ipa_module: Share code\n\tto find section header of ELF header","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 15:09:17 -0000"},"content":"Refactor the code to find section into a common helper function.\nThis commit introduces no functional changes.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n src/libcamera/ipa_module.cpp | 29 ++++++++++++++++-------------\n 1 file changed, 16 insertions(+), 13 deletions(-)","diff":"diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\nindex 045c8fc..f54dd8b 100644\n--- a/src/libcamera/ipa_module.cpp\n+++ b/src/libcamera/ipa_module.cpp\n@@ -88,6 +88,15 @@ int elfVerifyIdent(Span<uint8_t> elf)\n \treturn 0;\n }\n \n+ElfW(Shdr) *elfSection(Span<uint8_t> elf, ElfW(Ehdr) *eHdr, unsigned int idx)\n+{\n+\tif (idx >= eHdr->e_shnum)\n+\t\treturn nullptr;\n+\n+\toff_t offset = eHdr->e_shoff + idx * eHdr->e_shentsize;\n+\treturn elfPointer<ElfW(Shdr)>(elf, offset);\n+}\n+\n /**\n  * \\brief Retrieve address and size of a symbol from an mmap'ed ELF file\n  * \\param[in] elf Address and size of mmap'ed ELF file\n@@ -102,8 +111,7 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \tif (!eHdr)\n \t\treturn {};\n \n-\toff_t offset = eHdr->e_shoff + eHdr->e_shentsize * eHdr->e_shstrndx;\n-\tElfW(Shdr) *sHdr = elfPointer<ElfW(Shdr)>(elf, offset);\n+\tElfW(Shdr) *sHdr = elfSection(elf, eHdr, eHdr->e_shstrndx);\n \tif (!sHdr)\n \t\treturn {};\n \toff_t shnameoff = sHdr->sh_offset;\n@@ -111,12 +119,11 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \t/* Locate .dynsym section header. */\n \tElfW(Shdr) *dynsym = nullptr;\n \tfor (unsigned int i = 0; i < eHdr->e_shnum; i++) {\n-\t\toffset = eHdr->e_shoff + eHdr->e_shentsize * i;\n-\t\tsHdr = elfPointer<ElfW(Shdr)>(elf, offset);\n+\t\tsHdr = elfSection(elf, eHdr, i);\n \t\tif (!sHdr)\n \t\t\treturn {};\n \n-\t\toffset = shnameoff + sHdr->sh_name;\n+\t\toff_t offset = shnameoff + sHdr->sh_name;\n \t\tchar *name = elfPointer<char[8]>(elf, offset);\n \t\tif (!name)\n \t\t\treturn {};\n@@ -132,8 +139,7 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \t\treturn {};\n \t}\n \n-\toffset = eHdr->e_shoff + eHdr->e_shentsize * dynsym->sh_link;\n-\tsHdr = elfPointer<ElfW(Shdr)>(elf, offset);\n+\tsHdr = elfSection(elf, eHdr, dynsym->sh_link);\n \tif (!sHdr)\n \t\treturn {};\n \toff_t dynsym_nameoff = sHdr->sh_offset;\n@@ -142,7 +148,7 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \tElfW(Sym) *targetSymbol = nullptr;\n \tunsigned int dynsym_num = dynsym->sh_size / dynsym->sh_entsize;\n \tfor (unsigned int i = 0; i < dynsym_num; i++) {\n-\t\toffset = dynsym->sh_offset + dynsym->sh_entsize * i;\n+\t\toff_t offset = dynsym->sh_offset + dynsym->sh_entsize * i;\n \t\tElfW(Sym) *sym = elfPointer<ElfW(Sym)>(elf, offset);\n \t\tif (!sym)\n \t\t\treturn {};\n@@ -165,13 +171,10 @@ Span<uint8_t> elfLoadSymbol(Span<uint8_t> elf, const char *symbol)\n \t}\n \n \t/* Locate and return data of symbol. */\n-\tif (targetSymbol->st_shndx >= eHdr->e_shnum)\n-\t\treturn {};\n-\toffset = eHdr->e_shoff + targetSymbol->st_shndx * eHdr->e_shentsize;\n-\tsHdr = elfPointer<ElfW(Shdr)>(elf, offset);\n+\tsHdr = elfSection(elf, eHdr, targetSymbol->st_shndx);\n \tif (!sHdr)\n \t\treturn {};\n-\toffset = sHdr->sh_offset + (targetSymbol->st_value - sHdr->sh_addr);\n+\toff_t offset = sHdr->sh_offset + (targetSymbol->st_value - sHdr->sh_addr);\n \tuint8_t *data = elfPointer<uint8_t>(elf, offset, targetSymbol->st_size);\n \tif (!data)\n \t\treturn {};\n","prefixes":["libcamera-devel","v2","1/2"]}