{"id":2801,"url":"https://patchwork.libcamera.org/api/1.1/patches/2801/?format=json","web_url":"https://patchwork.libcamera.org/patch/2801/","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":"<20200206215914.25008-1-laurent.pinchart@ideasonboard.com>","date":"2020-02-06T21:59:14","name":"[libcamera-devel] libcamera: ipa_module: Use ElfW() macro for native word size","commit_ref":"68e76b668a5db176e2f817db7dd17e93e63cc30b","pull_url":null,"state":"accepted","archived":false,"hash":"498d76c89e955d4b721833946e32c7eb3411ad7b","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2801/mbox/","series":[{"id":665,"url":"https://patchwork.libcamera.org/api/1.1/series/665/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=665","date":"2020-02-06T21:59:14","name":"[libcamera-devel] libcamera: ipa_module: Use ElfW() macro for native word size","version":1,"mbox":"https://patchwork.libcamera.org/series/665/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2801/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2801/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F7E260864\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Feb 2020 22:59:35 +0100 (CET)","from localhost.localdomain (117.145-247-81.adsl-dyn.isp.belgacom.be\n\t[81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 45484B7D;\n\tThu,  6 Feb 2020 22:59:34 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1581026374;\n\tbh=PgBHwA1u4qJmgg0rSFQbJwt/r3AMKXY6bAiSrG4cGOg=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=EoIAhwyV0rFJj9xm+s7qLCcDC025MpT/SkCSMiqR4pHg7w6GaFAs8/FWH3kV9p9Gg\n\tNMZXHEYueEdYjtE7tSnRdka7iFpDae+gM0lCKoSAYPuhBkwSvjiMpnMeybsoumjmzB\n\tJFgUoO9RNJakFleQM1tUmbR4m3Bz0AzCP2OPdqZI=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  6 Feb 2020 23:59:14 +0200","Message-Id":"<20200206215914.25008-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] libcamera: ipa_module: Use ElfW() macro\n\tfor native word size","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":"Thu, 06 Feb 2020 21:59:35 -0000"},"content":"Access the ELF types corresponding to the native word size using the\nElfW() macro instead of template types. This is the standard method and\nsimplifies the code.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/ipa_module.cpp | 27 ++++++++++-----------------\n 1 file changed, 10 insertions(+), 17 deletions(-)","diff":"diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\nindex 2c355ea8b5e5..de65525b8319 100644\n--- a/src/libcamera/ipa_module.cpp\n+++ b/src/libcamera/ipa_module.cpp\n@@ -13,6 +13,7 @@\n #include <elf.h>\n #include <errno.h>\n #include <fcntl.h>\n+#include <link.h>\n #include <string.h>\n #include <sys/mman.h>\n #include <sys/stat.h>\n@@ -94,25 +95,24 @@ int elfVerifyIdent(void *map, size_t soSize)\n  * \\return zero or error code, address or nullptr, size of symbol or zero,\n  * respectively\n  */\n-template<class ElfHeader, class SecHeader, class SymHeader>\n std::tuple<void *, size_t>\n elfLoadSymbol(void *map, size_t soSize, const char *symbol)\n {\n-\tElfHeader *eHdr = elfPointer<ElfHeader>(map, 0, soSize);\n+\tElfW(Ehdr) *eHdr = elfPointer<ElfW(Ehdr)>(map, 0, soSize);\n \tif (!eHdr)\n \t\treturn std::make_tuple(nullptr, 0);\n \n \toff_t offset = eHdr->e_shoff + eHdr->e_shentsize * eHdr->e_shstrndx;\n-\tSecHeader *sHdr = elfPointer<SecHeader>(map, offset, soSize);\n+\tElfW(Shdr) *sHdr = elfPointer<ElfW(Shdr)>(map, offset, soSize);\n \tif (!sHdr)\n \t\treturn std::make_tuple(nullptr, 0);\n \toff_t shnameoff = sHdr->sh_offset;\n \n \t/* Locate .dynsym section header. */\n-\tSecHeader *dynsym = nullptr;\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<SecHeader>(map, offset, soSize);\n+\t\tsHdr = elfPointer<ElfW(Shdr)>(map, offset, soSize);\n \t\tif (!sHdr)\n \t\t\treturn std::make_tuple(nullptr, 0);\n \n@@ -133,17 +133,17 @@ elfLoadSymbol(void *map, size_t soSize, const char *symbol)\n \t}\n \n \toffset = eHdr->e_shoff + eHdr->e_shentsize * dynsym->sh_link;\n-\tsHdr = elfPointer<SecHeader>(map, offset, soSize);\n+\tsHdr = elfPointer<ElfW(Shdr)>(map, offset, soSize);\n \tif (!sHdr)\n \t\treturn std::make_tuple(nullptr, 0);\n \toff_t dynsym_nameoff = sHdr->sh_offset;\n \n \t/* Locate symbol in the .dynsym section. */\n-\tSymHeader *targetSymbol = nullptr;\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\tSymHeader *sym = elfPointer<SymHeader>(map, offset, soSize);\n+\t\tElfW(Sym) *sym = elfPointer<ElfW(Sym)>(map, offset, soSize);\n \t\tif (!sym)\n \t\t\treturn std::make_tuple(nullptr, 0);\n \n@@ -169,7 +169,7 @@ elfLoadSymbol(void *map, size_t soSize, const char *symbol)\n \tif (targetSymbol->st_shndx >= eHdr->e_shnum)\n \t\treturn std::make_tuple(nullptr, 0);\n \toffset = eHdr->e_shoff + targetSymbol->st_shndx * eHdr->e_shentsize;\n-\tsHdr = elfPointer<SecHeader>(map, offset, soSize);\n+\tsHdr = elfPointer<ElfW(Shdr)>(map, offset, soSize);\n \tif (!sHdr)\n \t\treturn std::make_tuple(nullptr, 0);\n \toffset = sHdr->sh_offset + (targetSymbol->st_value - sHdr->sh_addr);\n@@ -310,14 +310,7 @@ int IPAModule::loadIPAModuleInfo()\n \tif (ret)\n \t\tgoto unmap;\n \n-\tif (sizeof(unsigned long) == 4)\n-\t\tstd::tie(data, dataSize) =\n-\t\t\telfLoadSymbol<Elf32_Ehdr, Elf32_Shdr, Elf32_Sym>\n-\t\t\t\t     (map, soSize, \"ipaModuleInfo\");\n-\telse\n-\t\tstd::tie(data, dataSize) =\n-\t\t\telfLoadSymbol<Elf64_Ehdr, Elf64_Shdr, Elf64_Sym>\n-\t\t\t\t     (map, soSize, \"ipaModuleInfo\");\n+\tstd::tie(data, dataSize) = elfLoadSymbol(map, soSize, \"ipaModuleInfo\");\n \n \tif (data && dataSize == sizeof(info_))\n \t\tmemcpy(&info_, data, dataSize);\n","prefixes":["libcamera-devel"]}