public inbox for gas2@sourceware.org
 help / color / mirror / Atom feed
* emulation on i386-coff, i386-elf patches
@ 1997-01-08 10:43 Robert Lipe
  1997-01-08 10:50 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Lipe @ 1997-01-08 10:43 UTC (permalink / raw)
  To: gas2

I have a need for an assembler that can switch between generating
i386-elf and i386-coff.   Since the gas doco hints that the emulation
stuff is desirable, but not fully implemented, I decided to take one
stab at it.   Once finished, this would surely be desirable in, say, 
Linux, where it's common to need to flip between the two targets.


The attached patches probably break non-bfd COFF targets and should not
be applied by anyone not willing to slog around in the code a little bit.

If someone that really understands BFD is willing to work with me a little
bit on this, I think it will be useful.

I did most of my testing on progressive-96q4 code.  I did apply the
stuff to the 1217 snaps on ftp.cygnus.com:/private/jelly.  All I had
to change was to add the frob_file_after_relocs vector into the middle
of the format_ops structure.   

I can switch between the two modes with --em=i386coff [ default ]and 
--em=i386elf.   I see that it does the right thing in switching around
the recognized pseudo ops and it generates .o's recognized correctly by
file.   The ELF .o of "hello, world" world even links and runs.

However, the COFF version has a problem that isn't obvious to me.  Here
is a disassembly of the same .s file generated with the native COFF 
assembler and with this assembler in COFF  mode.

$ dis x.o | tail
main
           0:  eb 0d                  jmp    0xd <f>
           2:  68 00 00 00 00         pushl  $0x0
           7:  e8 fc ff ff ff         call   0xfffffffc <8>
           c:  59                     popl   %ecx
           d:  c9                     leave
           e:  c3                     ret
           f:  55                     pushl  %ebp
          10:  8b ec                  movl   %esp,%ebp
          12:  eb ee                  jmp    0xee <2>
(robertl) pento:/home/robertl/tmp/c/x/gas
$ dis x.gas.o | tail
main
           0:  eb 0d                  jmp    0xd <f>
           2:  68 00 00 00 00         pushl  $0x0
           7:  e8 04 00 00 00         call   0x4 <10>
           c:  59                     popl   %ecx
           d:  c9                     leave
           e:  c3                     ret
           f:  55                     pushl  %ebp
          10:  89 e5                  movl   %esp,%ebp
          12:  eb ee                  jmp    0xee <2>


Clearly, the call to printf is very different, and it's distrubing
that one of them is -4 and the other one is 4.



Can anyone work with me on getting this stuff hammered into a usable
form?

Thanx,
RJL








--- gas/Makefile.in_	Mon Aug 19 17:26:40 1996
+++ gas/Makefile.in	Wed Jan  8 10:11:15 1997
@@ -390,11 +390,18 @@
 	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/obj-elf.c
 obj-ecoff.o : $(srcdir)/config/obj-ecoff.c
 	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/obj-ecoff.c
+obj-coff.o : $(srcdir)/config/obj-coff.c
+	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/obj-coff.c
+
 
 e-mipself.o : $(srcdir)/config/e-mipself.c
 	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/e-mipself.c
 e-mipsecoff.o : $(srcdir)/config/e-mipsecoff.c
 	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/e-mipsecoff.c
+e-i386coff.o : $(srcdir)/config/e-i386coff.c
+	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/e-i386coff.c
+e-i386elf.o : $(srcdir)/config/e-i386elf.c
+	$(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(srcdir)/config/e-i386elf.c
 
 # The m68k operand parser.
 
--- gas/as.c_	Mon Aug 19 12:28:38 1996
+++ gas/as.c	Wed Jan  8 00:01:12 1997
@@ -146,6 +146,7 @@
 
 extern struct emulation mipsbelf, mipslelf, mipself;
 extern struct emulation mipsbecoff, mipslecoff, mipsecoff;
+extern struct emulation i386coff, i386elf;
 
 static struct emulation *const emulations[] = { EMULATIONS };
 static const int n_emulations = sizeof (emulations) / sizeof (emulations[0]);
--- gas/configure_	Wed Sep 11 19:20:03 1996
+++ gas/configure	Wed Jan  8 10:02:57 1997
@@ -1029,6 +1029,7 @@
 			big)	emulation="mipsbelf mipslelf mipself" ;;
 			*)	emulation="mipslelf mipsbelf mipself" ;;
 			esac ;;
