From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CAF20C433F5 for ; Thu, 2 Dec 2021 19:16:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2A60382F43; Thu, 2 Dec 2021 20:16:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=lobanov.in Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 25148837C5; Thu, 2 Dec 2021 20:16:51 +0100 (CET) Received: from forward103p.mail.yandex.net (forward103p.mail.yandex.net [77.88.28.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 56D2B837C9 for ; Thu, 2 Dec 2021 20:16:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=lobanov.in Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sergey@lobanov.in Received: from myt5-d8fb82618a34.qloud-c.yandex.net (myt5-d8fb82618a34.qloud-c.yandex.net [IPv6:2a02:6b8:c12:59a3:0:640:d8fb:8261]) by forward103p.mail.yandex.net (Yandex) with ESMTP id 8CDF15A1933 for ; Thu, 2 Dec 2021 22:16:44 +0300 (MSK) Received: from myt5-aad1beefab42.qloud-c.yandex.net (myt5-aad1beefab42.qloud-c.yandex.net [2a02:6b8:c12:128:0:640:aad1:beef]) by myt5-d8fb82618a34.qloud-c.yandex.net (mxback/Yandex) with ESMTP id sDxnxiyQCS-GieafgiE; Thu, 02 Dec 2021 22:16:44 +0300 Authentication-Results: myt5-d8fb82618a34.qloud-c.yandex.net; dkim=pass Received: by myt5-aad1beefab42.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id UjXhaEPMm9-GhPW4db6; Thu, 02 Dec 2021 22:16:44 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Fwd: 2 From: "Sergey V. Lobanov" To: u-boot@lists.denx.de Cc: "Sergey V. Lobanov" Subject: [PATCH] mkimage: fix segfault on MacOS arm64 Date: Thu, 2 Dec 2021 22:16:31 +0300 Message-Id: <20211202191631.98009-1-sergey@lobanov.in> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean mkimage segfaults due ASLR mechasim on MacOS arm64 It is required to use _dyld_get_image_vmaddr_slide() to prevent segfault on MacOS arm64 This patch ased on the discussion https://github.com/u-boot/u-boot/commit/3b142045e8a7f0ab17b6099e9226296af45967d0 Thanks to Ronny Kotzschmar and ptpt52 github user Signed-off-by: Sergey V. Lobanov --- tools/imagetool.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/imagetool.h b/tools/imagetool.h index e229a34ffc..13775ff9b3 100644 --- a/tools/imagetool.h +++ b/tools/imagetool.h @@ -271,11 +271,16 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams); * b) we need a API call to get the respective section symbols */ #if defined(__MACH__) #include +#include -#define INIT_SECTION(name) do { \ +#define INIT_SECTION(name) struct image_type_params \ + **__cat(__start_, name), **__cat(__stop_, name); \ + do { \ unsigned long name ## _len; \ char *__cat(pstart_, name) = getsectdata("__DATA", \ #name, &__cat(name, _len)); \ + __cat(pstart_, name) += \ + _dyld_get_image_vmaddr_slide(0); \ char *__cat(pstop_, name) = __cat(pstart_, name) + \ __cat(name, _len); \ __cat(__start_, name) = (void *)__cat(pstart_, name); \ @@ -283,7 +288,6 @@ int rockchip_copy_image(int fd, struct image_tool_params *mparams); } while (0) #define SECTION(name) __attribute__((section("__DATA, " #name))) -struct image_type_params **__start_image_type, **__stop_image_type; #else #define INIT_SECTION(name) /* no-op for ELF */ #define SECTION(name) __attribute__((section(#name))) -- 2.30.1 (Apple Git-130)