This patch fixes the libbacktrace file type detection, which is run at
configure time, to only look for a magic number at the very start of
the file.  Otherwise we can get confused if the bytes happen to appear
elsewhere on the first "line".  This is for PR 96971.  Bootstrapped
and ran libbacktrace tests on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian

PR libbacktrace/96971
            * filetype.awk: Only match magic number at start of line.
diff --git a/libbacktrace/filetype.awk b/libbacktrace/filetype.awk
index 14d91581f7e..1eefa7e72f0 100644
--- a/libbacktrace/filetype.awk
+++ b/libbacktrace/filetype.awk
@@ -1,13 +1,13 @@
 # An awk script to determine the type of a file.
-/\177ELF\001/      { if (NR == 1) { print "elf32"; exit } }
-/\177ELF\002/      { if (NR == 1) { print "elf64"; exit } }
-/\114\001/         { if (NR == 1) { print "pecoff"; exit } }
-/\144\206/         { if (NR == 1) { print "pecoff"; exit } }
-/\001\337/         { if (NR == 1) { print "xcoff32"; exit } }
-/\001\367/         { if (NR == 1) { print "xcoff64"; exit } }
-/\376\355\372\316/ { if (NR == 1) { print "macho"; exit } }
-/\316\372\355\376/ { if (NR == 1) { print "macho"; exit } }
-/\376\355\372\317/ { if (NR == 1) { print "macho"; exit } }
-/\317\372\355\376/ { if (NR == 1) { print "macho"; exit } }
-/\312\376\272\276/ { if (NR == 1) { print "macho"; exit } }
-/\276\272\376\312/ { if (NR == 1) { print "macho"; exit } }
+/^\177ELF\001/      { if (NR == 1) { print "elf32"; exit } }
+/^\177ELF\002/      { if (NR == 1) { print "elf64"; exit } }
+/^\114\001/         { if (NR == 1) { print "pecoff"; exit } }
+/^\144\206/         { if (NR == 1) { print "pecoff"; exit } }
+/^\001\337/         { if (NR == 1) { print "xcoff32"; exit } }
+/^\001\367/         { if (NR == 1) { print "xcoff64"; exit } }
+/^\376\355\372\316/ { if (NR == 1) { print "macho"; exit } }
+/^\316\372\355\376/ { if (NR == 1) { print "macho"; exit } }
+/^\376\355\372\317/ { if (NR == 1) { print "macho"; exit } }
+/^\317\372\355\376/ { if (NR == 1) { print "macho"; exit } }
+/^\312\376\272\276/ { if (NR == 1) { print "macho"; exit } }
+/^\276\272\376\312/ { if (NR == 1) { print "macho"; exit } }

Reply via email to