+      i386-*-*-elf)	emulation="i386coff i386elf" ;;
     esac
 
     emulations="$emulations $emulation"
@@ -1140,6 +1141,10 @@
 	fmt=elf   file=mipself ;;
     mipsbecoff | mipslecoff)
 	fmt=ecoff file=mipsecoff ;;
+    i386coff)
+	fmt=coff file=i386coff ;;
+    i386elf)
+	fmt=elf file=i386elf ;;
   esac
   formats="$formats $fmt"
   emfiles="$emfiles e-$file.o"
--- gas/obj.h_	Tue Jan  7 23:41:06 1997
+++ gas/obj.h	Tue Jan  7 23:44:09 1997
@@ -68,6 +68,7 @@
 
 extern const struct format_ops elf_format_ops;
 extern const struct format_ops ecoff_format_ops;
+extern const struct format_ops coff_format_ops;
 
 #ifndef this_format
 COMMON const struct format_ops *this_format;
--- /dev/null	Wed Jan  8 10:35:01 1997
+++ gas/config/e-i386elf.c	Wed Jan  8 10:19:46 1997
@@ -0,0 +1,18 @@
+#include "as.h"
+#include "emul.h"
+
+static const char *
+i386elf_bfd_name ()
+{
+  abort ();
+  return NULL;
+}
+
+#define emul_bfd_name	i386elf_bfd_name
+#define emul_format	&elf_format_ops
+
+#define emul_name	"i386elf"
+#define emul_struct_name i386elf
+#define emul_default_endian 0
+#include "emul-target.h"
+
--- /dev/null	Wed Jan  8 10:35:01 1997
+++ gas/config/e-i386coff.c	Wed Jan  8 10:19:31 1997
@@ -0,0 +1,18 @@
+#include "as.h"
+#include "emul.h"
+
+static const char *
+i386coff_bfd_name ()
+{
+  abort ();
+  return NULL;
+}
+
+#define emul_bfd_name	i386coff_bfd_name
+#define emul_format	&coff_format_ops
+
+#define emul_name	"i386coff"
+#define emul_struct_name i386coff
+#define emul_default_endian 0
+#include "emul-target.h"
+
--- gas/config/obj-coff.c_	Tue Jan  7 22:50:56 1997
+++ gas/config/obj-coff.c	Wed Jan  8 02:37:26 1997
@@ -18,7 +18,7 @@
    along with GAS; see the file COPYING.  If not, write to the Free
    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
-
+#define OBJ_HEADER "obj-coff.h"
 #include "as.h"
 #include "obstack.h"
 #include "subsegs.h"
@@ -328,7 +328,7 @@
 
 \f
 void
-obj_symbol_new_hook (symbolP)
+coff_obj_symbol_new_hook (symbolP)
      symbolS *symbolP;
 {
   char underscore = 0;		/* Symbol has leading _ */
@@ -869,7 +869,7 @@
 }
 
 void
-obj_read_begin_hook ()
+coff_obj_read_begin_hook ()
 {
   /* These had better be the same.  Usually 18 bytes. */
 #ifndef BFD_HEADERS
@@ -4215,6 +4215,7 @@
 #else
   {"optim", s_ignore, 0},	/* For sun386i cc (?) */
   {"ident", s_ignore, 0},	/* we don't yet handle this. */
+  {"version", s_ignore, 0},	/* we don't yet handle this. */
 #endif
   {"ABORT", s_abort, 0},
 #ifdef TC_M88K
@@ -4223,3 +4224,51 @@
 #endif
   {NULL}			/* end sentinel */
 };				/* obj_pseudo_table */
