From patchwork Mon Nov 14 15:03:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Werling X-Patchwork-Id: 19850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2193078wru; Mon, 14 Nov 2022 07:04:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6DB7eBg2nUEaHg+fnNmcObiqAyeBdRmqaZ/5haybi/hmaLzHSFv5hT4/bBBSenlQP1RyDN X-Received: by 2002:a17:906:1446:b0:7ae:47ef:93f with SMTP id q6-20020a170906144600b007ae47ef093fmr10419998ejc.116.1668438258278; Mon, 14 Nov 2022 07:04:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668438258; cv=none; d=google.com; s=arc-20160816; b=lgv1x3R0rK4vAxVXu/Y5pA/82WR2dDAUtcg7/5iuTlPcSfE5Z9q1CIFZjvLftjPgp5 s8eIf/tvVbbNcKdPo0i7zo4IA2fYRgQIMAhzNJkUybCDE/kxnHp02xfEn8nevqVjXuK7 9GPxrYBieCp6wTwxeAEH4uPfsT0TYAgqRsWv91gKpRIKnoBv6NTBvb566sJ0hcsHgUbw wdZDBuxeyK/2vKuDZQitPrfw6V1rXckJNyOMEI3ixEULIcCweHPweOOZyg9YVLnIs3IE JAQrTFrHb00sj5xQ6fTGJe2LD+kYAGIJnxI/BmEM7uQwORf1DXqeRQkYIb3jKNuaGkkr JR/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=egeAu/pVx29C+hHq9ZCOwQp+fCIp09lLuqC4LXHkokg=; b=oDG4KrJU/uvUnUkLqY1Rlh1l1aeiChpcB0dGyQlhxI1qjV6/qKHYHFkHB3yZzdaFQH am+QOsLqZ0TBvqaONemNmSg2k/u5hKIOcfl3E71rky1zmSSa0yuJ/tWKlSEd92OEmBRc upqtmZdFJNL16oXDlvSM5WfavX6g0pzO5GbuV7EBZmKP7HhX2l1IxKbOX3pc40SDWkuI HwbqlQN/24j9S3YXfJGn/sVSr3gTxkPvjfyWgXmnBoqJyxxwMrCUVWQ7z6sikRvVpJOk xJabkp8KrHU+Om7Mh2BqYNIKz6CmPlmEos8X7NucBYJGXeMM99uNthEIHzTSfI8m1uwI WvZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=oAFvcy1t; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id nc7-20020a1709071c0700b0078da856a4ecsi10202998ejc.391.2022.11.14.07.04.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 07:04:18 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=oAFvcy1t; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D98438357A8 for ; Mon, 14 Nov 2022 15:04:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D98438357A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668438255; bh=egeAu/pVx29C+hHq9ZCOwQp+fCIp09lLuqC4LXHkokg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oAFvcy1tqy8aByG5iJuL+F2HsfbMsU0lgI9ZZOR5WZhzecera4muuNODZc8kXXVN7 Q/QbYv8yyZK81HyHJwgMoyypvL8g0pJZgNsI+6OiBIzKVyJsSRmFFFpKOPnWriJBil 0v38Coaqop2yn8hU/u9F9irBdDdh51Wi7AaASYaw= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by sourceware.org (Postfix) with ESMTPS id 45AC338518AA for ; Mon, 14 Nov 2022 15:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45AC338518AA Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-13ae8117023so12735669fac.9 for ; Mon, 14 Nov 2022 07:04:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=egeAu/pVx29C+hHq9ZCOwQp+fCIp09lLuqC4LXHkokg=; b=K5xoewjglRHwfP//CQQta4xnbZDsnGzlS1LPClK0hMN2r37tuIEK6lu+IlfswKQD+5 rvsTt5xuCnogIbqoZ4KPjJ9GRUBg0fDrRQa50fkk06hKe/n3RDEN+gtIP13yPJVjBDfF 5r2dTLtw2g2PkyuVFg0CAvHoo4hSyCnlFaTCjXJvdfb2yUUhRZbhSetl6rsT3akTlckd drmnE65V61cA+j7R9MADwJ7di2bA0VKSxvXMNE6NjQHMJVQ7ZxqVs6rOiPpnB7xq74kK ZKJuK30UICujDch3C5Xklu5xgjbrp8ACPX1WTtpAHybDICP+/V3gsB0fV19/QUY5KNza e4wA== X-Gm-Message-State: ANoB5pm4BaOy6KMtQC3kSk4rcJOm/kcVCSf7EYsrDSkNT/Wz9AL8+QqI nQg258g1QAvg4cS+mi+GTi9bLLBEyfrxNQ== X-Received: by 2002:a05:6870:c6a5:b0:13d:2093:7c89 with SMTP id cv37-20020a056870c6a500b0013d20937c89mr7060788oab.295.1668438243224; Mon, 14 Nov 2022 07:04:03 -0800 (PST) Received: from ola-9d10b5e-vm.ad.garmin.com ([204.77.163.55]) by smtp.gmail.com with ESMTPSA id h3-20020a9d7983000000b0063b24357269sm4178925otm.13.2022.11.14.07.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 07:04:02 -0800 (PST) To: binutils@sourceware.org Cc: Brett Werling Subject: [PATCH] readelf: use fseeko for elf files >= 2 GiB on x86_64-mingw32 Date: Mon, 14 Nov 2022 09:03:48 -0600 Message-Id: <20221114150348.112815-1-bwerl.dev@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Brett Werling via Binutils From: Brett Werling Reply-To: Brett Werling Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749484315306995250?= X-GMAIL-MSGID: =?utf-8?q?1749484315306995250?= Switch all fseek calls to fseeko and cast the given offset as an off_t accordingly. When building readelf for x86_64-mingw32, a long will only be 32 bits wide. If the elf file in question is >= 2 GiB, that is greater than the max long value, and therefore fseek will fail indicating that the offset is negative. To work around this and support up to 4 GiB, we switch to using fseeko and cast the unsigned long offsets as off_t values because the size of off_t is 64 bits on x86_64-mingw32. --- binutils/readelf.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/binutils/readelf.c b/binutils/readelf.c index 6b5bebe743f..a705850af35 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -424,7 +424,7 @@ get_data (void * var, return NULL; } - if (fseek (filedata->handle, archive_file_offset + offset, SEEK_SET)) + if (fseeko (filedata->handle, (off_t)archive_file_offset + offset, SEEK_SET)) { if (reason) error (_("Unable to seek to 0x%lx for %s\n"), @@ -5343,7 +5343,7 @@ process_program_headers (Filedata * filedata) break; case PT_INTERP: - if (fseek (filedata->handle, archive_file_offset + (long) segment->p_offset, + if (fseeko (filedata->handle, (off_t)archive_file_offset + (long) segment->p_offset, SEEK_SET)) error (_("Unable to find program interpreter name\n")); else @@ -11720,8 +11720,8 @@ process_symbol_table (Filedata * filedata) && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) hash_ent_size = 8; - if (fseek (filedata->handle, - (archive_file_offset + if (fseeko (filedata->handle, + ((off_t)archive_file_offset + offset_from_vma (filedata, dynamic_info[DT_HASH], sizeof nb + sizeof nc)), SEEK_SET)) @@ -11772,8 +11772,8 @@ process_symbol_table (Filedata * filedata) bfd_vma i, maxchain = 0xffffffff, bitmaskwords; bfd_vma buckets_vma; - if (fseek (filedata->handle, - (archive_file_offset + if (fseeko (filedata->handle, + ((off_t)archive_file_offset + offset_from_vma (filedata, dynamic_info_DT_GNU_HASH, sizeof nb)), SEEK_SET)) @@ -11797,8 +11797,8 @@ process_symbol_table (Filedata * filedata) else buckets_vma += bitmaskwords * 8; - if (fseek (filedata->handle, - (archive_file_offset + if (fseeko (filedata->handle, + ((off_t)archive_file_offset + offset_from_vma (filedata, buckets_vma, 4)), SEEK_SET)) { @@ -11826,8 +11826,8 @@ process_symbol_table (Filedata * filedata) maxchain -= gnusymidx; - if (fseek (filedata->handle, - (archive_file_offset + if (fseeko (filedata->handle, + ((off_t)archive_file_offset + offset_from_vma (filedata, buckets_vma + 4 * (ngnubuckets + maxchain), 4)), SEEK_SET)) @@ -11851,8 +11851,8 @@ process_symbol_table (Filedata * filedata) } while ((byte_get (nb, 4) & 1) == 0); - if (fseek (filedata->handle, - (archive_file_offset + if (fseeko (filedata->handle, + ((off_t)archive_file_offset + offset_from_vma (filedata, buckets_vma + 4 * ngnubuckets, 4)), SEEK_SET)) { @@ -11868,8 +11868,8 @@ process_symbol_table (Filedata * filedata) if (dynamic_info_DT_MIPS_XHASH) { - if (fseek (filedata->handle, - (archive_file_offset + if (fseeko (filedata->handle, + ((off_t)archive_file_offset + offset_from_vma (filedata, (buckets_vma + 4 * (ngnubuckets + maxchain)), 4)), @@ -20185,7 +20185,7 @@ process_archive (Filedata * filedata, bfd_boolean is_thin_archive) ret = FALSE; } - if (fseek (filedata->handle, current_pos, SEEK_SET) != 0) + if (fseeko (filedata->handle, (off_t)current_pos, SEEK_SET) != 0) { error (_("%s: failed to seek back to start of object files in the archive\n"), filedata->file_name); @@ -20211,7 +20211,7 @@ process_archive (Filedata * filedata, bfd_boolean is_thin_archive) char * qualified_name; /* Read the next archive header. */ - if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) + if (fseeko (filedata->handle, (off_t)arch.next_arhdr_offset, SEEK_SET) != 0) { error (_("%s: failed to seek to next archive header\n"), arch.file_name); return FALSE; @@ -20309,7 +20309,7 @@ process_archive (Filedata * filedata, bfd_boolean is_thin_archive) /* The nested archive file will have been opened and setup by get_archive_member_name. */ - if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0) + if (fseeko (nested_arch.file, (off_t)archive_file_offset, SEEK_SET) != 0) { error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name); ret = FALSE;