{"id":3978,"url":"https://patchwork.libcamera.org/api/patches/3978/?format=json","web_url":"https://patchwork.libcamera.org/patch/3978/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20200607143012.17752-2-email@uajain.com>","date":"2020-06-07T14:30:18","name":"[libcamera-devel,v3,1/2] libcamera: ipa_module: Share code to find section header of ELF header","commit_ref":"6f6da7f8542481de8712bd46b720da9b13ce2e9c","pull_url":null,"state":"accepted","archived":false,"hash":"b5bd4f3a4c3e5de07dee366aa065d1fc91170842","submitter":{"id":1,"url":"https://patchwork.libcamera.org/api/people/1/?format=json","name":"Umang Jain","email":"email@uajain.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3978/mbox/","series":[{"id":967,"url":"https://patchwork.libcamera.org/api/series/967/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=967","date":"2020-06-07T14:30:17","name":"Fix implicit sign extension","version":3,"mbox":"https://patchwork.libcamera.org/series/967/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3978/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3978/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 A33AC600F7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  7 Jun 2020 16:30:19 +0200 (CEST)","by filterdrecv-p3mdw1-6f5df8956d-8rppr with SMTP id\n\tfilterdrecv-p3mdw1-6f5df8956d-8rppr-20-5EDCF9FA-46\n\t2020-06-07 14:30:18.473731592 +0000 UTC m=+324990.134891972","from mail.uajain.com (unknown)\n\tby ismtpd0008p1maa1.sendgrid.net (SG) with ESMTP\n\tid JS1To19sQaaSs9PR6LSkpQ Sun, 07 Jun 2020 14:30:17.787 +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=\"F+7phBrX\"; \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=2jabfmk5QR7Db/ZzwTlL0K8EIHd6SdbXBkLwGfoEG7s=;\n\tb=F+7phBrXBYkwTX8PE9syy2FDZhtQNL9LFU0/e8Z/O5lhFty/S6Z0wSy8EJKZTEy4j7i3\n\t9C5LZFCAQEgZ2BJUgxt1oS7/GGWuunu6T1FUmlOIXyCVcpE67V3p+Gh5064rHDM34ZASSo\n\tZoLcGmBD8jN1wU1r2QTIFepKgDUZTiCn4=","From":"Umang Jain <email@uajain.com>","Date":"Sun, 07 Jun 2020 14:30:18 +0000 (UTC)","Message-Id":"<20200607143012.17752-2-email@uajain.com>","In-Reply-To":"<20200607143012.17752-1-email@uajain.com>","References":"<20200607143012.17752-1-email@uajain.com>","Mime-Version":"1.0","X-SG-EID":"1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcGsFXrTC3nkaVUz7y/MXE3aIrlXxsCQ5m4ALiEPD7h7ovoYuI8rMAdRC0ZWithFTpYl7lK6P+7uq966qmJ9nDdeZ9aZ7jWmIbf9goYdnYdqiyyV8o9ESSKrU3mkJc4w3ibxSRTXOED1Je4hnpHyLxaybSH+01mZTLZOqZN9IEIFMDY1kGl442ZQQzkkfmEl9lai45zAzGZGjzD3itEisnYg==","To":"laurent.pinchart@ideasonboard.com, libcamera-devel@lists.libcamera.org, \n\tkieran.bingham@ideasonboard.com","Content-Transfer-Encoding":"7bit","Content-Type":"text/plain; charset=us-ascii","Subject":"[libcamera-devel] [PATCH v3 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":"Sun, 07 Jun 2020 14:30:20 -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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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..60aaa34 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, ElfW(Half) 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","v3","1/2"]}