[{"id":5050,"web_url":"https://patchwork.libcamera.org/comment/5050/","msgid":"<20200605164254.GB1175@pendragon.ideasonboard.com>","date":"2020-06-05T16:42:54","subject":"Re: [libcamera-devel] [PATCH v2 1/2] libcamera: ipa_module: Share\n\tcode to find section header of ELF header","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Fri, Jun 05, 2020 at 03:09:15PM +0000, Umang Jain wrote:\n> Refactor the code to find section into a common helper function.\n> This commit introduces no functional changes.\n> \n> Signed-off-by: Umang Jain <email@uajain.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/libcamera/ipa_module.cpp | 29 ++++++++++++++++-------------\n>  1 file changed, 16 insertions(+), 13 deletions(-)\n> \n> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\n> index 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 {};","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9818F603C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 18:43:13 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 12AE227C;\n\tFri,  5 Jun 2020 18:43:13 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"qo5thVlY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591375393;\n\tbh=OlnUBoEGGlMFrMGtqb5LFzucl+7iDaSbmoVadQGTEzQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qo5thVlYnsSQA+S7t864xb3vIBIeYJtlFcm8b8MOTCwLBBzrshk0BzSGk9jjWL6IB\n\t4WIp+E8ovUXE8bQJoRAGuyrvew/u3lPY7AMClj5mxKC7vze5+LkyPFTI0f9qJu/m3S\n\tb4L7V751afQoUT6RQNIPHuuskYNmnn3qfXPKM0B8=","Date":"Fri, 5 Jun 2020 19:42:54 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <email@uajain.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200605164254.GB1175@pendragon.ideasonboard.com>","References":"<20200605150858.116564-1-email@uajain.com>\n\t<20200605150858.116564-2-email@uajain.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200605150858.116564-2-email@uajain.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/2] libcamera: ipa_module: Share\n\tcode to 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 16:43:13 -0000"}}]