From patchwork Mon Feb 1 15:53:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Martin X-Patchwork-Id: 576601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id 5AF72140C4E for ; Tue, 2 Feb 2016 02:54:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=yo3uuNwf; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id A5EC333A5E; Mon, 1 Feb 2016 15:54:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6akMi7r+ZjZO; Mon, 1 Feb 2016 15:54:46 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 9A16633A9D; Mon, 1 Feb 2016 15:54:15 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id E56AB1C0BE0 for ; Mon, 1 Feb 2016 15:54:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 90844956FD for ; Mon, 1 Feb 2016 15:54:04 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XkY6j6hlB0Ee for ; Mon, 1 Feb 2016 15:54:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by hemlock.osuosl.org (Postfix) with ESMTPS id B940B9572A for ; Mon, 1 Feb 2016 15:53:57 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id p63so9743651wmp.1 for ; Mon, 01 Feb 2016 07:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=APE0+rhR0JQ4Ki0qprhP3zneOuAFXk6lqH+oCGqTn4Q=; b=yo3uuNwfQFdZP/L6Y3ITYzB8fq6kfiu09fm49OmsyjUU6JaURmOUzazVhlhxNqnkBx zrF8Gr01R2+D2kcqcyNunhjjWh96GHllcr9nQ2JbdE9cARA0X3E9p4zv6vfAYKd581GU U0VGbNh4pKU2Ga6U7RXH2P4WcbE+7LxSxK9SddjijzBSh91yMkDzMAk+abDy1onvDKbU HwQc3ySrmiQxM25Ej7rT7tod7MRGG3m9HPZpPN3O7bRP0E4YoQw1anReXEc/+icc9hm7 GdBllg72LBjpSbWIC4qlg+8tVC460pnr/VIOw6M3ZKfgjvBter5uCiHKeO3jFWHfFzIt rAdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=APE0+rhR0JQ4Ki0qprhP3zneOuAFXk6lqH+oCGqTn4Q=; b=M4BJ4oTwwPmzz0SxKqpD/MbEGzl6GGTuURK/EN4UZnzSA4hIzLhNISJWHsfJlc+0hI 6QGLtB6OwJUpvQa7VrpdMOVs6vGmoNiEbP4aQAHvK36L/GHbD5RGtjXqNQchCst/qV/1 HNUxVGvl5IqcsHvBbcwa+Q3k5RVD7oSq9N0OPl73NmNcdb+AGU/rfCjElV1AyexyJJgl G36fuY4SarthD034Vo41smYYy4A9HmavKHfHlwf5d+d2j2sRZC2h/my4D/rocndh8NHm lu78/tngBlkH4reBL/80dy1dgNHHek5K3fGP5Kzwt6JoJ+td6iSMYf1Au/EeqBXamJtv jZjQ== X-Gm-Message-State: AG10YOR28005cDXGitRd3sHUjfWze7EByfJIqGKAQCCQCgKzJgtbJU/LOCAMg47YEaDO7w== X-Received: by 10.194.240.42 with SMTP id vx10mr23131126wjc.38.1454342036523; Mon, 01 Feb 2016 07:53:56 -0800 (PST) Received: from bobook.localdomain ([2620:0:1055:fd00:4a51:b7ff:fed2:2913]) by smtp.gmail.com with ESMTPSA id g3sm29762745wjw.31.2016.02.01.07.53.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Feb 2016 07:53:55 -0800 (PST) From: Samuel Martin To: buildroot@buildroot.org Date: Mon, 1 Feb 2016 16:53:36 +0100 Message-Id: <1454342021-22960-9-git-send-email-s.martin49@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454342021-22960-1-git-send-email-s.martin49@gmail.com> References: <1454342021-22960-1-git-send-email-s.martin49@gmail.com> Subject: [Buildroot] [PATCH v6 08/13] core: add HOST_SANITIZE_RPATH_HOOK to TARGET_FINALIZE_HOOKS X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch adds host-patchelf as a target-finalize dependency, and introduces the HOST_SANITIZE_RPATH_HOOK hook to fix the ELF files' RPATH from the HOST_DIR location (excluding the sysroot). After running this hook, the RPATH from any host ELF files is relative to the binary location itself. Notes: - we avoid to fix RPATH in the sysroot. - we do not try to fix RPATH in the external toolchain installation location as they may have been built in a way, this is already correct; furthermore, fixing RPATH in those programs may result in breaking them. - the whole host directory is processed because a number of host-package install programs that could be useful in places different from $(HOST_DIR)/{bin,sbin,usr/bin,usr/sbin}. - the shared libraries are also processed in case they have a 'main' function. As a step toward a fully relocatable SDK, this change allows to get the toolchain relocatable, but not yet the whole SDK. Signed-off-by: Samuel Martin --- changes v5->v6: - update for the new script version - add debug mode support changes v4->v5: - add verbose support changes v3->v4: - add host-patchelf to PACKAGES instead of target-finalize (Baruch) - add comment changes v2->v3: - move hook in Makefile (Baruch) --- Makefile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Makefile b/Makefile index 7c87177..b1f4fcf 100644 --- a/Makefile +++ b/Makefile @@ -616,6 +616,31 @@ endef TARGET_FINALIZE_HOOKS += PURGE_LOCALES endif +# RPATH fixing +# - The host hook sets RPATH in host ELF binaries, using relative paths to the +# library locations. +# - The target hook sanitizes RPATH in target ELF binaries, removing paths +# pointing to package's build directories or the sysroot's libdirs. +PACKAGES += host-patchelf + +ifeq ($(BR2_DEBUG_RPATH),) +BR2_DEBUG_RPATH = 0 +endif +ifeq ($(BR2_DEBUG_RPATH),0) +DEBUG_RPATH = 0 +else +DEBUG_RPATH = $(shell echo $$(($(BR2_DEBUG_RPATH)+1))) +endif + +define HOST_SANITIZE_RPATH_HOOK + DEBUG=$(DEBUG_RPATH) \ + PATCHELF=$(HOST_DIR)/usr/bin/patchelf \ + READELF=readelf \ + $(TOPDIR)/support/scripts/fix-rpath host $(HOST_DIR) +endef + +TARGET_FINALIZE_HOOKS += HOST_SANITIZE_RPATH_HOOK + $(TARGETS_ROOTFS): target-finalize target-finalize: $(PACKAGES)