public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch] coff-stgo32: Fix false format match
@ 2011-07-20 15:55 Jan Kratochvil
  2011-07-20 19:10 ` DJ Delorie
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2011-07-20 15:55 UTC (permalink / raw)
  To: binutils; +Cc: DJ Delorie

Hello DJ,

on fedora-rawhide-x86_64 with -m32 (not on fedora-rawhide-i386) GDB gets false:
	FAIL: gdb.base/solib-nodir.exp: running to main in runto (end of file)
	FAIL: gdb.base/solib-nodir.exp: library loaded

because the ELF32 i386 file gets falsely matched as I386PTXMAGIC COFF file.
BFD/GDB then crashes on trying to read that file; fix of that crash is outside
of scope of this patch, it would not work with the COFF format anyway.

No regressions x86_64-fedora16pre-linux-gnu --target=i386-unknown-go32.


Thanks,
Jan


bfd/
2011-07-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix false coff-go32-exe matches.
	* coff-i386.c (TARGET_SYM) <_bfd_check_format>: Conditionally use
	COFF_CHECK_FORMAT.
	* coff-stgo32.c (go32_check_format): New forward declaration.
	(COFF_CHECK_FORMAT): New defintion.
	(go32_check_format): New function.

--- a/bfd/coff-i386.c
+++ b/bfd/coff-i386.c
@@ -671,8 +671,13 @@ const bfd_target
      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
 
 /* Note that we allow an object file to be treated as a core file as well.  */
-    {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
-       bfd_generic_archive_p, coff_object_p},
+    /* bfd_check_format */
+#ifdef COFF_CHECK_FORMAT
+    {_bfd_dummy_target, COFF_CHECK_FORMAT,
+       bfd_generic_archive_p, COFF_CHECK_FORMAT},
+#else
+    {_bfd_dummy_target, coff_object_p, bfd_generic_archive_p, coff_object_p},
+#endif
     {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
        bfd_false},
     {bfd_false, coff_write_object_contents, /* bfd_write_contents */
--- a/bfd/coff-stgo32.c
+++ b/bfd/coff-stgo32.c
@@ -95,6 +95,10 @@ create_go32_stub PARAMS ((bfd *));
 #define COFF_ADJUST_AUX_OUT_PRE adjust_aux_out_pre
 #define COFF_ADJUST_AUX_OUT_POST adjust_aux_out_post
 
+static const bfd_target *go32_check_format (bfd *abfd);
+
+#define COFF_CHECK_FORMAT go32_check_format
+
 static bfd_boolean
   go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
 
@@ -414,3 +418,23 @@ go32_stubbed_coff_bfd_copy_private_bfd_data  (ibfd, obfd)
 
   return TRUE;
 }
+
+/* coff_object_p only checks 2 bytes F_MAGIC at GO32_STUBSIZE inside the file
+   which is too fragile.  */
+
+static const bfd_target *
+go32_check_format (bfd *abfd)
+{
+  char mz[2];
+
+  if (bfd_bread (mz, 2, abfd) != 2 || mz[0] != 'M' || mz[1] != 'Z')
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return NULL;
+    }
+
+  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
+    return NULL;
+
+  return coff_object_p (abfd);
+}


begin 755 solib-nodir.so.gz
M'XL("+;O)DX"`W-O;&EB+6YO9&ER+G-O`)U7?6@41Q2?O;O$BSGC);U\:%(\
M6BF)K=LDFO@)YL,D:F-BD]A:0EPNV35W>G>KMQM)Q%KC58@-`:FA?[3_"$(+
M%HN@E!8I:).6]I\VM/8#2JG4#TX,&C$M1<3K>S.S=W/K^4<[Q[LW;]]OYLW.
MO/=VWELM[:V2)!&K.>&'T@XG(:N!'U[`GJ\F?I)+*LFS9"E)HWG+882,>`G3
MHU#,R`,/?$"Y7.\`5@;ZLF)&,X01ZEV<Y@5:SLG2[;AIJI/0L:B",++TKX*>
M9&GB_#[ZKH2T=>PDRXYM2ER__,IOG??J>O\X>_)8WH-SAYP<Y^#CQIK\$IEN
MR,-GN"5Y0$TM/\V.&6/YEZZ_>_C7`[LJ/I^X7W#GQWL%=KL50O\Y0C+VSP_T
MHDU^'<A3PF0ON9_<A#(8?AYX$<DG>W']@GZW#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
M9@`QJJ$KP4!4#4.=N/F-CL;M6YN)TM;>V=38KG2VMG:W]"@]C4WM+4JJ-,Q2
?8C8TB`6AK3+%4I/6D!E%99::E)6P_P)C1HRJS1``````
`
end

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] coff-stgo32: Fix false format match
  2011-07-20 15:55 [patch] coff-stgo32: Fix false format match Jan Kratochvil
@ 2011-07-20 19:10 ` DJ Delorie
  2011-07-20 19:24   ` Jan Kratochvil
  0 siblings, 1 reply; 5+ messages in thread
From: DJ Delorie @ 2011-07-20 19:10 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: binutils


GO32 binaries need not have the stub on them, so you have to check for
MZ as well as a standard COFF magic number at offset zero.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] coff-stgo32: Fix false format match
  2011-07-20 19:10 ` DJ Delorie
