From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 784A73858D1E for ; Tue, 23 Aug 2022 21:11:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 784A73858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=martin.st Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=martin.st Received: by mail-lj1-x22d.google.com with SMTP id z20so14680370ljq.3 for ; Tue, 23 Aug 2022 14:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc; bh=roDgDMWt97+JYFDGHyXCxRlmtEqJMWjZlRRpBGk8b/w=; b=7wZEUYgffMngJghwFHA/0x4VNMAxo0t8QA7oureFqa8F6czH9nosay0NFO5rvsnEG9 M6L/CbTzaQjMUxzXEZb156m5NlBRthtU2n50lVemSh7RumhitumXeGrNkm+csgzKzxW0 AhvRlAPo5JNJPSnlYS/VFeM3pQauBDusoXtPAXTm2PmbyBWfua1kz/irNwizm+ZlWRQR l4YZKUqa6n/cX3c+QjJ2it4O8Uamq5XY069djxfwfQVHiva8LtW13wmYL9vXLGNAJUP2 odlDX7XTpNT7XlijK+HqQwT4NZVHgZZ+8sAnx6ENuOJ0p7FbwWAHHlxu1scnkyFa8z/8 Lsaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=roDgDMWt97+JYFDGHyXCxRlmtEqJMWjZlRRpBGk8b/w=; b=sNXGiiT21O4lLNkl/vL518biAxk7doCwWTPCxmHB8ovZFkIYRrPM/5SK4gzZcheK8c EfURrhzanYsL0VcLhfHilZj5ueQl7T43w8EuloNZq6szILjIap9LW7Iqp5SC650X7f83 VzcBhixfodq+ovidJ0q/XVIl8TWxA0HY91ZOQAd0QiL4nlf0LZKIb2eRXSFNnOdkNrDr RNi98s+wy1VP8rwyCk9TOnN3Gn6nr+wJWjNTadzpNvbOqMqKdnL2+Eyw+nIjEEdaEgmn QFpE5BuOgkw0nB9kc+cGMBcKqS04sZt/Y+fC6p59v1Rqy6BqxnfFxxfCSvZc5WFjMJX4 YaVQ== X-Gm-Message-State: ACgBeo0g+jvvAYzyJgt091onuMotAtJugb+Pi4fIAXato7ars7rb9byN 54rpH8xwgCiN8YocYj9+IOj/IgC5QcSvtHNv X-Google-Smtp-Source: AA6agR6srvD41c7B5AmP2LtmazBZg9gwsv5f5i5qs1iDSbIEek3YJUQR8JAtL7uaHmvSdf80szF5cA== X-Received: by 2002:a2e:9049:0:b0:261:c790:948a with SMTP id n9-20020a2e9049000000b00261c790948amr4406367ljg.449.1661289116133; Tue, 23 Aug 2022 14:11:56 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id o22-20020ac24e96000000b0048a9a756763sm1569497lfr.19.2022.08.23.14.11.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 14:11:55 -0700 (PDT) From: =?UTF-8?q?Martin=20Storsj=C3=B6?= To: binutils@sourceware.org Subject: [PATCH v3] ld: Make archive member file extension comparisons case insensitive when cross compiling too Date: Wed, 24 Aug 2022 00:11:54 +0300 Message-Id: <20220823211154.1775739-1-martin@martin.st> X-Mailer: git-send-email 2.25.1 In-Reply-To: <58cd3a02-08bf-972d-c4e0-f39622d849c0@suse.com> References: <58cd3a02-08bf-972d-c4e0-f39622d849c0@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, 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 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-List-Received-Date: Tue, 23 Aug 2022 21:12:01 -0000 On Windows, filename_cmp is case insensitive, but when cross compiling with libraries that may contain members with uppercase file names, we should keep those comparisons case insensitive when running the build tools on other OSes too. --- v3: Renamed the function to fileext_cmp as suggested. (This also fixes building on Windows, where there already existed a non-static function named stricmp.) --- ld/emultempl/pe.em | 25 +++++++++++++++++++++---- ld/emultempl/pep.em | 24 ++++++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index ad969ccec13..c34ddebd489 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -171,6 +171,23 @@ static int is_underscoring (void) return pe_leading_underscore; } +/* A case insensitive comparison, regardless of the host platform, + used for comparing file extensions. */ +static int fileext_cmp (const char *s1, const char *s2) +{ + for (;;) + { + int c1 = TOLOWER (*s1++); + int c2 = TOLOWER (*s2++); + + if (c1 != c2) + return (c1 - c2); + + if (c1 == '\0') + return 0; + } +} + static void gld${EMULATION_NAME}_before_parse (void) { @@ -1666,7 +1683,7 @@ gld${EMULATION_NAME}_after_open (void) extension, and use that for the remainder of the comparisons. */ pnt = strrchr (bfd_get_filename (is3->the_bfd), '.'); - if (pnt != NULL && filename_cmp (pnt, ".dll") == 0) + if (pnt != NULL && fileext_cmp (pnt, ".dll") == 0) break; } @@ -1683,7 +1700,7 @@ gld${EMULATION_NAME}_after_open (void) /* Skip static members, ie anything with a .obj extension. */ pnt = strrchr (bfd_get_filename (is2->the_bfd), '.'); - if (pnt != NULL && filename_cmp (pnt, ".obj") == 0) + if (pnt != NULL && fileext_cmp (pnt, ".obj") == 0) continue; if (filename_cmp (bfd_get_filename (is3->the_bfd), @@ -1701,7 +1718,7 @@ gld${EMULATION_NAME}_after_open (void) then leave the filename alone. */ pnt = strrchr (bfd_get_filename (is->the_bfd), '.'); - if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0)) + if (is_ms_arch && (fileext_cmp (pnt, ".dll") == 0)) { int idata2 = 0, reloc_count=0; asection *sec; @@ -1857,7 +1874,7 @@ gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBU #ifdef DLL_SUPPORT const char *ext = entry->filename + strlen (entry->filename) - 4; - if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0) + if (fileext_cmp (ext, ".def") == 0) { pe_def_file = def_file_parse (entry->filename, pe_def_file); diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index ee36a9a7e56..ba4fc01ed70 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -181,6 +181,22 @@ static int is_underscoring (void) return pep_leading_underscore; } +/* A case insensitive comparison, regardless of the host platform, + used for comparing file extensions. */ +static int fileext_cmp (const char *s1, const char *s2) +{ + for (;;) + { + int c1 = TOLOWER (*s1++); + int c2 = TOLOWER (*s2++); + + if (c1 != c2) + return (c1 - c2); + + if (c1 == '\0') + return 0; + } +} static void gld${EMULATION_NAME}_before_parse (void) @@ -1630,7 +1646,7 @@ gld${EMULATION_NAME}_after_open (void) extension, and use that for the remainder of the comparisons. */ pnt = strrchr (bfd_get_filename (is3->the_bfd), '.'); - if (pnt != NULL && filename_cmp (pnt, ".dll") == 0) + if (pnt != NULL && fileext_cmp (pnt, ".dll") == 0) break; } @@ -1647,7 +1663,7 @@ gld${EMULATION_NAME}_after_open (void) /* Skip static members, ie anything with a .obj extension. */ pnt = strrchr (bfd_get_filename (is2->the_bfd), '.'); - if (pnt != NULL && filename_cmp (pnt, ".obj") == 0) + if (pnt != NULL && fileext_cmp (pnt, ".obj") == 0) continue; if (filename_cmp (bfd_get_filename (is3->the_bfd), @@ -1665,7 +1681,7 @@ gld${EMULATION_NAME}_after_open (void) then leave the filename alone. */ pnt = strrchr (bfd_get_filename (is->the_bfd), '.'); - if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0)) + if (is_ms_arch && (fileext_cmp (pnt, ".dll") == 0)) { int idata2 = 0, reloc_count=0; asection *sec; @@ -1727,7 +1743,7 @@ gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBU #ifdef DLL_SUPPORT const char *ext = entry->filename + strlen (entry->filename) - 4; - if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0) + if (fileext_cmp (ext, ".def") == 0) { pep_def_file = def_file_parse (entry->filename, pep_def_file); -- 2.25.1