From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id GFBWGZH3TmczTAEA62LTzQ:P1 (envelope-from ) for ; Tue, 03 Dec 2024 12:20:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id GFBWGZH3TmczTAEA62LTzQ (envelope-from ) for ; Tue, 03 Dec 2024 13:20:33 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=kzhad4Uy; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1733228433; a=rsa-sha256; cv=none; b=Z1iAONV9mBxG+856EGCRdYMc2XY9CfrF+nnzThXj5/2SEk0mSykhJWASwJFk3I8NohiUwR k1nrcsGEWcYvu7iM6fv1KW2JcC9j+OlCvGsexSY0fV8O1T667Eiok5kquCL8+7ZQFx4U43 M4mxv0idqOIpf2tE9TZEfmlUqJU6iU/PaWT8b0fya+x8LEp0beLW8q029tL7D4i3gcjGTw gFKLQLcQTMgL/xddRqgUjA1J9cEg9BNq2/Q9v9GJAlEOruGOm74vWBSfOSyilIlOWUxD27 GkNMnanQDwPgVRGtCCqldN4ZCoWdKBHUPVmEXAgbRfFURSwWlkM9yWnS7+0IQg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=kzhad4Uy; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1733228433; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=lIScpAyaaHSxCE5dErc1Vqdl4aITWiudORM/46QaxSc=; b=NPOrCbtcgVeoJt9l8owUil7lfPHAGYqWHwtzMLFtEaHUwyFAW8WBmG7Nwt7YBcZZPkHFEa CglC5DmhCJZZ2OnhQjJ9UUSGNnZOxuSVXpXrTsVmqnteTyohzCzpE1GPOhsDiMNSK1bB9B F++gnPRr07jgX/xe+zxJWod6C0MnBEHBpeI6F3fzzDpkBTSrcc12YryS4fNWVh9OJ50VI3 7fQo1wdX0GQRA+lNe3nagFM6cusnMWg2ffkOMJyGIJlVivu8gcc0yDrxa6FJWMdgl3DUCh 4EmxNDeThwUxFC0dzgHlYBXy3GbYGB8TppOP7izwzQXSvAXm3UYlympSsZZQCA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1E6191DBAB for ; Tue, 03 Dec 2024 13:20:32 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIRss-0002kT-H6; Tue, 03 Dec 2024 07:20:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIRsp-0002kI-QH for guix-patches@gnu.org; Tue, 03 Dec 2024 07:20:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIRsp-0006rd-E8 for guix-patches@gnu.org; Tue, 03 Dec 2024 07:20:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=lIScpAyaaHSxCE5dErc1Vqdl4aITWiudORM/46QaxSc=; b=kzhad4UyA7/oodcHqYmPYCzvqeQdKdZjhsIzMlUmTYnAcpE5a+3GGd+tBXVyjXiprju9UY/bBZU5BqwYbzMvOPHYCkdQv9fG98crgN2cwh4kyevBSCx5SX7uPlKbS4a5NuO7pEDdRXL2kKtZfuJy44ZwVW9yMpWJTG+7Dy7nm+5T0JD14fY1sUP8s2KelupK8Cx/xVDhSsxEP7B0wi2e0JWyHWtOiqywcczIHIx1smEAaHN+m2/SmySXrn6QCBQ+iAOwZiZxicCSVK50JCsgqYz0LgY96GYnSTVj1BCkv0XSVlxqfjkSQwZOJMs652hYhgzXdSG8RPavxlHbLX22Ng==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tIRso-0002zJ-Fb for guix-patches@gnu.org; Tue, 03 Dec 2024 07:20:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74669] [PATCH] gnu: elfutils: Fix cross-compilation. Resent-From: Zheng Junjie Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 03 Dec 2024 12:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74669 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74669@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.173322836311411 (code B ref -1); Tue, 03 Dec 2024 12:20:02 +0000 Received: (at submit) by debbugs.gnu.org; 3 Dec 2024 12:19:23 +0000 Received: from localhost ([127.0.0.1]:58516 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tIRsB-0002xz-09 for submit@debbugs.gnu.org; Tue, 03 Dec 2024 07:19:23 -0500 Received: from lists.gnu.org ([209.51.188.17]:36048) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tIRs6-0002xo-R2 for submit@debbugs.gnu.org; Tue, 03 Dec 2024 07:19:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIRs6-0002hG-K3 for guix-patches@gnu.org; Tue, 03 Dec 2024 07:19:18 -0500 Received: from smtp81.cstnet.cn ([159.226.251.81] helo=cstnet.cn) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1tIRs2-0006n2-4A for guix-patches@gnu.org; Tue, 03 Dec 2024 07:19:18 -0500 Received: from m.tailaa68d.ts.net (unknown [107.174.64.25]) by APP-03 (Coremail) with SMTP id rQCowAAXuO0t905newhyBw--.18010S2; Tue, 03 Dec 2024 20:18:58 +0800 (CST) From: Zheng Junjie Date: Tue, 3 Dec 2024 20:18:51 +0800 Message-ID: <814be590b438138df7b35507a0fd266b319da388.1733228331.git.zhengjunjie@iscas.ac.cn> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAAXuO0t905newhyBw--.18010S2 X-Coremail-Antispam: 1UD129KBjvJXoW3XFyUJryxCF4DCr4rtF4Utwb_yoW3Cw15pa yayFs5JayrJrn7Zrs3JF10kw1rZ397XFy5Z34fG3W0vF4Ygwn5GrWrtryYkFW7Crs7C343 Zws5tFykXas8A3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUy2b7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1j6r15MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j 6r4UYxBIdaVFxhVjvjDU0xZFpf9x07bOoGdUUUUU= X-Originating-IP: [107.174.64.25] X-CM-SenderInfo: x2kh0wxmxqyx3h6l2u1dvotugofq/ Received-SPF: pass client-ip=159.226.251.81; envelope-from=zhengjunjie@iscas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.82 X-Spam-Score: -1.82 X-Migadu-Queue-Id: 1E6191DBAB X-Migadu-Scanner: mx12.migadu.com X-TUID: YdvFq1H+hQNb * gnu/packages/elf.scm (elfutils): Fix cross-compilation [arguments]: When cross-compilation, apply patch. [native-inputs]: When cross-compilation, Add patch. * gnu/packages/patches/elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch: new file. * gnu/local.mk (dist_patch_DATA): Register it. Change-Id: Ia1ab9c09124a140608bda34bf62f0ae80eb44f9b --- gnu/local.mk | 1 + gnu/packages/elf.scm | 21 +++- ...reading-of-ar_size-in-elf_begin_rand.patch | 116 ++++++++++++++++++ 3 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 gnu/packages/patches/elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch diff --git a/gnu/local.mk b/gnu/local.mk index a7bd32453b0..eee768615ea 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1177,6 +1177,7 @@ dist_patch_DATA = \ %D%/packages/patches/eigen-fix-strict-aliasing-bug.patch \ %D%/packages/patches/einstein-build.patch \ %D%/packages/patches/elfutils-tests-ptrace.patch \ + %D%/packages/patches/elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch \ %D%/packages/patches/elixir-path-length.patch \ %D%/packages/patches/elm-ghc9.2.patch \ %D%/packages/patches/elm-offline-package-registry.patch \ diff --git a/gnu/packages/elf.scm b/gnu/packages/elf.scm index 81a753a4835..4fae3929ba2 100644 --- a/gnu/packages/elf.scm +++ b/gnu/packages/elf.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2021 Leo Le Bouter ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2023, 2024 Janneke Nieuwenhuizen +;;; Copyright © 2024 Zheng Junjie <873216071@qq.com> ;;; ;;; This file is part of GNU Guix. ;;; @@ -140,9 +141,25 @@ (define-public elfutils "tests/run-varlocs.sh") (("^#!.*" all) (string-append all "exit 77;\n")))))) - '())))) + '()) + ,@(if + (%current-target-system) + '((add-after 'unpack 'patch + (lambda* (#:key native-inputs #:allow-other-keys) + (invoke "patch" "-Np1" "-i" + (assoc-ref native-inputs + "elfutils-libdwfl-Rewrite-reading-of-ar\ +_size-in-elf_begin_rand.patch"))))) + '())))) - (native-inputs (list m4)) + (native-inputs + (if + (%current-target-system) + `(("m4" ,m4) + ("elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch" + ,(search-patch + "elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch"))) + (list m4))) (inputs (list xz zlib)) (home-page "https://sourceware.org/elfutils/") (synopsis "Collection of utilities and libraries to handle ELF files and diff --git a/gnu/packages/patches/elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch b/gnu/packages/patches/elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch new file mode 100644 index 00000000000..e9d51359c4b --- /dev/null +++ b/gnu/packages/patches/elfutils-libdwfl-Rewrite-reading-of-ar_size-in-elf_begin_rand.patch @@ -0,0 +1,116 @@ +from https://sourceware.org/cgit/elfutils/patch/?id=0873ae782d14e672e8344775e76b7fca0a8b41bf + +Adjust the changelog so it can be applied on elfutils 0.187. + +From 0873ae782d14e672e8344775e76b7fca0a8b41bf Mon Sep 17 00:00:00 2001 +From: Mark Wielaard +Date: Thu, 28 Jul 2022 15:31:12 +0200 +Subject: libdwfl: Rewrite reading of ar_size in elf_begin_rand +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +With GCC 12.1.1, glibc 2.35, -fsanitize=undefined and +-D_FORTIFY_SOURCE=3 we get the following error message: + +In file included from /usr/include/ar.h:22, + from ../libelf/libelfP.h:33, + from core-file.c:31: +In function ‘pread’, + inlined from ‘pread_retry’ at ../lib/system.h:188:21, + inlined from ‘elf_begin_rand’ at core-file.c:86:16, + inlined from ‘core_file_read_eagerly’ at core-file.c:205:15: +/usr/include/bits/unistd.h:74:10: error: ‘__pread_alias’ writing 58 or more bytes into a region of size 10 overflows the destination [-Werror=stringop-overflow=] + 74 | return __glibc_fortify (pread, __nbytes, sizeof (char), + | ^~~~~~~~~~~~~~~ +/usr/include/ar.h: In function ‘core_file_read_eagerly’: +/usr/include/ar.h:41:10: note: destination object ‘ar_size’ of size 10 + 41 | char ar_size[10]; /* File size, in ASCII decimal. */ + | ^~~~~~~ +/usr/include/bits/unistd.h:50:16: note: in a call to function ‘__pread_alias’ declared with attribute ‘access (write_only, 2, 3)’ + 50 | extern ssize_t __REDIRECT (__pread_alias, + | ^~~~~~~~~~ +cc1: all warnings being treated as errors + +The warning disappears when dropping either -fsanitize=undefined +or when using -D_FORTIFY_SOURCE=2. It looks like a false positive. +But I haven't figured out how/why it happens. + +The code is a little tricky to proof correct though. The ar_size +field is a not-zero terminated string ASCII decimal, right-padded +with spaces. Which is then converted with strtoll. Relying on the +fact that the struct ar_hdr is zero initialized, so there will be +a zero byte after the ar_size field. + +Rewrite the code to just use a zero byte terminated char array. +Which is much easier to reason about. As a bonus the error disappears. + +Signed-off-by: Mark Wielaard +--- + libdwfl/ChangeLog | 5 +++++ + libdwfl/core-file.c | 26 ++++++++++++++++---------- + 2 files changed, 21 insertions(+), 10 deletions(-) + +diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog +index 75c53948d..acdaa0138 100644 +--- a/libdwfl/ChangeLog ++++ b/libdwfl/ChangeLog +@@ -1,0 +1,5 @@ ++2022-07-28 Mark Wielaard ++ ++ * core-file.c (elf_begin_rand): Replace struct ar_hdr h with ++ a char ar_size[AR_SIZE_CHARS + 1] array to read size. ++ +2022-04-22 Mark Wielaard + + * debuginfod-client.c (init_control): New static pthread_once_t. +diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c +index cefc3db0f..4418ef338 100644 +--- a/libdwfl/core-file.c ++++ b/libdwfl/core-file.c +@@ -75,26 +75,32 @@ elf_begin_rand (Elf *parent, off_t offset, off_t size, off_t *next) + from the archive header to override SIZE. */ + if (parent->kind == ELF_K_AR) + { +- struct ar_hdr h = { .ar_size = "" }; +- +- if (unlikely (parent->maximum_size - offset < sizeof h)) ++ /* File size, in ASCII decimal, right-padded with ASCII spaces. ++ Max 10 characters. Not zero terminated. So make this ar_size ++ array one larger and explicitly zero terminate it. As needed ++ for strtoll. */ ++ #define AR_SIZE_CHARS 10 ++ char ar_size[AR_SIZE_CHARS + 1]; ++ ar_size[AR_SIZE_CHARS] = '\0'; ++ ++ if (unlikely (parent->maximum_size - offset < sizeof (struct ar_hdr))) + return fail (ELF_E_RANGE); + + if (parent->map_address != NULL) +- memcpy (h.ar_size, parent->map_address + parent->start_offset + offset, +- sizeof h.ar_size); ++ memcpy (ar_size, parent->map_address + parent->start_offset + offset, ++ AR_SIZE_CHARS); + else if (unlikely (pread_retry (parent->fildes, +- h.ar_size, sizeof (h.ar_size), ++ ar_size, AR_SIZE_CHARS, + parent->start_offset + offset + + offsetof (struct ar_hdr, ar_size)) +- != sizeof (h.ar_size))) ++ != AR_SIZE_CHARS)) + return fail (ELF_E_READ_ERROR); + +- offset += sizeof h; ++ offset += sizeof (struct ar_hdr); + + char *endp; +- size = strtoll (h.ar_size, &endp, 10); +- if (unlikely (endp == h.ar_size) ++ size = strtoll (ar_size, &endp, 10); ++ if (unlikely (endp == ar_size) + || unlikely ((off_t) parent->maximum_size - offset < size)) + return fail (ELF_E_INVALID_ARCHIVE); + } +-- +cgit + base-commit: 58a134224e327cfc0af105314598d080dfc0392d -- 2.46.0