summaryrefslogtreecommitdiff
path: root/rts/linker/LoadArchive.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-02-05 23:12:07 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-04-06 13:01:28 -0400
commit400666c81af024b6d16100aba88c2e8e78e8eef8 (patch)
tree08324c14136e7fd92fa20769f9e25c280a0eeb35 /rts/linker/LoadArchive.c
parent410c76eea7370f2d1143cf79aa524fcdec184f89 (diff)
downloadhaskell-400666c81af024b6d16100aba88c2e8e78e8eef8.tar.gz
rts/linker: Catch archives masquerading as object files
Check the file's header to catch static archive bearing the `.o` extension, as may happen on Windows after the Clang refactoring. See #21068
Diffstat (limited to 'rts/linker/LoadArchive.c')
-rw-r--r--rts/linker/LoadArchive.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/rts/linker/LoadArchive.c b/rts/linker/LoadArchive.c
index 99e405db22..86fa5cb94b 100644
--- a/rts/linker/LoadArchive.c
+++ b/rts/linker/LoadArchive.c
@@ -241,7 +241,7 @@ lookupGNUArchiveIndex(int gnuFileIndexSize, char **fileName_,
return true;
}
-static HsInt loadArchive_ (pathchar *path)
+HsInt loadArchive_ (pathchar *path)
{
char *image = NULL;
HsInt retcode = 0;
@@ -632,3 +632,21 @@ HsInt loadArchive (pathchar *path)
RELEASE_LOCK(&linker_mutex);
return r;
}
+
+bool isArchive (pathchar *path)
+{
+ static const char ARCHIVE_HEADER[] = "!<arch>\n";
+ char buffer[10];
+ FILE *f = pathopen(path, WSTR("rb"));
+ if (f == NULL) {
+ return false;
+ }
+
+ size_t ret = fread(buffer, 1, sizeof(buffer), f);
+ if (ret < sizeof(buffer)) {
+ return false;
+ }
+ fclose(f);
+ return strncmp(ARCHIVE_HEADER, buffer, sizeof(ARCHIVE_HEADER)-1) == 0;
+}
+