From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 13C6C3858C5F for ; Mon, 18 Mar 2024 22:37:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13C6C3858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13C6C3858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.83.234.184 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710801476; cv=none; b=nL46Z6UwE7LLVHM7amdiDU0iKjtrVMmqCZVEqO2p9/33rIu8MCNxMe4GKlr10BXTPJaUMap07GzncdJ08jTguO/ss7yKSWCtKlSBHp4fvrc8bwRLBNv+H9MKxdqc+dlVoH4+CVYoGOjb04sHrFOhmZeAPw4P2DlXOU7SSsdyugI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710801476; c=relaxed/simple; bh=xMY/hlRt05Jfjux7CnKE78I/Xbr3GoeGqpkoL7AnJ1U=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=S3FPgN97UzmcsDXBT92sHdpmXEtSPffGVlQ828SJuNeDmee8XaN12uxKVIzrA54RrMSSZC+f1RRIkYs7uhoW1ZzCwRMQW8RO6A3Whh5OTZkFxDy95IRFGSzZMfUTbsvKU2mpGCmA2pFM8YeeAScQnu1tB5SLICHNql/CdYStAj4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from csb.redhat.com (deer0x03.wildebeest.org [172.31.17.133]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 95B6C3000472; Mon, 18 Mar 2024 23:37:53 +0100 (CET) Received: by csb.redhat.com (Postfix, from userid 10916) id 73009D0A8A; Mon, 18 Mar 2024 23:37:53 +0100 (CET) From: Mark Wielaard To: debugedit@sourceware.org Cc: Mark Wielaard Subject: [PATCH] debugedit: Only write the ELF file when updating strings or build-id Date: Mon, 18 Mar 2024 23:37:47 +0100 Message-Id: <20240318223747.119737-1-mark@klomp.org> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Only open the ELF file read/write and write out the data if we are changing a dest_dir or updating the build-id. * tools/debugedit.c (fdopen_dso): Call elf_begin with ELF_C_READ when not changing dest_dir or build_id, otherwise use ELF_C_RDWR. (main): Call open with O_RDONLY when not changing dest_dir or build_id, otherwise use O_RDWR. Call elf_update with ELF_C_WRITE when changing dest_dir or build_id. https://sourceware.org/bugzilla/show_bug.cgi?id=31504 Signed-off-by: Mark Wielaard --- tools/debugedit.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/debugedit.c b/tools/debugedit.c index 7802f9fe03fc..5886d0d8e50f 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -3261,7 +3261,10 @@ fdopen_dso (int fd, const char *name) DSO *dso = NULL; size_t phnum; - elf = elf_begin (fd, ELF_C_RDWR, NULL); + if (dest_dir == NULL && (!do_build_id || no_recompute_build_id)) + elf = elf_begin (fd, ELF_C_READ, NULL); + else + elf = elf_begin (fd, ELF_C_RDWR, NULL); if (elf == NULL) { error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1)); @@ -3600,7 +3603,10 @@ main (int argc, char *argv[]) if (chmod (file, stat_buf.st_mode | S_IRUSR | S_IWUSR) != 0) error (0, errno, "Failed to chmod input file '%s' to make sure we can read and write", file); - fd = open (file, O_RDWR); + if (dest_dir == NULL && (!do_build_id || no_recompute_build_id)) + fd = open (file, O_RDONLY); + else + fd = open (file, O_RDWR); if (fd < 0) { error (1, errno, "Failed to open input file '%s'", file); @@ -3805,7 +3811,8 @@ main (int argc, char *argv[]) if (do_build_id && build_id != NULL) handle_build_id (dso, build_id, build_id_offset, build_id_size); - if (elf_update (dso->elf, ELF_C_WRITE) < 0) + if ((dest_dir != NULL || (build_id && !no_recompute_build_id)) + && elf_update (dso->elf, ELF_C_WRITE) < 0) { error (1, 0, "Failed to write file: %s", elf_errmsg (elf_errno())); } -- 2.39.3