This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Make dotnet assemblies test more robust


Omair Majid <omajid@redhat.com> writes:

> Nick Clifton <nickc@redhat.com> writes:
>
>> I think that what we need to do is to extend gentestdlls.c so that
>> it generates a normal x86 PE dll file as well.  Then the test can
>> be extended to check this file first.  If the target objdump is
>> able to parse this file, then it should be able to parse the other
>> two files as well.  If it cannot then there is an error.  (Actually
>> 32-bit PE toolchains may only be able to parse one of the new .NET
>> PE dlls).
>
> Thanks for the idea! How does the attached patch look?

Oops. I just realized that I made a mistake in strcmp. Fixed now.

binutils/ChangeLog:

2019-07-25  Omair Majid  <omajid@redhat.com>

	* testsuite/binutils-all/objdump.exp
	(test_objdump_dotnet_assemblies): Fix test to distinguish errors
	in parsing simple pei-i386 and pei-x86-64 vs parsing the newly
	introduced machine types.
	* testsuite/gentestdlls.c (write_simple_dll): New function.
	(main): Generate simple and Linux-specific variants of pei-i386
	and pei-x86-64 files so both can be used by tests.
Omair

--
PGP Key: B157A9F0 (http://pgp.mit.edu/)
Fingerprint = 9DB5 2F0B FD3E C239 E108  E7BD DF99 7AF8 B157 A9F0


===File
/home/omajid/devel/binutils-gdb/0001-Make-objdump-PEI-tests-a-little-more-robust-portable.patch===
>From 1070dacd022500d2dcb72b7d60f13921600d3b6b Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Thu, 25 Jul 2019 18:31:53 -0400
Subject: [PATCH] Make objdump PEI tests a little more robust/portable

---
 binutils/testsuite/binutils-all/objdump.exp | 25 ++++--
 binutils/testsuite/gentestdlls.c            | 91 +++++++++++++--------
 2 files changed, 74 insertions(+), 42 deletions(-)

diff --git a/binutils/testsuite/binutils-all/objdump.exp b/binutils/testsuite/binutils-all/objdump.exp
index b46fd0a8bb..1b65486479 100644
--- a/binutils/testsuite/binutils-all/objdump.exp
+++ b/binutils/testsuite/binutils-all/objdump.exp
@@ -740,15 +740,16 @@ proc test_objdump_dotnet_assemblies {} {

     set test "dotnet-assemblies"

-    set got [binutils_run "$base_dir/testsuite/gentestdlls" "tmpdir"]
-    set want "wrote dotnet-linux-x86-64.dll"
+    set got [binutils_run "$base_dir/testsuite/gentestdlls" "tmpdir pei-i386 pei-x86-64"]
+    set want "wrote linux-pei-x86-64.dll"
+    # The test program is hardcoded to generate valid dlls on any target
     if ![regexp $want $got] then {
-	unsupported "$test"
+        fail "$test"
     }

     set test "dotnet-assemblies (32-bit)"
     set want "file format pei-i386"
-    set got [binutils_run $OBJDUMP "-x tmpdir/simple-i386.dll"]
+    set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-i386.dll"]
     if ![regexp $want $got] then {
 	if [regexp "file format not recognized" $got] then {
 	    unsupported $test
@@ -756,12 +757,17 @@ proc test_objdump_dotnet_assemblies {} {
 	    fail "$test"
 	}
     } else {
-	pass $test
+        set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-i386.dll"]
+        if ![regexp $want $got] then {
+            fail "$test"
+        } else {
+            pass $test
+        }
     }

     set test "dotnet-assemblies (64-bit)"
     set want "file format pei-x86-64"
-    set got [binutils_run $OBJDUMP "-x tmpdir/dotnet-linux-x86-64.dll"]
+    set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-x86-64.dll"]
     if ![regexp $want $got] then {
 	if [regexp "file format not recognized" $got] then {
 	    unsupported $test
@@ -769,7 +775,12 @@ proc test_objdump_dotnet_assemblies {} {
 	    fail "$test"
 	}
     } else {
-	pass $test
+        set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-x86-64.dll"]
+        if ![regexp $want $got] then {
+            fail "$test"
+        } else {
+            pass $test
+        }
     }
 }

diff --git a/binutils/testsuite/gentestdlls.c b/binutils/testsuite/gentestdlls.c
index b1463c0178..bebe831e92 100644
--- a/binutils/testsuite/gentestdlls.c
+++ b/binutils/testsuite/gentestdlls.c
@@ -29,8 +29,12 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>

+#define INCORRECT_USAGE 2
+#define IO_ERROR 3
+
 static void
 write_dos_header_and_stub (FILE* file)
 {
@@ -100,53 +104,70 @@ write_coff_header (FILE* file, uint16_t machine)
   memset (buffer, 0 , sizeof (buffer));
 }

-int
-main (int argc, char** argv)
+static void
+write_simple_dll(const char* name, uint16_t machine)
 {
-  FILE* file;
-
-  if (argc < 2)
-    {
-      fprintf (stderr, "usage: %s output-directory\n", argv[0]);
-      exit (2);
-    }
-  if (chdir (argv[1]) != 0)
-    {
-      fprintf (stderr, "error: unable to change directory to %s\n", argv[0]);
-      exit (2);
-    }
-
-  /* Generate a simple DLL file.  */
-  file = fopen ("simple-i386.dll", "w");
+  FILE* file = fopen (name, "w");
   if (file == NULL)
     {
       fprintf (stderr, "error: unable to open file for writing\n");
-      exit (1);
+      exit (IO_ERROR);
     }

   write_dos_header_and_stub (file);
   write_pe_signature (file);
-  write_coff_header (file, 0x14c);
+  write_coff_header (file, machine);
   fclose (file);
-  printf ("wrote simple-i386.dll\n");
-
-  /* Generate a sample .NET Core on Linux dll file.  As opposed to the
-     more common DLLs that contain bytecode (CIL/MSIL), many .NET Core
-     DLLs are pre-compiled for specific architectures and platforms.
-     See https://github.com/jbevain/cecil/issues/337 for an example of
-     this value being used in practice.  */
-  file = fopen ("dotnet-linux-x86-64.dll", "w");
-  if (file == NULL)
+  file = NULL;
+  printf ("wrote %s\n", name);
+}
+
+int
+main (int argc, char** argv)
+{
+  char* program_name = argv[0];
+  if (argc < 3)
     {
-      fprintf (stderr, "error: unable to open file for writing\n");
-      exit (1);
+      fprintf (stderr, "usage: %s output-directory format [format ...] \n\n", program_name);
+      fprintf (stderr, "format is an objdump-style format string, like pei-i386\n");
+      exit (INCORRECT_USAGE);
+    }
+  char* output_directory = argv[1];
+  if (chdir (output_directory) != 0)
+    {
+      fprintf (stderr, "error: unable to change directory to %s\n", output_directory);
+      exit (INCORRECT_USAGE);
     }

-  write_dos_header_and_stub (file);
-  write_pe_signature (file);
-  write_coff_header (file, 0xfd1d /* x86-64 + Linux */);
-  fclose (file);
-  printf ("wrote dotnet-linux-x86-64.dll\n");
+  /* We generate a simple PEI format files, and then .NET Core on
+     Linux-style PEI files for a number of architectures.  As opposed
+     to the more common PEI files that contain bytecode (CIL/MSIL), many
+     .NET Core DLLs are pre-compiled for specific architectures and
+     platforms.  See https://github.com/jbevain/cecil/issues/337 for an
+     example of this value being used in practice.  */
+
+  for (int i = 2; i < argc; i++)
+    {
+      char* wanted_format = argv[i];
+
+      if (strcmp ("pei-i386", wanted_format) == 0)
+        {
+          write_simple_dll ("simple-pei-i386.dll", 0x14c);
+
+          write_simple_dll ("linux-pei-i386.dll", 0x14c ^ 0x7b79 /* i386 + Linux */);
+        }
+      else if (strcmp ("pei-x86-64", wanted_format) == 0)
+        {
+          write_simple_dll ("simple-pei-x86-64.dll", 0x8664);
+
+          write_simple_dll ("linux-pei-x86-64.dll", 0x8664 ^ 0x7b79 /* x86-64 + Linux */);
+        }
+      else
+        {
+          fprintf (stderr, "error: can't handle format %s\n", wanted_format);
+          exit (INCORRECT_USAGE);
+        }
+    }

   return 0;
 }
--
2.21.0

============================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]