public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: Make library member file suffix comparisons case insensitive when cross compiling too
@ 2022-08-23 11:37 Martin Storsjö
  0 siblings, 0 replies; only message in thread
From: Martin Storsjö @ 2022-08-23 11:37 UTC (permalink / raw)
  To: binutils

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.
---
 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..7228a879065 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"))
     {
       pep_def_file = def_file_parse (entry->filename, pep_def_file);
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-23 11:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 11:37 [PATCH] ld: Make library member file suffix comparisons case insensitive when cross compiling too Martin Storsjö

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).