This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Thumb code alignment padding
- From: Paul Brook <paul at codesourcery dot com>
- To: binutils at sourceware dot org
- Date: Wed, 6 Jun 2007 18:36:46 +0100
- Subject: Thumb code alignment padding
On ARM targets the .align directive pads with zeros, unlike .p2align which
pads code sections with NOP instructions.
In arm mode we get away with this because zero happens to be a nop
instruction. In Thumb mode it's interpreted as lsls, which clobbers the
flags.
The patch below fixes it to use nops for padding in code sections.
Tested on arm-none-eabi.
Applied to CVS head.
Paul
2007-06-06 Paul Brook <paul@codesourcery.com>
gas/
* config/tc-arm.c (s_align): Pad code sections appropriately.
gas/testsuite/
* gas/arm/thumb.d: Update expected output.
* gas/arm/thumb2_relax.d: Ditto.
Index: gas/config/tc-arm.c
===================================================================
RCS file: /var/cvsroot/src-cvs/src/gas/config/tc-arm.c,v
retrieving revision 1.329
diff -u -p -r1.329 tc-arm.c
--- gas/config/tc-arm.c 5 Jun 2007 22:02:46 -0000 1.329
+++ gas/config/tc-arm.c 6 Jun 2007 16:21:05 -0000
@@ -2613,6 +2613,7 @@ static void
s_align (int unused ATTRIBUTE_UNUSED)
{
int temp;
+ bfd_boolean fill_p;
long temp_fill;
long max_alignment = 15;
@@ -2629,16 +2630,25 @@ s_align (int unused ATTRIBUTE_UNUSED)
{
input_line_pointer++;
temp_fill = get_absolute_expression ();
+ fill_p = TRUE;
}
else
- temp_fill = 0;
+ {
+ fill_p = FALSE;
+ temp_fill = 0;
+ }
if (!temp)
temp = 2;
/* Only make a frag if we HAVE to. */
if (temp && !need_pass_2)
- frag_align (temp, (int) temp_fill, 0);
+ {
+ if (!fill_p && subseg_text_p (now_seg))
+ frag_align_code (temp, 0);
+ else
+ frag_align (temp, (int) temp_fill, 0);
+ }
demand_empty_rest_of_line ();
record_alignment (now_seg, temp);
Index: gas/testsuite/gas/arm/thumb.d
===================================================================
RCS file: /var/cvsroot/src-cvs/src/gas/testsuite/gas/arm/thumb.d,v
retrieving revision 1.9
diff -u -p -r1.9 thumb.d
--- gas/testsuite/gas/arm/thumb.d 21 Apr 2007 19:45:05 -0000 1.9
+++ gas/testsuite/gas/arm/thumb.d 6 Jun 2007 16:29:26 -0000
@@ -50,7 +50,7 @@ Disassembly of section \.text:
0+050 <[^>]+> 46c0 nop \(mov r8, r8\)
0+052 <[^>]+> 4738 bx r7
0+054 <[^>]+> 4740 bx r8
-0+056 <[^>]+> 0000 lsls r0, r0, #0
+0+056 <[^>]+> 46c0 nop \(mov r8, r8\)
0+058 <[^>]+> 4778 bx pc
0+05a <[^>]+> 4b20 ldr r3, \[pc, #128\] \(0+0dc <[^>]+>\)
0+05c <[^>]+> 4c02 ldr r4, \[pc, #8\] \(0+068 <[^>]+>\)
@@ -58,7 +58,7 @@ Disassembly of section \.text:
0+060 <[^>]+> 5511 strb r1, \[r2, r4\]
0+062 <[^>]+> 59f5 ldr r5, \[r6, r7\]
0+064 <[^>]+> 5d62 ldrb r2, \[r4, r5\]
- \.\.\.
+0+066 <[^>]+> 46c0 nop \(mov r8, r8\)
0+068 <[^>]+> 52d1 strh r1, \[r2, r3\]
0+06a <[^>]+> 5a23 ldrh r3, \[r4, r0\]
0+06c <[^>]+> 57f1 ldrsb r1, \[r6, r7\]
@@ -134,7 +134,7 @@ Disassembly of section \.text:
0+106 <[^>]+> f000 f815 bl 0+134 <[^>]+>
0+10a <[^>]+> 4700 bx r0
0+10c <[^>]+> dfff (swi|svc) 255
- \.\.\.
+0+10e <[^>]+> 46c0 nop \(mov r8, r8\)
0+110 <[^>]+> d010 beq.n 0+134 <[^>]+>
0+112 <[^>]+> d10f bne.n 0+134 <[^>]+>
0+114 <[^>]+> d20e bcs.n 0+134 <[^>]+>
Index: gas/testsuite/gas/arm/thumb2_relax.d
===================================================================
RCS file: /var/cvsroot/src-cvs/src/gas/testsuite/gas/arm/thumb2_relax.d,v
retrieving revision 1.2
diff -u -p -r1.2 thumb2_relax.d
--- gas/testsuite/gas/arm/thumb2_relax.d 21 Apr 2007 19:45:05 -0000 1.2
+++ gas/testsuite/gas/arm/thumb2_relax.d 6 Jun 2007 16:32:07 -0000
@@ -20,7 +20,7 @@ Disassembly of section .text:
0+02e <[^>]+> f89f 800c ldrb.w r8, \[pc, #12\] ; 0+03c <[^>]+>
0+032 <[^>]+> f89f 100a ldrb.w r1, \[pc, #10\] ; 0+03e <[^>]+>
0+036 <[^>]+> f81f 1038 ldrb.w r1, \[pc, #-56\] ; 0+000 <[^>]+>
-0+03a <[^>]+> 0000 lsls r0, r0, #0
+0+03a <[^>]+> 46c0 nop \(mov r8, r8\)
0+03c <[^>]+> bf00 nop
0+03e <[^>]+> f995 1000 ldrsb.w r1, \[r5\]
0+042 <[^>]+> f995 1023 ldrsb.w r1, \[r5, #35\]
@@ -89,7 +89,7 @@ Disassembly of section .text:
0+126 <[^>]+> f8df 800c ldr.w r8, \[pc, #12\] ; 0+134 <[^>]+>
0+12a <[^>]+> f8df 100a ldr.w r1, \[pc, #10\] ; 0+136 <[^>]+>
0+12e <[^>]+> f85f 1036 ldr.w r1, \[pc, #-54\] ; 0+0fa <[^>]+>
-0+132 <[^>]+> 0000 lsls r0, r0, #0
+0+132 <[^>]+> 46c0 nop \(mov r8, r8\)
0+134 <[^>]+> bf00 nop
0+136 <[^>]+> 7029 strb r1, \[r5, #0\]
0+138 <[^>]+> f885 1023 strb.w r1, \[r5, #35\]