From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id DF6E83858C62 for ; Tue, 23 Aug 2022 13:06:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF6E83858C62 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-lf1-x12d.google.com with SMTP id bq23so10549352lfb.7 for ; Tue, 23 Aug 2022 06:06:08 -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:message-id:date:subject:to :from:from:to:cc; bh=3Gtvc+KFx6qeelHJyZl+vzLF9bPeTeq38FGmn95o1+8=; b=LHFF164iOQ2Ov+CepFNexpavRc+0gdHsXgpJsZzzk0u+B+mh0o9DJxfTdffQGeSicr 9JTlWLSsN5COIBQNX5R06DVY5V7wa34Jo91x+JObrXnwPyopluM1n0pKGz76psjFTIMm I2iU3ea7ny5yDxt2oyRWyU/pe+qaqEVjQFdcnYS9S+GYdn0XLCI3tDmSS+tGz6kn/Kc7 xOPWwP15U8RlI0fCExEHwZYkYbJiZC0cJiYlJx19uqk574WrTZ3B4fkLK4hk4YGqyFss 5LVHt+Ngl5hoewUX5nkAGOf4JjKE5XLagifnHxmM9lbGtWF6F8eYFIRp7GmP+R03lO+D OEGw== 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:to :from:x-gm-message-state:from:to:cc; bh=3Gtvc+KFx6qeelHJyZl+vzLF9bPeTeq38FGmn95o1+8=; b=ugJJRkEBuJW4ALo8p6ewRL9fE7UukJ9Hl5XNDs9ZT5ddHdE6Bvo073NqIvdhfIpHky nCGDbswu4ptzUzWB1Ohh9LTpwyd/0yIsGnBPV6zCah1lnCB3hQzKnLUgyPgrahJ/hlmS 5qsA+q9SXoHxuzZIv2aYozZyi7CzUr7Ddk0+brbV2ToX4udkziuXPwOoGo30if+qwwnd muo/vJjBQuXe2cjz7yBsCGu1aI5i/72oOtEDOJ8Ooa+obYuZnjhFeSWcpS9yKvVA88bS IclRAeykbYQWJT3INz3I7QFdnoHF2IKCWLeUfgFVuMaINTQzVLsrUqQ+JinrLhFUsEv/ Su1Q== X-Gm-Message-State: ACgBeo1CQjD/tjWD/el1Fa3jBmHyCOCrs2bY55oQFQ3xa0aVq/iSUK9s VBSEGnpYxLWa//JYNrTaJKMEeu/BqE0kpRP5 X-Google-Smtp-Source: AA6agR74EoLCsqIVtMxCxn+1rMiv/QqtbsAgkIBSiSITkMBnb5g1oRaP99zR5U88PPhosYuOC6R6fA== X-Received: by 2002:a05:6512:ac6:b0:492:f389:a065 with SMTP id n6-20020a0565120ac600b00492f389a065mr1218782lfu.278.1661259967434; Tue, 23 Aug 2022 06:06:07 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id y25-20020a056512045900b0048a8b6914d2sm127288lfk.155.2022.08.23.06.06.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 06:06:07 -0700 (PDT) From: =?UTF-8?q?Martin=20Storsj=C3=B6?= To: binutils@sourceware.org Subject: [PATCH v2] ld: Make library member file suffix comparisons case insensitive when cross compiling too Date: Tue, 23 Aug 2022 16:06:06 +0300 Message-Id: <20220823130606.1659316-1-martin@martin.st> X-Mailer: git-send-email 2.25.1 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 13:06:11 -0000 On Windows, filename_cmp is case insensitive, but when cross compiling with similar 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. --- v2: Fix a missed == 0 in pep.em, which was accidentally removed in the first version of the patch. --- ld/emultempl/pe.em | 26 ++++++++++++++++++++++---- ld/emultempl/pep.em | 25 +++++++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 2fd4ff4acaf..59bda7da968 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -171,6 +171,24 @@ static int is_underscoring (void) return pe_leading_underscore; } +/* Hardcoded case insensitive comparison. filename_cmp is insensitive + * when running on Windows, but when cross compiling to Windows, we + * also want similar comparisons to be case insensitive. */ +static int stricmp (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) { @@ -1660,7 +1678,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 && stricmp (pnt, ".dll") == 0) break; } @@ -1677,7 +1695,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 && stricmp (pnt, ".obj") == 0) continue; if (filename_cmp (bfd_get_filename (is3->the_bfd), @@ -1695,7 +1713,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 && (stricmp (pnt, ".dll") == 0)) { int idata2 = 0, reloc_count=0; asection *sec; @@ -1854,7 +1872,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 (stricmp (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 e68d1e69f17..0c2f6159ac9 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -181,6 +181,23 @@ static int is_underscoring (void) return pep_leading_underscore; } +/* Hardcoded case insensitive comparison. filename_cmp is insensitive + * when running on Windows, but when cross compiling to Windows, we + * also want similar comparisons to be case insensitive. */ +static int stricmp (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) @@ -1624,7 +1641,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 && stricmp (pnt, ".dll") == 0) break; } @@ -1641,7 +1658,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 && stricmp (pnt, ".obj") == 0) continue; if (filename_cmp (bfd_get_filename (is3->the_bfd), @@ -1659,7 +1676,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 && (stricmp (pnt, ".dll") == 0)) { int idata2 = 0, reloc_count=0; asection *sec; @@ -1724,7 +1741,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 (stricmp (ext, ".def") == 0) { pep_def_file = def_file_parse (entry->filename, pep_def_file); -- 2.25.1