@ 2011-07-20 19:24   ` Jan Kratochvil
  2011-07-22 11:21     ` DJ Delorie
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2011-07-20 19:24 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

On Wed, 20 Jul 2011 20:26:51 +0200, DJ Delorie wrote:
> GO32 binaries need not have the stub on them, so you have to check for
> MZ as well as a standard COFF magic number at offset zero.

I have modified only coff-stgo32.c ("coff-go32-exe") which seems to always
offset everything of COFF by GO32_STUBSIZE.

There is also coff-go32.c ("coff-go32") but I haven't touched that one.

My former patch for coff-go32-exe does MZ check && coff magic check.
The FSF binutils HEAD code does                    coff magic check.
Your proposed IIUC                     MZ check || coff magic check
is not useful because the coff magic check itself has the false positives.

Still I do not know whether there isn't in use some alternative env(GO32STUB)
for a .com file - where for .com there would be no 'MZ' signature.


Alternatively proposing the patch below.
No regressions x86_64-fedora16pre-linux-gnu --target=i386-unknown-go32.


Thanks,
Jan


bfd/
2011-07-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix false coff-go32-exe matches.
	* coff-i386.c (TARGET_SYM) <match_priority>: Use TARGET_MATCH_PRIORITY
	if available.
	* coff-stgo32.c (TARGET_MATCH_PRIORITY): New defintion.

--- a/bfd/coff-i386.c
+++ b/bfd/coff-i386.c
@@ -661,7 +661,11 @@ const bfd_target
 #endif
   '/',				/* ar_pad_char */
   15,				/* ar_max_namelen */
-  0,				/* match priority.  */
+#ifdef TARGET_MATCH_PRIORITY
+  TARGET_MATCH_PRIORITY,	/* match priority */
+#else
+  0,				/* match priority */
+#endif
 
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
--- a/bfd/coff-stgo32.c
+++ b/bfd/coff-stgo32.c
@@ -100,6 +100,10 @@ static bfd_boolean
 
 #define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data
 
+/* Two bytes of magic are too fragile when matched at GO32_STUBSIZE offset
+   inside executable.  */
+#define TARGET_MATCH_PRIORITY 10
+
 #include "coff-i386.c"
 
 /* This macro is used, because I cannot assume the endianness of the

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] coff-stgo32: Fix false format match
  2011-07-20 19:24   ` Jan Kratochvil
@ 2011-07-22 11:21     ` DJ Delorie
  2011-07-22 12:49       ` Jan Kratochvil
  0 siblings, 1 reply; 5+ messages in thread
From: DJ Delorie @ 2011-07-22 11:21 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: binutils


Ah, right.  Nevermind.  Your original patch is fine, then.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] coff-stgo32: Fix false format match
  2011-07-22 11:21     ` DJ Delorie
@ 2011-07-22 12:49       ` Jan Kratochvil
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Kratochvil @ 2011-07-22 12:49 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

On Wed, 20 Jul 2011 21:10:12 +0200, DJ Delorie wrote:
> Ah, right.  Nevermind.  Your original patch is fine, then.

On Wed, 20 Jul 2011 17:21:21 +0200, Jan Kratochvil wrote:
# bfd/
# 2011-07-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
# 
# 	Fix false coff-go32-exe matches.
# 	* coff-i386.c (TARGET_SYM) <_bfd_check_format>: Conditionally use
# 	COFF_CHECK_FORMAT.
# 	* coff-stgo32.c (go32_check_format): New forward declaration.
# 	(COFF_CHECK_FORMAT): New defintion.
# 	(go32_check_format): New function.

Therefore checked the first patch in:
	http://sourceware.org/ml/binutils-cvs/2011-07/msg00109.html


Thanks,
Jan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-20 19:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-20 15:55 [patch] coff-stgo32: Fix false format match Jan Kratochvil
2011-07-20 19:10 ` DJ Delorie
2011-07-20 19:24   ` Jan Kratochvil
2011-07-22 11:21     ` DJ Delorie
2011-07-22 12:49       ` Jan Kratochvil

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).