This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] initial i386-nacl target support for gas
- From: Roland McGrath <mcgrathr at google dot com>
- To: binutils at sourceware dot org
- Cc: David Sehr <sehr at google dot com>
- Date: Fri, 20 Jan 2012 15:27:06 -0800
- Subject: [PATCH] initial i386-nacl target support for gas
This patch adds initial support for the i386-nacl target to gas. It's
already supported in BFD. This is not everything that's needed to be
actually useful for building Native Client binaries, but it's a start.
I cleaned up md_section_align to use "if (constant)" instead of #if for
its sometimes-used code. This is generally good practice that reduces
chances of bit rot in the code not used in many configurations, and it
also makes it easier and cleaner for a te-*.h file like mine to enable
this code.
Ok for trunk?
Thanks,
Roland
gas/
2012-01-20 Roland McGrath <mcgrathr@google.com>
* config/tc-i386.c (ALIGN_SECTION_P): New macro, define it if not
already defined by the te-*.h file.
(md_section_align): Use it.
* configure.tgt (i386-*-nacl*): Match it.
* config/te-nacl.h: New file.
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index dbac2ce..d9b70df 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -309,7 +309,8 @@ const char extra_symbol_chars[] = "*%-(["
|| ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
&& !defined (TE_GNU) \
&& !defined (TE_LINUX) \
- && !defined (TE_NETWARE) \
+ && !defined (TE_NACL) \
+ && !defined (TE_NETWARE) \
&& !defined (TE_FreeBSD) \
&& !defined (TE_DragonFly) \
&& !defined (TE_NetBSD)))
@@ -8880,25 +8881,32 @@ md_undefined_symbol (char *name)
return 0;
}
+/* If ALIGN_SECTION_P evaluates to nonzero, we'll explicit pad out
+ a section to its alignment, as if it had ended with a .align directive. */
+#ifndef ALIGN_SECTION_P
+# if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
+/* For a.out, force the section size to be aligned. If we don't do this,
+ BFD will align it for us, but it will not write out the final bytes of
+ the section. This may be a bug in BFD, but it is easier to fix it here
+ since that is how the other a.out targets work. */
+# define ALIGN_SECTION_P (OUTPUT_FLAVOR == bfd_target_aout_flavour)
+# else
+# define ALIGN_SECTION_P 0
+# endif
+#endif
+
/* Round up a section size to the appropriate boundary. */
valueT
-md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
+md_section_align (segT segment, valueT size)
{
-#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
- if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
+ if (ALIGN_SECTION_P)
{
- /* For a.out, force the section size to be aligned. If we don't do
- this, BFD will align it for us, but it will not write out the
- final bytes of the section. This may be a bug in BFD, but it is
- easier to fix it here since that is how the other a.out targets
- work. */
int align;
align = bfd_get_section_alignment (stdoutput, segment);
size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
}
-#endif
return size;
}
diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h
index 6a6b31d..688c69a 100644
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -1,6 +1,6 @@
/* tc-i386.h -- Header file for tc-i386.c
Copyright 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
@@ -61,6 +61,8 @@ extern unsigned long i386_mach (void);
#define ELF_TARGET_FORMAT64 "elf64-x86-64-freebsd"
#elif defined (TE_VXWORKS)
#define ELF_TARGET_FORMAT "elf32-i386-vxworks"
+#elif defined (TE_NACL)
+#define ELF_TARGET_FORMAT "elf32-i386-nacl"
#endif
#ifdef TE_SOLARIS
diff --git a/gas/config/te-nacl.h b/gas/config/te-nacl.h
new file mode 100644
index 0000000..17f3b5e
--- /dev/null
+++ b/gas/config/te-nacl.h
@@ -0,0 +1,29 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+ This file is part of GAS, the GNU Assembler.
+
+ GAS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ GAS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GAS; see the file COPYING. If not, write to the Free
+ Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#define TE_NACL
+#define LOCAL_LABELS_FB 1
+
+/* Align explicitly in the assembler so we always do it with nops.
+ Without this, we'd be relying on the linker to pad between input
+ sections. But it doesn't always pad executable sections with nops,
+ sometimes with zero, which NaCl cannot accept. */
+#define ALIGN_SECTION_P 1
+
+#include "obj-format.h"
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 7090682..c33bb7a 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -181,6 +181,7 @@ case ${generic_target} in
i386-*-elf) fmt=elf ;;
i386-*-kaos*) fmt=elf ;;
i386-*-bsd*) fmt=aout em=386bsd ;;
+ i386-*-nacl*) fmt=elf em=nacl ;;
i386-*-netbsd0.8) fmt=aout em=386bsd ;;
i386-*-netbsdpe*) fmt=coff em=pe ;;
i386-*-netbsd*-gnu* | \