From patchwork Tue Nov 26 13:03:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: christian.braunersorensen@prevas.dk X-Patchwork-Id: 294323 X-Patchwork-Delegate: esben@haabendal.dk Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hugin.dotsrc.org (hugin.dotsrc.org [IPv6:2001:878:346::102]) by ozlabs.org (Postfix) with ESMTP id 740C52C00AD for ; Wed, 27 Nov 2013 00:03:28 +1100 (EST) Received: from hugin.dotsrc.org (localhost [127.0.0.1]) by hugin.dotsrc.org (Postfix) with ESMTP id 96E543FC9E for ; Tue, 26 Nov 2013 14:03:23 +0100 (CET) X-Original-To: dev@oe-lite.org Delivered-To: dev@oe-lite.org Received: from mail01.prevas.se (mail01.prevas.se [62.95.78.3]) by hugin.dotsrc.org (Postfix) with ESMTPS id 98FCE3F8F3 for ; Tue, 26 Nov 2013 14:03:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=3509; q=dns/txt; s=ironport1; t=1385471001; x=1417007001; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MVY5xf0Ba4j1JSdAZRexldnfJrVV5F4YBcw2DF6DbP4=; b=fNZ/dns0wIjenbY5KIuhOiptWxu7kPFLpOtZ4mvs+tbrM1mYTQe5252a +KvEVR5ao6edvhjQsqCofBYjLL5yf6dxiN7mFe+UgkvDF7O2jEzNZT1yt Y3AtC5mtxUgpbJsRB3kG421v+inHqXQFm7pFbARsQ5rY+Tfq/kbC6/2Uc g=; X-IronPort-AV: E=Sophos;i="4.93,774,1378850400"; d="scan'208";a="4175582" Received: from vmprevas3.prevas.se (HELO smtp.prevas.se) ([172.16.8.103]) by ironport1.prevas.se with ESMTP/TLS/AES128-SHA; 26 Nov 2013 14:03:20 +0100 Received: from localhost (172.16.10.102) by smtp.prevas.se (172.16.8.105) with Microsoft SMTP Server id 14.2.347.0; Tue, 26 Nov 2013 14:03:20 +0100 Received: by localhost (Postfix, from userid 30007) id 789076814DB; Tue, 26 Nov 2013 13:03:20 +0000 (UTC) From: To: Subject: [PATCH 1/4] elfwrapper: Add new class for the elfwrapper function. Date: Tue, 26 Nov 2013 13:03:16 +0000 Message-ID: X-Mailer: git-send-email 1.8.4 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dev@oe-lite.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: OE-lite development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dev-bounces@oe-lite.org Errors-To: dev-bounces@oe-lite.org From: Christian Sørensen Signed-off-by: Christian Sørensen --- classes/elfwrapper.oeclass | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 classes/elfwrapper.oeclass diff --git a/classes/elfwrapper.oeclass b/classes/elfwrapper.oeclass new file mode 100644 index 0000000..33ab1a0 --- /dev/null +++ b/classes/elfwrapper.oeclass @@ -0,0 +1,77 @@ +## Class for wrapping elf +## +## Has included fixes for non-static images +## toolchains w.r.t. ensuring that the correct libraries are chosen when using +## binary tools. +## +## @var SDK_IMAGE_ELF_SOWRAP_DIRS If set, ensures that the correct libraries +## is used when executing binary files. This is ofcause only relevant for +## non-static toolchains. Moves the binary tools to ., and uses a wrapper +## that uses ld-linux to ensure that the correct libraries is chosen. + +IMAGE_ELF_SOWRAP_DIRS ?= "${base_bindir} ${bindir}" +IMAGE_ELF_SOWRAP_LD_SO ?= "/lib/ld-linux*.so.*" + +RSTAGE_FIXUP_FUNCS += "${IMAGE_PREPROCESS_ELF_SOWRAP}" +IMAGE_PREPROCESS_ELF_SOWRAP = "" +IMAGE_PREPROCESS_ELF_SOWRAP:HOST_BINFMT_elf = " image_preprocess_elf_sowrap" +def image_preprocess_elf_sowrap(d): + import stat + import magic + + filemagic = magic.open(magic.MAGIC_NONE) + filemagic.load() + host_elf_re = re.compile(d.get("HOST_ELF")) + ld_so = d.get("IMAGE_ELF_SOWRAP_LD_SO") + + def is_elf(path): + filetype = filemagic.file(path) + return bool(host_elf_re.match(filetype)) + + def is_static(path): + filetype = filemagic.file(path) + static_re = re.compile(".*statically.*") + return bool(static_re.match(filetype)) + + def sowrap_dir(dir, recursive=False): + if not os.path.exists(dir): + return True + assert os.path.isdir(dir) + ok = True + for file in os.listdir(dir): + path = os.path.join(dir, file) + if os.path.islink(path): + continue + if os.path.isdir(path): + if recursive: + sowrap_dir(path, recursive) + continue + dotpath = "%s/.%s"%(os.path.dirname(path), os.path.basename(path)) + if os.path.exists(dotpath): + print "ERROR: file already exists:", os.path.join(dir, path) + ok = False + continue + if is_elf(path) and is_static(path): + continue + os.rename(path, dotpath) + with open(path, "w") as wrapper: + dirparts = len(os.path.dirname(path).split('/')) + relative_root = "/".join([".."] * dirparts) + wrapper.write("#!/bin/sh\n") + wrapper.write("$(dirname $0)/%s%s $(dirname $0)/%s $*\n"%( + relative_root, ld_so, os.path.basename(dotpath))) + os.chmod(path, stat.S_IRWXU|stat.S_IRWXG|stat.S_IROTH|stat.S_IXOTH) + return True + + bindirs = set(d.get("IMAGE_ELF_SOWRAP_DIRS").split()) + for dir in bindirs: + recursive=False + if dir.endswith("//"): + recursive=True + dir = dir.strip("/") + rc = sowrap_dir(dir, recursive) + if not rc: + filemagic.close() + return rc + filemagic.close() + return