This is the mail archive of the binutils@sources.redhat.com 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: More i386 architectures?


On Mon, Nov 12, 2001 at 06:01:03PM -0500, Elena Zannoni wrote:
> H . J . Lu writes:
>  > On Mon, Nov 12, 2001 at 10:43:14AM +1030, Alan Modra wrote:
>  > > On Sun, Nov 11, 2001 at 12:13:42PM +0000, Nick Clifton wrote:
>  > > > 
>  > > > > On a related matter, is there anything in an executable indicating
>  > > > > which architecture an i386 binary belongs?
>  > > > 
>  > > > Don't know,  Sorry.
>  > > 
>  > > There isn't, apart from examining the code, and we certainly don't want
>  > > to go down the mips path and start using flags in the ELF header for this
>  > > purpose.  If gdb needs the info, then it could be arranged for a special
>  > > note to be emitted.
>  > 
>  > FWIW, personally, I don't like the MIPS scheme at all. On the other
>  > hand, it may be just because we still don't support n32/n64 ABIs. We
>  > have to use all kinds of weird stuffs on MIPS.
> 
> 
> The SH uses e_flags pretty effectively for this purpose.  But if the
> ix86 ABI forbids using e_flags (the ppc ABI does this) we have little
> choice.

"The ELF header's e_flags member holds bit flags associated with the
file. The Intel386 architecture defines no flags; so this member
contains zero."

> Geoff is implementing the Dwarf3 extension for this, but I would like to
> see the note section as well, so that it works with stabs.

Here is a first pass at implementing an architecture note for x86, and
a bug-fix for obj-elf.c I noticed.  I'm checking in the bug-fix, but
waiting for comments on i386_elf_emit_arch_note. :)  The note will only
be emitted if an ".arch" directive is encountered in the source file,
and the last ".arch" directive wins.  Please ignore the other random
bug-fixes in tc-i386.c

gas/ChangeLog
	* config/tc-i386.h (md_end): Define.
	(i386_elf_emit_arch_note): Declare.
	(CpuUnknown): Delete.
	* config/tc-i386.c (default_arch): Constify.
	(smallest_imm_type): Remove CpuUnknown test.
	(md_assemble): Don't bother checking cpu_arch_flags non-zero.
	(i386_elf_emit_arch_note): New function.

	* config/obj-elf.c (obj_elf_version): Ensure terminating NUL is
	put in note section.  Use sizeof instead of hard-coded constants.

include/elf/ChangeLog
	* common.h (NT_ARCH): Define.  Remove incorrect comment.

