public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][AArch64][gas] Set the minimum alignment on code segments.
@ 2015-03-05 11:30 Matthew Wahab
  2015-03-10 10:22 ` Nicholas Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Wahab @ 2015-03-05 11:30 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 882 bytes --]

On AArch64, gas doesn't set the minimum alignment for code segments 
making it possible for a segment to become misaligned during a link. It 
is also inconsistent with the ABI (4.3.5: Section Alignment).

This patch sets the minimum alignment for a section to 4 bytes, if the 
section contains an instruction.

A similar issue in the ARM backend has already been fixed 
(https://sourceware.org/bugzilla/show_bug.cgi?id=12931).

Tested aarch64-none-linux-gnu and aarch64-none-elf with check-gas, 
check-ld, check-binutils.

Ok for trunk?
Matthew

gas/
2015-03-05  Matthew Wahab  <matthew.wahab@arm.com>

	* config/tc-aarch64.c (mapping_state): Set minimum alignment for
	code sections.


gas/testsuite
2015-03-05  Matthew Wahab  <matthew.wahab@arm.com>

	* gas/aarch64/codealign.d: Add test for code section alignment.
	* gas/aarch64/codealign.s: New file.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: codealign.patch --]
[-- Type: text/x-patch; name=codealign.patch, Size: 1756 bytes --]

diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 9179fc6..77701c6 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -1478,7 +1478,14 @@ mapping_state (enum mstate state)
     /* The mapping symbol has already been emitted.
        There is nothing else to do.  */
     return;
-  else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
+
+  if (state == MAP_INSN)
+    /* AArch64 instructions require 4-byte alignment.  When emitting
+       instructions into any section, record the appropriate section
+       alignment.  */
+    record_alignment (now_seg, 2);
+
+  if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
     /* This case will be evaluated later in the next else.  */
     return;
   else if (TRANSITION (MAP_UNDEFINED, MAP_INSN))
diff --git a/gas/testsuite/gas/aarch64/codealign.d b/gas/testsuite/gas/aarch64/codealign.d
new file mode 100644
index 0000000..8e75c87
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/codealign.d
@@ -0,0 +1,16 @@
+#objdump: --section-headers 
+# Minimum code alignment should be set.
+# This test is only valid on ELF based ports.
+#not-target: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd *-*-riscix*
+
+.*: +file format.*aarch64.*
+
+Sections:
+Idx Name          Size      VMA               LMA               File off  Algn
+  0 \.text         .*  .*  .*  .*  2\*\*2
+                  .*CODE.*
+  1 \.data         .*  .*  .* .*  2\*\*0
+                  .*DATA.*
+  2 \.bss          .*  .*  .*  .*  2\*\*0
+.*
+
diff --git a/gas/testsuite/gas/aarch64/codealign.s b/gas/testsuite/gas/aarch64/codealign.s
new file mode 100644
index 0000000..b80a6d9
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/codealign.s
@@ -0,0 +1,2 @@
+.text
+  nop

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

* Re: [PATCH][AArch64][gas] Set the minimum alignment on code segments.
  2015-03-05 11:30 [PATCH][AArch64][gas] Set the minimum alignment on code segments Matthew Wahab
@ 2015-03-10 10:22 ` Nicholas Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nicholas Clifton @ 2015-03-10 10:22 UTC (permalink / raw)
  To: Matthew Wahab, binutils

Hi Matthew,

> gas/
> 2015-03-05  Matthew Wahab  <matthew.wahab@arm.com>
>
>      * config/tc-aarch64.c (mapping_state): Set minimum alignment for
>      code sections.
>
>
> gas/testsuite
> 2015-03-05  Matthew Wahab  <matthew.wahab@arm.com>
>
>      * gas/aarch64/codealign.d: Add test for code section alignment.
>      * gas/aarch64/codealign.s: New file.

Approved - please apply.

Cheers
   Nick

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

end of thread, other threads:[~2015-03-10 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 11:30 [PATCH][AArch64][gas] Set the minimum alignment on code segments Matthew Wahab
2015-03-10 10:22 ` Nicholas Clifton

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