From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id D41AD3858D33 for ; Thu, 2 Mar 2023 12:01:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D41AD3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1032.google.com with SMTP id m3-20020a17090ade0300b00229eec90a7fso3467395pjv.0 for ; Thu, 02 Mar 2023 04:01:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677758488; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=lQBb0YWFcrH+EsqHqW1U6aDoTeZLRjawfwMhNbjzR1g=; b=bsD6+X8FKLTFcA/Y8G2qYqZ6xc6GESXdmQ8GOHAek0Xezuzu0v2oK7mfXku0Rj/dWx IEY3zDN0kqUquqdTEWDgoic2nWaijFKQ4Cfj1Ykz8QulxD10NpDZYi/DUOL2f9vhoUgv vYF9LR+Wq5VTp74DDOEJd9bfE2o0mB3LcT3Zrv1zEcVdyFhIUKrJnmAsVcVKU/D5qXHV ItythOfM+C03PQZw5ijRjrNi5duMBxQdVO7vrWHCQ2qdBCgiCbJKVCYJJwamLxC0fnep zFNyWYCCa5Kvzm8MwWjVRjR8LLHM1KDg5YD1TJ43574bsHO0opUeGH7IikkBldzj42Wa O0yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677758488; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lQBb0YWFcrH+EsqHqW1U6aDoTeZLRjawfwMhNbjzR1g=; b=bc6atZykX2Wb2BJsUk1XdMOrUwMgVOLJbKieAnIhqDosAJeJGpbu5ThDri3MfYMwXF 3FvWbAezb0sDDzrn5YuWd6QTWZUEZQefavM/xGMIMNTEM8rfddUzTSbFbdgUIktISUCz NqmQLjhzR+8TBYeHyCOji3lzJR+iyHjHwN4KPtvTiQFUKuq8+Ovgq1l1n65U46imF15+ XAJGDa//eaSr8W8+4H5UGWTvT2h/NhMoPJyxjj62rKmZ7p6ZdgZWdy5zDOenxmDe48zz /HLI5i2aPy7qNximre3kKAGvWlqIRgB2xKA7yzwy40ox//GHllYurOrRoJpdB5LJOa5S UeBw== X-Gm-Message-State: AO0yUKWMExrhcuP2hlbn/XHBwqhYkKLlIW1Vc06ATqa99rVJwLTrNOQr k8iX2Ooc5KO/MmH+pe2rReIai3yDb7I= X-Google-Smtp-Source: AK7set+VpGJPxVulVvExRFDbLYgobd+NktHNnpiw5ZzSBiPudP3hvywVE9YuBKVWrZaHErMuluIcTQ== X-Received: by 2002:a17:902:ea0e:b0:19a:9580:74c with SMTP id s14-20020a170902ea0e00b0019a9580074cmr11392183plg.7.1677758488615; Thu, 02 Mar 2023 04:01:28 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id j24-20020a170902759800b0019a60b7cc0esm10155163pll.248.2023.03.02.04.01.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 04:01:28 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id BB0761142C90; Thu, 2 Mar 2023 22:31:25 +1030 (ACDT) Date: Thu, 2 Mar 2023 22:31:25 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Don't write zeros to a gap in the output file Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: Writing out zeros is counterproductive if a file system supports sparse files. A very large gap need not take much actual disk space, but it usually will if zeros are written. memory_bseek also supports not writing out zeros in a gap. * elf.c (write_zeros): Delete. (assign_file_positions_for_load_sections): Don't call write_zeros. Comment. diff --git a/bfd/elf.c b/bfd/elf.c index 37f331b98cd..409be7068ec 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5402,22 +5402,6 @@ print_segment_map (const struct elf_segment_map *m) fflush (stderr); } -static bool -write_zeros (bfd *abfd, file_ptr pos, bfd_size_type len) -{ - void *buf; - bool ret; - - if (bfd_seek (abfd, pos, SEEK_SET) != 0) - return false; - buf = bfd_zmalloc (len); - if (buf == NULL) - return false; - ret = bfd_bwrite (buf, len, abfd) == len; - free (buf); - return ret; -} - /* Assign file positions to the sections based on the mapping from sections to segments. This function also sets up some fields in the file header. */ @@ -5866,11 +5850,13 @@ assign_file_positions_for_load_sections (bfd *abfd, if (p->p_filesz + adjust < p->p_memsz) { /* We have a PROGBITS section following NOBITS ones. - Allocate file space for the NOBITS section(s) and - zero it. */ + Allocate file space for the NOBITS section(s). + We don't need to write out the zeros, posix + fseek past the end of data already written + followed by a write at that location is + guaranteed to result in zeros being read + from the gap. */ adjust = p->p_memsz - p->p_filesz; - if (!write_zeros (abfd, off, adjust)) - return false; } } /* We only adjust sh_offset in SHT_NOBITS sections -- Alan Modra Australia Development Lab, IBM