-- 
Alan Modra

Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.43
diff -u -p -r1.43 obj-elf.c
--- obj-elf.c	2001/10/09 13:13:09	1.43
+++ obj-elf.c	2001/11/13 03:10:56
@@ -1417,14 +1417,13 @@ obj_elf_version (ignore)
 {
   char *name;
   unsigned int c;
-  char ch;
   char *p;
   asection *seg = now_seg;
   subsegT subseg = now_subseg;
   Elf_Internal_Note i_note;
   Elf_External_Note e_note;
   asection *note_secp = (asection *) NULL;
-  int i, len;
+  int len;
 
   SKIP_WHITESPACE ();
   if (*input_line_pointer == '\"')
@@ -1454,19 +1453,14 @@ obj_elf_version (ignore)
       i_note.descsz = 0;	/* no description */
       i_note.type = NT_VERSION;
       p = frag_more (sizeof (e_note.namesz));
-      md_number_to_chars (p, (valueT) i_note.namesz, 4);
+      md_number_to_chars (p, (valueT) i_note.namesz, sizeof (e_note.namesz));
       p = frag_more (sizeof (e_note.descsz));
-      md_number_to_chars (p, (valueT) i_note.descsz, 4);
+      md_number_to_chars (p, (valueT) i_note.descsz, sizeof (e_note.descsz));
       p = frag_more (sizeof (e_note.type));
-      md_number_to_chars (p, (valueT) i_note.type, 4);
+      md_number_to_chars (p, (valueT) i_note.type, sizeof (e_note.type));
+      p = frag_more (len + 1);
+      strcpy (p, name);
 
-      for (i = 0; i < len; i++)
-	{
-	  ch = *(name + i);
-	  {
-	    FRAG_APPEND_1_CHAR (ch);
-	  }
-	}
       frag_align (2, 0, 0);
 
       subseg_set (seg, subseg);
Index: gas/config/tc-i386.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i386.h,v
retrieving revision 1.27
diff -u -p -r1.27 tc-i386.h
--- tc-i386.h	2001/07/23 14:02:12	1.27
+++ tc-i386.h	2001/11/13 03:10:56
@@ -111,6 +111,11 @@ extern const char *i386_target_format PA
 #endif
 #endif
 
+#if (defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF))
+#define md_end i386_elf_emit_arch_note
+extern void i386_elf_emit_arch_note PARAMS ((void));
+#endif
+
 #else /* ! BFD_ASSEMBLER */
 
 /* COFF STUFF */
@@ -293,7 +298,6 @@ typedef struct
 #define CpuSSE	       0x1000	/* Streaming SIMD extensions required */
 #define CpuSSE2	       0x2000	/* Streaming SIMD extensions 2 required */
 #define Cpu3dnow       0x4000	/* 3dnow! support required */
-#define CpuUnknown     0x8000	/* The CPU is unknown,  be on the safe side.  */
 
   /* These flags are set by gas depending on the flag_code.  */
 #define Cpu64	     0x4000000   /* 64bit support required  */
Index: gas/config/tc-i386.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i386.c,v
retrieving revision 1.105
diff -u -p -r1.105 tc-i386.c
--- tc-i386.c	2001/10/04 18:01:46	1.105
+++ tc-i386.c	2001/11/13 03:11:01
@@ -77,7 +77,7 @@ static bfd_reloc_code_real_type reloc
 #ifndef DEFAULT_ARCH
 #define DEFAULT_ARCH "i386"
 #endif
-static char *default_arch = DEFAULT_ARCH;
+static const char *default_arch = DEFAULT_ARCH;
 
 /* 'md_assemble ()' gathers together information and puts it into a
    i386_insn.  */
@@ -539,8 +539,7 @@ static int
 smallest_imm_type (num)
      offsetT num;
 {
-  if (cpu_arch_flags != (Cpu086 | Cpu186 | Cpu286 | Cpu386 | Cpu486 | CpuNo64)
-      && !(cpu_arch_flags & (CpuUnknown)))
+  if (cpu_arch_flags != (Cpu086 | Cpu186 | Cpu286 | Cpu386 | Cpu486 | CpuNo64))
     {
       /* This code is disabled on the 486 because all the Imm1 forms
 	 in the opcode table are slower on the i486.  They're the
@@ -1393,19 +1392,16 @@ md_assemble (line)
       }
 
     /* Check if instruction is supported on specified architecture.  */
-    if (cpu_arch_flags != 0)
+    if ((current_templates->start->cpu_flags & ~(Cpu64 | CpuNo64))
+	& ~(cpu_arch_flags & ~(Cpu64 | CpuNo64)))
       {
-	if ((current_templates->start->cpu_flags & ~(Cpu64 | CpuNo64))
-	    & ~(cpu_arch_flags & ~(Cpu64 | CpuNo64)))
-	  {
-	    as_warn (_("`%s' is not supported on `%s'"),
-		     current_templates->start->name, cpu_arch_name);
-	  }
-	else if ((Cpu386 & ~cpu_arch_flags) && (flag_code != CODE_16BIT))
-	  {
-	    as_warn (_("use .code16 to ensure correct addressing mode"));
-	  }
+	as_warn (_("`%s' is not supported on `%s'"),
+		 current_templates->start->name, cpu_arch_name);
       }
+    else if ((Cpu386 & ~cpu_arch_flags) && (flag_code != CODE_16BIT))
+      {
+	as_warn (_("use .code16 to ensure correct addressing mode"));
+      }
 
     /* Check for rep/repne without a string instruction.  */
     if (expecting_string_instruction
@@ -4661,6 +4657,48 @@ i386_target_format ()
 }
 
 #endif /* OBJ_MAYBE_ more than one  */
+
+#if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))
+void i386_elf_emit_arch_note ()
+{
+  if (OUTPUT_FLAVOR == bfd_target_elf_flavour
+      && cpu_arch_name != NULL)
+    {
+      char *p;
+      asection *seg = now_seg;
+      subsegT subseg = now_subseg;
+      Elf_Internal_Note i_note;
+      Elf_External_Note e_note;
+      asection *note_secp;
+      int len;
+
+      /* Create the .note section.  */
+      note_secp = subseg_new (".note", 0);
+      bfd_set_section_flags (stdoutput,
+			     note_secp,
+			     SEC_HAS_CONTENTS | SEC_READONLY);
+
+      /* Process the arch string.  */
+      len = strlen (cpu_arch_name);
+
+      i_note.namesz = len + 1;
+      i_note.descsz = 0;
+      i_note.type = NT_ARCH;
+      p = frag_more (sizeof (e_note.namesz));
+      md_number_to_chars (p, (valueT) i_note.namesz, sizeof (e_note.namesz));
+      p = frag_more (sizeof (e_note.descsz));
+      md_number_to_chars (p, (valueT) i_note.descsz, sizeof (e_note.descsz));
+      p = frag_more (sizeof (e_note.type));
+      md_number_to_chars (p, (valueT) i_note.type, sizeof (e_note.type));
+      p = frag_more (len + 1);
+      strcpy (p, cpu_arch_name);
+
+      frag_align (2, 0, 0);
+
+      subseg_set (seg, subseg);
+    }
+}
+#endif
 #endif /* BFD_ASSEMBLER  */
 
 symbolS *
Index: include/elf/common.h
===================================================================
RCS file: /cvs/src/src/include/elf/common.h,v
retrieving revision 1.34
diff -u -p -r1.34 common.h
--- common.h	2001/09/13 21:02:21	1.34
+++ common.h	2001/11/13 03:11:02
@@ -339,9 +339,9 @@ Foundation, Inc., 59 Temple Place - Suit
 #define NT_WIN32PSTATUS	18		/* Has a struct win32_pstatus */
 
 /* Values of note segment descriptor types for object files.  */
-/* (Only for hppa right now.  Should this be moved elsewhere?)  */
 
 #define NT_VERSION	1		/* Contains a version string.  */
+#define NT_ARCH		2		/* Contains an architecture string.  */
 
 /* These three macros disassemble and assemble a symbol table st_info field,
    which contains the symbol binding and symbol type.  The STB_ and STT_


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