+
+void coff_pop_insert(void) 
+{
+	pop_insert(obj_pseudo_table) ;
+}
+
+static int 
+coff_sec_sym_ok_for_reloc (sec)
+     asection *sec;
+{
+	return (0);
+}
+
+void no_func(void)
+{
+	abort();
+}
+static int 
+null_func(void)
+{
+	return(0);
+}
+
+const struct format_ops coff_format_ops =
+{
+  bfd_target_coff_flavour,
+  0,
+  1,
+  coff_frob_symbol,
+  coff_frob_file,
+  no_func,
+  0, 0,
+  0, 0,
+  0,
+#if 0
+  obj_generate_asm_lineno,
+#else
+  no_func,
+#endif
+#if 0
+  obj_stab,
+#else
+  no_func,
+#endif
+  coff_sec_sym_ok_for_reloc,
+  coff_pop_insert,
+#if 0
+  obj_set_ext,
+#else
+  no_func,
+#endif
+  coff_obj_read_begin_hook,
+  coff_obj_symbol_new_hook,
+};
--- gas/config/tc-i386.c_	Wed Jan  8 00:57:03 1997
+++ gas/config/tc-i386.c	Wed Jan  8 01:15:08 1997
@@ -3001,6 +3001,19 @@
   return rel;
 }
 
+const char *
+i386_target_format()
+{
+	switch (OUTPUT_FLAVOR) {
+		case bfd_target_coff_flavour: 
+			return "coff-i386" ;
+		case bfd_target_elf_flavour:
+			return "elf32-i386" ;
+		default: 
+			abort() ;
+	}
+}
+
 #else /* ! BFD_ASSEMBLER */
 
 #if (defined(OBJ_AOUT) | defined(OBJ_BOUT))
--- gas/config/tc-i386.h_	Wed Jan  8 01:05:12 1997
+++ gas/config/tc-i386.h	Wed Jan  8 01:19:18 1997
@@ -82,6 +82,7 @@
 #ifdef OBJ_ELF
 #define TARGET_FORMAT		"elf32-i386"
 #endif
+#define TARGET_FORMAT		i386_target_format()
 
 #else /* ! BFD_ASSEMBLER */
 

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

* Re: emulation on i386-coff, i386-elf patches
  1997-01-08 10:43 emulation on i386-coff, i386-elf patches Robert Lipe
@ 1997-01-08 10:50 ` Ian Lance Taylor
  1997-01-08 12:07   ` Ken Raeburn
  1997-01-08 20:20   ` Robert Lipe
  0 siblings, 2 replies; 5+ messages in thread
From: Ian Lance Taylor @ 1997-01-08 10:50 UTC (permalink / raw)
  To: robertl; +Cc: gas2

   Date: Wed, 8 Jan 1997 12:00:26 -0600 (CST)
   From: Robert Lipe <robertl@dgii.com>

   However, the COFF version has a problem that isn't obvious to me.  Here
   is a disassembly of the same .s file generated with the native COFF=20
   assembler and with this assembler in COFF  mode.

It looks to me like you need to hack md_apply_fix3 in tc-i386.c.  In
general, anything that does an #ifdef OBJ_ELF or #ifdef OBJ_COFF will
have to be hacked.

In fact, I'm not certain that the BFD_ASSEMBLER version of the i386
COFF assembler works correctly.  You need to make sure that if you
configure with --target i386-coff --enable-bfd-assembler the resulting
code works.

By the way, for some reason your patch came in scrambled, with lots of
=20 strings scattered around.  I can never remember how to get rid of
those.

Ian


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

* Re: emulation on i386-coff, i386-elf patches
  1997-01-08 10:50 ` Ian Lance Taylor
@ 1997-01-08 12:07   ` Ken Raeburn
  1997-01-08 20:20   ` Robert Lipe
  1 sibling, 0 replies; 5+ messages in thread
From: Ken Raeburn @ 1997-01-08 12:07 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: robertl, gas2

Ian Lance Taylor <ian@cygnus.com> writes:

> It looks to me like you need to hack md_apply_fix3 in tc-i386.c.  In
> general, anything that does an #ifdef OBJ_ELF or #ifdef OBJ_COFF will
> have to be hacked.

You can check OUTPUT_FLAVOR at run time.  Accesses to flavour-specific
structure members and such can also be conditionalized at compile time
on OBJ_MAYBE_* macros like in the MIPS code.

> In fact, I'm not certain that the BFD_ASSEMBLER version of the i386
> COFF assembler works correctly.  You need to make sure that if you
> configure with --target i386-coff --enable-bfd-assembler the resulting
> code works.

That's the first thing to check....

> By the way, for some reason your patch came in scrambled, with lots of
> =20 strings scattered around.  I can never remember how to get rid of
> those.

