From feaa0af17a4d4e1a87c7de1d53a72fe19e708286 Mon Sep 17 00:00:00 2001
From: Evgeny Eltsin <eaeltsin@google.com>
Date: Tue, 21 Dec 2010 21:06:19 +0300
Subject: [PATCH 63/63] [binutils] Force assembler to align code section size

Assembler pads code sections with NOPs, which is exactly what we need for NaCl.

This change introduces NOP padding at the end of the code section. Whitout this change, linker may add zero padding to code sections, which does not validate.

BUG=http://code.google.com/p/nativeclient/issues/detail?id=499
TEST=code sections in object files should be padded with NOPs at the end when needed

Review URL: http://codereview.chromium.org/6001005
---
 binutils/gas/config/tc-i386.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/binutils/gas/config/tc-i386.c b/binutils/gas/config/tc-i386.c
index 6cc6b72..2140582 100644
--- a/binutils/gas/config/tc-i386.c
+++ b/binutils/gas/config/tc-i386.c
@@ -8716,6 +8716,25 @@ md_undefined_symbol (name)
 
 /* Round up a section size to the appropriate boundary.  */
 
+#ifdef TC_NACL_C
+valueT
+md_section_align (segment, size)
+     segT segment;
+     valueT size;
+{
+  if (bfd_get_section_flags (stdoutput, segment) & SEC_CODE)
+    {
+      /* For NaCl, force the code section size to be aligned. This implies
+	 padding with NOPs that is required for validation.  */
+      int align;
+
+      align = bfd_get_section_alignment (stdoutput, segment);
+      size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
+    }
+
+  return size;
+}
+#else
 valueT
 md_section_align (segment, size)
      segT segment ATTRIBUTE_UNUSED;
@@ -8738,6 +8757,7 @@ md_section_align (segment, size)
 
   return size;
 }
+#endif
 
 /* On the i386, PC-relative offsets are relative to the start of the
    next instruction.  That is, the address of the offset, plus its
-- 
1.7.3.1


Update binutils patches from git.
Update binutils patches from git.

Review URL: http://codereview.chromium.org/6001005/

Review URL: http://codereview.chromium.org/6037008

git-svn-id: 721b910a23eff8a86f00c8fd261a7587cddf18f8@4024 fcba33aa-ac0c-11dd-b9e7-8d5594d729c2
