From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 7F4C438582BE for ; Wed, 24 Aug 2022 08:23:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7F4C438582BE 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-x130.google.com with SMTP id bq23so13931813lfb.7 for ; Wed, 24 Aug 2022 01:23:19 -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=AxhQOTTa15afihr3pZvLw6P0jqjj3Zkl+9XjXTsmoUg=; b=HYMQtIem+BbGdgBZsJaXUu2/eLYgvPX/Dy8DTkh3znnyZJPShr+DFFmFVS1z79+uGq MI6Udj2JzOAbt4PiLx8a9Z/G586dNZWN2OEu6Gy1LZpC3KOUXs+cb5+7prlZsTHN5suC NIRsRgE3yDHsElstg48u7OpxlBsYaUgd0jPFOvDgz56ARvvTdPvuffXBulMqY8gQmtwt o4UBFAPLo0JOGsLpCiBdFS7BBfuzW7pqZOzFiQu3/RKSPgQEfmHEUfSHH9sO48g0degi klcSzg4cg/LEltoYib8LPF6NNCXuTxyHAjEcV80ZRxZGC8xaj6BnkfoJ6PrueEahE6oH nqag== 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=AxhQOTTa15afihr3pZvLw6P0jqjj3Zkl+9XjXTsmoUg=; b=yafS7fIxL9j884lUXwYuz7FDUuwxgpO38VN9mJhaXcsRO3auUlaEQMjyfFqvg36W6u 94KEee53O5xGDGAlWuKxS57qTQl+PlvKh1uCHG6X+jaTWsKJvdwhHQ/P76nVjGcF5/Pl 4W86pY/36s8d9joyqt1SDengesYDHG8eIs0N8tbRoY99vvQKM5QHlJzxwvz9fpRKtEXJ CjcJ4X2pnQbaUV5K0aXrPlliegyUMGN5TYcWi06hj0INtoy/Ga7D3+qv02J4u98GR80P SKDRZv33VLyY2+qBeHxF6V8PiK1hKeUpkMSCnNEJlHzkE3XPE+F/E/57ITXulExReU3g 9YXQ== X-Gm-Message-State: ACgBeo0scciSvqfMoBvAOy4/cwqTBYgn4KklrguEJU3LYbcO/TdUgNls JWr+fu60D+q3ASxvZQz7fXLkHJi9YWAV/sZ4 X-Google-Smtp-Source: AA6agR6YXEh0C2IdKYB/71mmBprp3QnK2TIC4uHV2POVW7o7vcKETz7aGd7DEas4Dw8TGTb9IbKVnQ== X-Received: by 2002:a05:6512:3c93:b0:48c:dc60:4786 with SMTP id h19-20020a0565123c9300b0048cdc604786mr9550680lfv.208.1661329398040; Wed, 24 Aug 2022 01:23:18 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id 10-20020ac25f0a000000b00492f37e428asm904281lfq.172.2022.08.24.01.23.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 01:23:17 -0700 (PDT) From: =?UTF-8?q?Martin=20Storsj=C3=B6?= To: binutils@sourceware.org Subject: [PATCH v4] ld: Make archive member file extension comparisons case insensitive when cross compiling too Date: Wed, 24 Aug 2022 11:23:16 +0300 Message-Id: <20220824082316.3213884-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. --- v4: Made the function assume that the second parameter is lower case and without a leading '.'. --- ld/emultempl/pe.em | 30 ++++++++++++++++++++++++++---- ld/emultempl/pep.em | 29 +++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index ad969ccec13..86120fa0f57 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -171,6 +171,28 @@ 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 +1688,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 +1705,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 +1723,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 +1879,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..96dbd15a870 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -181,6 +181,27 @@ 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 +1651,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 +1668,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 +1686,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 +1748,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