In Gnus, turning on MIME processing gets rid of them for me.


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

* Re: emulation on i386-coff, i386-elf patches
  1997-01-08 10:50 ` Ian Lance Taylor
  1997-01-08 12:07   ` Ken Raeburn
@ 1997-01-08 20:20   ` Robert Lipe
  1997-01-09  9:06     ` Ian Lance Taylor
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Lipe @ 1997-01-08 20:20 UTC (permalink / raw)
  To: gas2

> It looks to me like you need to hack md_apply_fix3 in tc-i386.c.  In
> general, anything that does an #ifdef OBJ_ELF or #ifdef OBJ_COFF will
> have to be hacked.

Excellent catch, Ian.

Carving up tc-i386.c gave me exactly the results I needed.   The ELF
emulation mode of the assembler seems to be in excellent shape.  I just
watched the COFF side trip over itself, but the failure case needs trimmed
up considerably:

$ make CC='gcc ' CFLAGS=-g
gcc  -c -I. -I../../gas-961217/binutils -I../bfd -I../../gas-961217/binutils/../
bfd -I../../gas-961217/binutils/../include  -g ../../gas-961217/binutils/prdbg.c

gcc   -g  -o objdump objdump.o prdbg.o rddbg.o debug.o stabs.o ieee.o rdcoff.o -
L../bfd -lbfd -L../opcodes -lopcodes bucomm.o version.o filemode.o -L../bfd -lbf
d ../libiberty/libiberty.a
ld: line nbr entry (1125 0) found for non-relocatable symbol: section .text, fil
e prdbg.o

Note: this isn't GNU ld.

Rebuilding that specific file without -g makes it go away.   I'll pursue.


> In fact, I'm not certain that the BFD_ASSEMBLER version of the i386
> COFF assembler works correctly.  You need to make sure that if you
> configure with --target i386-coff --enable-bfd-assembler the resulting
> code works.

Building that stand-alone results in it being unable to resolve:
	obj_read_begin_hook                 read.o
	obj_symbol_new_hook                 symbols.o

I didn't pursue that aspect further.

Since you and Ken both sound doubtful of BFD_ASSEMBLER on i386 COFF, 
could you offer hints on suspected problem areas?   Sounds like I 
should take the time to get a 'make check' working.


Thanx, guys.

RJL


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

* Re: emulation on i386-coff, i386-elf patches
  1997-01-08 20:20   ` Robert Lipe
@ 1997-01-09  9:06     ` Ian Lance Taylor
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 1997-01-09  9:06 UTC (permalink / raw)
  To: robertl; +Cc: gas2

   Date: Wed, 8 Jan 1997 22:19:36 -0600 (CST)
   From: Robert Lipe <robertl@dgii.com>

   > In fact, I'm not certain that the BFD_ASSEMBLER version of the i386
   > COFF assembler works correctly.  You need to make sure that if you
   > configure with --target i386-coff --enable-bfd-assembler the resulting
   > code works.

   Building that stand-alone results in it being unable to resolve:
	   obj_read_begin_hook                 read.o
	   obj_symbol_new_hook                 symbols.o

   I didn't pursue that aspect further.

You can probably define both to be empty macros in tc-i386.h.

   Since you and Ken both sound doubtful of BFD_ASSEMBLER on i386 COFF, 
   could you offer hints on suspected problem areas?   Sounds like I 
   should take the time to get a 'make check' working.

Since you have access to an i386 COFF native system, the best check is
to run `make CC=gcc bootstrap' in the gas build directory.  That will
do a three stage of gas with itself.

The problem areas will be md_apply_fix and tc_gen_reloc.  You will
need to tweak them in apparently senseless fashion until they do the
right thing (you should be able to figure out what the right thing is
by looking at the object code generated by the non-BFD version).
Unfortunately, gas reloc handling is broken, and fixing it is hard.

Ian


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

end of thread, other threads:[~1997-01-09  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-08 10:43 emulation on i386-coff, i386-elf patches Robert Lipe
1997-01-08 10:50 ` Ian Lance Taylor
1997-01-08 12:07   ` Ken Raeburn
1997-01-08 20:20   ` Robert Lipe
1997-01-09  9:06     ` Ian Lance Taylor

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