From patchwork Fri Feb 21 23:57:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Naour X-Patchwork-Id: 1242367 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=smile.fr Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=smile-fr.20150623.gappssmtp.com header.i=@smile-fr.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=VgkUkZaL; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48PT0m62ngz9sR4 for ; Sat, 22 Feb 2020 10:57:44 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 79AD1221DC; Fri, 21 Feb 2020 23:57:40 +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 MTRdn0HXOMBH; Fri, 21 Feb 2020 23:57:37 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id DEA6820499; Fri, 21 Feb 2020 23:57:36 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 01A661BF681 for ; Fri, 21 Feb 2020 23:57:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id F115A875EB for ; Fri, 21 Feb 2020 23:57:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VHhVa8fl-3fG for ; Fri, 21 Feb 2020 23:57:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by whitealder.osuosl.org (Postfix) with ESMTPS id 5D086871E0 for ; Fri, 21 Feb 2020 23:57:34 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id p17so3639124wma.1 for ; Fri, 21 Feb 2020 15:57:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smile-fr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=If6vwUIWJMFM+uCYNrKJCr3hcH5k+KvmgP+u4523YVs=; b=VgkUkZaLAPlTM1j5No67tJFXND7XQtL1P4hh3mdCQCKn9TnnMkqE9Zk7uDDIlWz6ao 53SZ2JSzI25bH+iPIxBbgHnt4qQ8fB1U2iwcB2ryq4rP5AxHm0NrcYfE7sPhgA80MIBc 3VfIgKJqc88ngCKaFvr+gOjF1kJFA5EZoPYPILCvwEmEIHNEYJP0mEV46cl4UB64a1Pv 6FMcdwsB5BNDy+Vt3ylrX56kGL22TxBeEmnOk7cTtr2NZndtbfqLyEa9JnZti1WU4sNN fbIutFV4whqgGAlkv93YhME7qR1XNZLn3y/L/Ac3RuJpX/glHTjbBzprflRFrVdH91c3 F+OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=If6vwUIWJMFM+uCYNrKJCr3hcH5k+KvmgP+u4523YVs=; b=uRfAjlJvMQaCUeyz6AaHreL0Vf4VHSmK0bdqCLUBQeuC2s4JnIPULoQiIeB064/DR0 tH4WOg+ToneBEss8ZPlE/ZaJer4Zw/EmE8LozCokIz/IPib5n4+8oBWz6BcU+tEePcAJ 7c3MPlyMiQI9a1g8uCsmZPaVv4zDPvO/JmRQW10B7bbdHgMXV4aGIKHbK3Bz14o22DsV OmrURUscOxEROoQNkwTwI/80cke+9Ahrf5eVBqm+oPqkCbyqt86zph753b7MEnf+xqwN kjRnbq9zvEAde5vycYZCjh1IwQA9qMUcDy6/Z0kDeYsK7IybTHunhmQQLlewUQKI1Bt9 XApw== X-Gm-Message-State: APjAAAVkRv8p/bV4AI8jQ2tB2jsbI+a7ODyL884wlcVO3Dg/m7IyvKdy c6Wnn+hRcCqzp6LZcYoVijx5ZbN40IPmNg== X-Google-Smtp-Source: APXvYqwHUoL13DEyMAz6ZC1VSX4QqEXVJ/ioMOSW1mRBjlJZmXt1dT3umv9EMC3WwyAHRuGHUtSyTQ== X-Received: by 2002:a1c:3906:: with SMTP id g6mr6535297wma.49.1582329452152; Fri, 21 Feb 2020 15:57:32 -0800 (PST) Received: from localhost.localdomain (2a01cb0589880c0046708304bf1f24fd.ipv6.abo.wanadoo.fr. [2a01:cb05:8988:c00:4670:8304:bf1f:24fd]) by smtp.gmail.com with ESMTPSA id 2sm5560883wrq.31.2020.02.21.15.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 15:57:31 -0800 (PST) From: Romain Naour To: buildroot@buildroot.org Date: Sat, 22 Feb 2020 00:57:28 +0100 Message-Id: <20200221235728.592613-1-romain.naour@smile.fr> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH] package/elf2flt: fix relocations for readonly .eh_frame section X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Naour , Thomas Petazzoni Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" The patch added to fix a efl2flt segfault on ARM Cortex-m4 introduced some regressions on m68k and ARM [2]. While debuging, we can notice the flags value (0x12f) for .eh_frame just before the crash. RELOCS: .eh_frame [0x2185c20]: flags=0x12f vma=0x84384 /* bug case: flags = 0x12f (m68k) * SEC_HAS_CONTENTS 0x100 * SEC_DATA 0x020 * SEC_READONLY 0x008 * SEC_RELOC 0x004 * SEC_LOAD 0x002 * SEC_ALLOC 0x001 */ On ARM cortex-m4, we have the same flags: RELOCS: .ARM.exidx [0x9ac5b0]: flags=0x12f vma=0x4b4ec So due to the new condition introduced by [1] the .eh_frame section located in a readonly data section will be moved to the "text" section. Looking at the gcc code for m68k [3]: "Because .eh_frame refers to both code and data, it follows that .eh_frame must be in the data segment itself. [...] In theory, we could create a read-only .eh_frame [...]. However, gcc currently handles indirect references using a per-TU constant pool. This means that if a function and its eh_frame are removed by the linker, the eh_frame's indirect references to the removed function will not be removed, leading to an unresolved symbol error." Fix this crash by checking the section name and move .eh_frame section even if it is located in readonly data. Upstream status: under review [4] Build tested on m68k and ARM w/ host-binutils 2.33.1. [1] 2b064f86b6a0fd683f307b51f12d9d919fcaa386 [2] http://lists.busybox.net/pipermail/buildroot/2020-February/274593.html [3] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/m68k/m68k.h;h=fc65e524b139a6d43e528956a788b9110aebaf2e;hb=a0c06cc27d2146b7d86758ffa236516c6143d62c#l785 [4] https://github.com/uclinux-dev/elf2flt/issues/12 Signed-off-by: Romain Naour Cc: Thomas Petazzoni --- ...cations-for-read-only-.eh_frame-sect.patch | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 package/elf2flt/0003-elf2flt-fix-relocations-for-read-only-.eh_frame-sect.patch diff --git a/package/elf2flt/0003-elf2flt-fix-relocations-for-read-only-.eh_frame-sect.patch b/package/elf2flt/0003-elf2flt-fix-relocations-for-read-only-.eh_frame-sect.patch new file mode 100644 index 0000000000..7b7daccdbb --- /dev/null +++ b/package/elf2flt/0003-elf2flt-fix-relocations-for-read-only-.eh_frame-sect.patch @@ -0,0 +1,81 @@ +From 9cab9b546359eba9ac4391f64626714f0534da0b Mon Sep 17 00:00:00 2001 +From: Romain Naour +Date: Fri, 21 Feb 2020 23:31:55 +0100 +Subject: [PATCH] elf2flt: fix relocations for read-only .eh_frame section + +The commit [1] moved readonly data sections to "text" section. +This was needed to fix a elf2flt segfault on ARM architectures with +Binutils >= 2.33.1. + +After this patch was applied to Buildroot's elf2flt package, +new segfault appear while building several packages +(acpica, augeas, binutils, cairo, fontconfig, gptfdisk, libopenssl, +mimic...) [2]. + +We can reproduce the issue manually from the binutils build directory: + +'output/host/m68k-buildroot-uclinux-uclibc/bin/elf2flt' '-a' '-o' 'readelf' '-r' 'readelf.gdb' + +While debuging, we can notice the flags value (0x12f) for .eh_frame +just before the crash. + +RELOCS: .eh_frame [0x2185c20]: flags=0x12f vma=0x84384 + + /* bug case: flags = 0x12f (m68k) + * SEC_HAS_CONTENTS 0x100 + * SEC_DATA 0x020 + * SEC_READONLY 0x008 + * SEC_RELOC 0x004 + * SEC_LOAD 0x002 + * SEC_ALLOC 0x001 + */ + +On ARM cortex-m4, we have the same flags: +RELOCS: .ARM.exidx [0x9ac5b0]: flags=0x12f vma=0x4b4ec + +So due to the new condition introduced by [1] the .eh_frame +section located in a readonly data section will be moved to +the "text" section. + +Looking at the gcc code for m68k [3]: + +"Because .eh_frame refers to both code and data, it follows that +.eh_frame must be in the data segment itself. +[...] +In theory, we could create a read-only .eh_frame [...]. However, +gcc currently handles indirect references using a per-TU constant +pool. This means that if a function and its eh_frame are removed +by the linker, the eh_frame's indirect references to the removed +function will not be removed, leading to an unresolved symbol +error." + +Fix this crash by checking the section name and move +.eh_frame section even if it is located in readonly data. + +[1] 73325b7f209e0f68887333385184af275531427d +[2] http://lists.busybox.net/pipermail/buildroot/2020-February/274593.html +[3] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/m68k/m68k.h;h=fc65e524b139a6d43e528956a788b9110aebaf2e;hb=a0c06cc27d2146b7d86758ffa236516c6143d62c#l785 +[4] https://github.com/uclinux-dev/elf2flt/issues/12 + +Signed-off-by: Romain Naour +--- + elf2flt.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/elf2flt.c b/elf2flt.c +index 656e19b..30778a9 100644 +--- a/elf2flt.c ++++ b/elf2flt.c +@@ -283,7 +283,8 @@ output_relocs ( + */ + if ((!pic_with_got || ALWAYS_RELOC_TEXT) && + ((a->flags & SEC_CODE) || +- ((a->flags & (SEC_DATA | SEC_READONLY)) == (SEC_DATA | SEC_READONLY)))) ++ ((a->flags & (SEC_DATA | SEC_READONLY)) == (SEC_DATA | SEC_READONLY) && ++ (strcmp(".eh_frame", a->name) != 0)))) + sectionp = text + (a->vma - text_vma); + else if (a->flags & SEC_DATA) + sectionp = data + (a->vma - data_vma); +-- +2.24.1 +