From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 45E313858036 for ; Wed, 24 Aug 2022 10:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45E313858036 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-x132.google.com with SMTP id m5so12623897lfj.4 for ; Wed, 24 Aug 2022 03:04:40 -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=/4JZK7fYtzHFqJyDo5nSpx78JHWJm1PVeu9nQWEcwzo=; b=aw4HY1Kr0ue4KG6TODmjwXW4NEIg2TDHCFHDJoewOMC2MFxGl4ZkMbKJfmGSFystgt uXHYnHf8vvA+XWGwv3EkInHKzoG8ScrcMw5DhOaMmhuPhxlgQ2nHC7IeN03CatSNioUF a81D2UhBW6YZ3/GizG4nOzNN5QfAcqe6eyap76XtzM3UzqN8iSsxqKD09rmuI2lRAT3h 0R4zlxy7B3vbgFqKqYvf8d1ohQhiL/Oela1dhkRa/lyIZQeK9QYPjnRY6K7/DZZHuB+c 7bLax85VCABAUwRyKHH/17BsIYYfxDQPfpiaFgafF99u53ZsKhQpPsS0PuFOObUs0hD0 BDxw== 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=/4JZK7fYtzHFqJyDo5nSpx78JHWJm1PVeu9nQWEcwzo=; b=reRBwWiXqe8e7vAMBFHBHPN90mp5t4evk+g+OA5ld2LQbcXDrzGadyezGJUVn/YDYt EtTJyl5UTE4xWdr98Nz+0FCy0q7rEKemr7lD+javCd0PZeVZuzkqR7hb78j51n60J07Y cOGRPSJbZEJRChHvKVdE3wiMRtYyuIOFZMlQRcLi+pj5PmiDNBxokwzDeGgnLRGb2uN4 5gg7bi0+dzKZ57XtqZYR1v9+iOIw10yATIJyirqer8nxFJvCKiLSCCy8vbDii/zGqfmz ihnmmxzfz6ipgeg02Fnq72qke6+KUb3IBneMNlTgOSmpi/p6rUXI2t3dyEE46LG9rFSt I1JQ== X-Gm-Message-State: ACgBeo1Z0Z2M7zU+lmhX1ZibTdLhaTxb8b+Sz9vNPziRZ6fnLWEP/s+X joY0xBsNzx9YXsZEGS8NeT/tVzu5Y0L7gMts X-Google-Smtp-Source: AA6agR7JW5nyB7RtXBw/us6vadgBgmfordW6t2UDiSTjmJ2vy5krO+hG4WgUu7bgKHcaDkqzbrtOww== X-Received: by 2002:a05:6512:228a:b0:492:b0d5:910e with SMTP id f10-20020a056512228a00b00492b0d5910emr11019617lfu.616.1661335478821; Wed, 24 Aug 2022 03:04:38 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id 23-20020ac25f57000000b0048ceb3836d4sm1639159lfz.6.2022.08.24.03.04.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 03:04:38 -0700 (PDT) From: =?UTF-8?q?Martin=20Storsj=C3=B6?= To: binutils@sourceware.org Subject: [PATCH v5] ld: Make archive member file extension comparisons case insensitive when cross compiling too Date: Wed, 24 Aug 2022 13:04:33 +0300 Message-Id: <20220824100434.7797-1-martin@martin.st> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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 List-Id: 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. --- v5: Moved the function name to a separate line, added double spaces before the closing of comments. --- ld/emultempl/pe.em | 31 +++++++++++++++++++++++++++---- ld/emultempl/pep.em | 30 ++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index ad969ccec13..d51bf4d3abb 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -171,6 +171,29 @@ static int is_underscoring (void) return pe_leading_underscore; } +/* A case insensitive comparison, regardless of the host platform, used for + comparing file extensions. Parameter s1 points at the extension in a file + name (pointing at the starting '.'). Parameter s2 is a lower case string + without the leading '.'. */ +static int +fileext_cmp (const char *s1, const char *s2) +{ + if (*s1 != '.') + return 1; + s1++; + for (;;) + { + int c1 = TOLOWER (*s1++); + int c2 = *s2++; /* Assumed to be lower case from the caller. */ + + if (c1 != c2) + return (c1 - c2); + + if (c1 == '\0') + return 0; + } +} + static void gld${EMULATION_NAME}_before_parse (void) { @@ -1666,7 +1689,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 +1706,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 +1724,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 +1880,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..f060bf092ed 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -181,6 +181,28 @@ static int is_underscoring (void) return pep_leading_underscore; } +/* A case insensitive comparison, regardless of the host platform, used for + comparing file extensions. Parameter s1 points at the extension in a file + name (pointing at the starting '.'). Parameter s2 is a lower case string + without the leading '.'. */ +static int +fileext_cmp (const char *s1, const char *s2) +{ + if (*s1 != '.') + return 1; + s1++; + for (;;) + { + int c1 = TOLOWER (*s1++); + int c2 = *s2++; /* Assumed to be lower case from the caller. */ + + if (c1 != c2) + return (c1 - c2); + + if (c1 == '\0') + return 0; + } +} static void gld${EMULATION_NAME}_before_parse (void) @@ -1630,7 +1652,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 +1669,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 +1687,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 +1749,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