Skip to contentSkip to conversation

recordmcount: arm: Implement make_nop

PATCH/RESEND Stephen Boyd 4 participants 12 messages Oct 18, 2016 – Nov 16, 2016

lore
Share & tools
lore
#0 lore raw

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

---
 scripts/recordmcount.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
scripts/recordmcount.c +65 -0
index 5423a58d1b06..aeb34223167c 100644
@@ -213,6 +213,59 @@ static int make_nop_x86(void *map, size_t const offset)
 	return 0;
 }
 
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */
+static unsigned char *ideal_nop4_arm;
+
+static unsigned char bl_mcount_arm_le[4] = { 0xfe, 0xff, 0xff, 0xeb }; /* bl */
+static unsigned char bl_mcount_arm_be[4] = { 0xeb, 0xff, 0xff, 0xfe }; /* bl */
+static unsigned char *bl_mcount_arm;
+
+static unsigned char push_arm_le[4] = { 0x04, 0xe0, 0x2d, 0xe5 }; /* push {lr} */
+static unsigned char push_arm_be[4] = { 0xe5, 0x2d, 0xe0, 0x04 }; /* push {lr} */
+static unsigned char *push_arm;
+
+static unsigned char ideal_nop2_thumb_le[2] = { 0x00, 0xbf }; /* nop */
+static unsigned char ideal_nop2_thumb_be[2] = { 0xbf, 0x00 }; /* nop */
+static unsigned char *ideal_nop2_thumb;
+
+static unsigned char push_bl_mcount_thumb_le[6] = { 0x00, 0xb5, 0xff, 0xf7, 0xfe, 0xff }; /* push {lr}, bl */
+static unsigned char push_bl_mcount_thumb_be[6] = { 0xb5, 0x00, 0xf7, 0xff, 0xff, 0xfe }; /* push {lr}, bl */
+static unsigned char *push_bl_mcount_thumb;
+
+static int make_nop_arm(void *map, size_t const offset)
+{
+	char *ptr;
+	int cnt = 1;
+	int nop_size;
+	size_t off = offset;
+
+	ptr = map + offset;
+	if (memcmp(ptr, bl_mcount_arm, 4) == 0) {
+		if (memcmp(ptr - 4, push_arm, 4) == 0) {
+			off -= 4;
+			cnt = 2;
+		}
+		ideal_nop = ideal_nop4_arm;
+		nop_size = 4;
+	} else if (memcmp(ptr - 2, push_bl_mcount_thumb, 6) == 0) {
+		cnt = 3;
+		nop_size = 2;
+		off -= 2;
+		ideal_nop = ideal_nop2_thumb;
+	} else
+		return -1;
+
+	/* Convert to nop */
+	ulseek(fd_map, off, SEEK_SET);
+
+	do {
+		uwrite(fd_map, ideal_nop, nop_size);
+	} while (--cnt > 0);
+
+	return 0;
+}
+
 static unsigned char ideal_nop4_arm64[4] = {0x1f, 0x20, 0x03, 0xd5};
 static int make_nop_arm64(void *map, size_t const offset)
 {
@@ -430,6 +483,11 @@ do_file(char const *const fname)
 			w2 = w2rev;
 			w8 = w8rev;
 		}
+		ideal_nop4_arm = ideal_nop4_arm_le;
+		bl_mcount_arm = bl_mcount_arm_le;
+		push_arm = push_arm_le;
+		ideal_nop2_thumb = ideal_nop2_thumb_le;
+		push_bl_mcount_thumb = push_bl_mcount_thumb_le;
 		break;
 	case ELFDATA2MSB:
 		if (*(unsigned char const *)&endian != 0) {
@@ -438,6 +496,11 @@ do_file(char const *const fname)
 			w2 = w2rev;
 			w8 = w8rev;
 		}
+		ideal_nop4_arm = ideal_nop4_arm_be;
+		bl_mcount_arm = bl_mcount_arm_be;
+		push_arm = push_arm_be;
+		ideal_nop2_thumb = ideal_nop2_thumb_be;
+		push_bl_mcount_thumb = push_bl_mcount_thumb_be;
 		break;
 	}  /* end switch */
 	if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0
@@ -463,6 +526,8 @@ do_file(char const *const fname)
 		break;
 	case EM_ARM:	 reltype = R_ARM_ABS32;
 			 altmcount = "__gnu_mcount_nc";
+			 make_nop = make_nop_arm;
+			 rel_type_nop = R_ARM_NONE;
 			 break;
 	case EM_AARCH64:
 			reltype = R_AARCH64_ABS64;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
Quoted 7 lines · On Tue, 18 Oct 2016 20:07:07 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines · On Tue, 18 Oct 2016 16:42:00 -0700 Stephen Boyd <[email protected]> wrote:

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

Quoted 5 lines
Quoted 3 lines

I can take this if I can get an ack from the ARM maintainers.

Any ARM maintainer want to ack this, or take it in their tree if they haven't already?

-- Steve

Acked-by Russell King
#3 lore raw
Quoted 10 lines · Steven Rostedt
Quoted 7 lines · On Tue, 18 Oct 2016 20:07:07 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines · On Tue, 18 Oct 2016 16:42:00 -0700 Stephen Boyd <[email protected]> wrote:

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I can take this if I can get an ack from the ARM maintainers.

Any ARM maintainer want to ack this, or take it in their tree if they haven't already?

Assuming it's been tested:

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#4 lore raw
In reply to Stephen Boyd
Quoted 16 lines · Stephen Boyd

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

---
 scripts/recordmcount.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
scripts/recordmcount.c +0 -0
index 5423a58d1b06..aeb34223167c 100644

scripts/recordmcount.c static int make_nop_x86(void *map, size_t const offset) · line 217

Quoted 5 lines
scripts/recordmcount.c +2 -0
@@ -213,6 +213,59 @@ static int make_nop_x86(void *map, size_t const offset)
        return 0;
 }
 
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */

Shouldn't you be taking the difference between BE8 and BE32 into account here? IIRC, BE8 uses little endian encoding for instructions.

Quoted 96 lines
scripts/recordmcount.c +63 -1
+static unsigned char *ideal_nop4_arm;
+
+static unsigned char bl_mcount_arm_le[4] = { 0xfe, 0xff, 0xff, 0xeb }; /* bl */
+static unsigned char bl_mcount_arm_be[4] = { 0xeb, 0xff, 0xff, 0xfe }; /* bl */
+static unsigned char *bl_mcount_arm;
+
+static unsigned char push_arm_le[4] = { 0x04, 0xe0, 0x2d, 0xe5 }; /* push {lr} */
+static unsigned char push_arm_be[4] = { 0xe5, 0x2d, 0xe0, 0x04 }; /* push {lr} */
+static unsigned char *push_arm;
+
+static unsigned char ideal_nop2_thumb_le[2] = { 0x00, 0xbf }; /* nop */
+static unsigned char ideal_nop2_thumb_be[2] = { 0xbf, 0x00 }; /* nop */
+static unsigned char *ideal_nop2_thumb;
+
+static unsigned char push_bl_mcount_thumb_le[6] = { 0x00, 0xb5, 0xff, 0xf7, 0xfe, 0xff }; /* push {lr}, bl */
+static unsigned char push_bl_mcount_thumb_be[6] = { 0xb5, 0x00, 0xf7, 0xff, 0xff, 0xfe }; /* push {lr}, bl */
+static unsigned char *push_bl_mcount_thumb;
+
+static int make_nop_arm(void *map, size_t const offset)
+{
+       char *ptr;
+       int cnt = 1;
+       int nop_size;
+       size_t off = offset;
+
+       ptr = map + offset;
+       if (memcmp(ptr, bl_mcount_arm, 4) == 0) {
+               if (memcmp(ptr - 4, push_arm, 4) == 0) {
+                       off -= 4;
+                       cnt = 2;
+               }
+               ideal_nop = ideal_nop4_arm;
+               nop_size = 4;
+       } else if (memcmp(ptr - 2, push_bl_mcount_thumb, 6) == 0) {
+               cnt = 3;
+               nop_size = 2;
+               off -= 2;
+               ideal_nop = ideal_nop2_thumb;
+       } else
+               return -1;
+
+       /* Convert to nop */
+       ulseek(fd_map, off, SEEK_SET);
+
+       do {
+               uwrite(fd_map, ideal_nop, nop_size);
+       } while (--cnt > 0);
+
+       return 0;
+}
+
 static unsigned char ideal_nop4_arm64[4] = {0x1f, 0x20, 0x03, 0xd5};
 static int make_nop_arm64(void *map, size_t const offset)
 {
@@ -430,6 +483,11 @@ do_file(char const *const fname)
                        w2 = w2rev;
                        w8 = w8rev;
                }
+               ideal_nop4_arm = ideal_nop4_arm_le;
+               bl_mcount_arm = bl_mcount_arm_le;
+               push_arm = push_arm_le;
+               ideal_nop2_thumb = ideal_nop2_thumb_le;
+               push_bl_mcount_thumb = push_bl_mcount_thumb_le;
                break;
        case ELFDATA2MSB:
                if (*(unsigned char const *)&endian != 0) {
@@ -438,6 +496,11 @@ do_file(char const *const fname)
                        w2 = w2rev;
                        w8 = w8rev;
                }
+               ideal_nop4_arm = ideal_nop4_arm_be;
+               bl_mcount_arm = bl_mcount_arm_be;
+               push_arm = push_arm_be;
+               ideal_nop2_thumb = ideal_nop2_thumb_be;
+               push_bl_mcount_thumb = push_bl_mcount_thumb_be;
                break;
        }  /* end switch */
        if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0
@@ -463,6 +526,8 @@ do_file(char const *const fname)
                break;
        case EM_ARM:     reltype = R_ARM_ABS32;
                         altmcount = "__gnu_mcount_nc";
+                        make_nop = make_nop_arm;
+                        rel_type_nop = R_ARM_NONE;
                         break;
        case EM_AARCH64:
                        reltype = R_AARCH64_ABS64;
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw
Quoted 20 lines · On Tue, 15 Nov 2016 14:19:44 +0000 Ard Biesheuvel <[email protected]>…
Quoted 19 lines · Stephen Boyd

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

---
 scripts/recordmcount.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
scripts/recordmcount.c +0 -0
index 5423a58d1b06..aeb34223167c 100644
@@ -213,6 +213,59 @@ static int make_nop_x86(void *map, size_t const offset)
        return 0;
 }
 
Quoted 6 lines

scripts/recordmcount.c static int make_nop_x86(void *map, size_t const offset) · line 217

Quoted 2 lines
scripts/recordmcount.c +2 -0
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */  

Shouldn't you be taking the difference between BE8 and BE32 into account here? IIRC, BE8 uses little endian encoding for instructions.

I was just about to push this to linux-next (where I don't rebase). I'm guessing I should hold off then.

Luckily, this was the last patch of my tree that I tested, and I can just remove that one.

-- Steve

#6 lore raw
In reply to Ard Biesheuvel
Quoted 20 lines · Ard Biesheuvel
Quoted 19 lines · Stephen Boyd

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

---
 scripts/recordmcount.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
scripts/recordmcount.c +0 -0
index 5423a58d1b06..aeb34223167c 100644
@@ -213,6 +213,59 @@ static int make_nop_x86(void *map, size_t const offset)
        return 0;
 }
 
Quoted 5 lines

scripts/recordmcount.c static int make_nop_x86(void *map, size_t const offset) · line 217

Quoted 2 lines
scripts/recordmcount.c +2 -0
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */

Shouldn't you be taking the difference between BE8 and BE32 into account here? IIRC, BE8 uses little endian encoding for instructions.

I admit I haven't tested on a pre-armv6 CPU so I haven't come across the case of a BE32 CPU. But from what I can tell that doesn't matter.

According to scripts/Makefile.build, cmd_record_mcount only runs the recordmcount program if CONFIG_FTRACE_MCOUNT_RECORD=y. That config is defined as:

config FTRACE_MCOUNT_RECORD
def_bool y
depends on DYNAMIC_FTRACE depends on HAVE_FTRACE_MCOUNT_RECORD

And in arch/arm/Kconfig we see that DYNAMIC_FTRACE is selected:

	select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU

which means that FTRACE_MCOUNT_RECORD can't be set when CPU_ENDIAN_BE32 is set.

Do you agree that BE32 is not a concern here?

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw
Quoted 41 lines · Stephen Boyd
Quoted 20 lines · Ard Biesheuvel
Quoted 19 lines · Stephen Boyd

In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a nop in sections that aren't traced.

---
 scripts/recordmcount.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
scripts/recordmcount.c +0 -0
index 5423a58d1b06..aeb34223167c 100644
@@ -213,6 +213,59 @@ static int make_nop_x86(void *map, size_t const offset)
        return 0;
 }
 
Quoted 5 lines

scripts/recordmcount.c static int make_nop_x86(void *map, size_t const offset) · line 217

Quoted 2 lines
scripts/recordmcount.c +2 -0
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */

Shouldn't you be taking the difference between BE8 and BE32 into account here? IIRC, BE8 uses little endian encoding for instructions.

I admit I haven't tested on a pre-armv6 CPU so I haven't come across the case of a BE32 CPU. But from what I can tell that doesn't matter.

According to scripts/Makefile.build, cmd_record_mcount only runs the recordmcount program if CONFIG_FTRACE_MCOUNT_RECORD=y. That config is defined as:

config FTRACE_MCOUNT_RECORD
def_bool y
depends on DYNAMIC_FTRACE depends on HAVE_FTRACE_MCOUNT_RECORD

Quoted 9 lines

And in arch/arm/Kconfig we see that DYNAMIC_FTRACE is selected:

        select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU

which means that FTRACE_MCOUNT_RECORD can't be set when CPU_ENDIAN_BE32 is set.

Do you agree that BE32 is not a concern here?

Yes. But that implies then that you should not be using big-endian instruction encodings at all, and simply use the _le variants for both LE and BE8

#8 lore raw
Quoted 31 lines · Ard Biesheuvel
Quoted 30 lines · Stephen Boyd
Quoted 7 lines · Ard Biesheuvel

scripts/recordmcount.c static int make_nop_x86(void *map, size_t const offset) · line 217

Quoted 3 lines · Stephen Boyd
scripts/recordmcount.c +2 -0
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */

Shouldn't you be taking the difference between BE8 and BE32 into account here? IIRC, BE8 uses little endian encoding for instructions.

I admit I haven't tested on a pre-armv6 CPU so I haven't come across the case of a BE32 CPU. But from what I can tell that doesn't matter.

According to scripts/Makefile.build, cmd_record_mcount only runs the recordmcount program if CONFIG_FTRACE_MCOUNT_RECORD=y. That config is defined as:

config FTRACE_MCOUNT_RECORD
def_bool y
depends on DYNAMIC_FTRACE depends on HAVE_FTRACE_MCOUNT_RECORD

And in arch/arm/Kconfig we see that DYNAMIC_FTRACE is selected:

        select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU

which means that FTRACE_MCOUNT_RECORD can't be set when CPU_ENDIAN_BE32 is set.

Quoted 6 lines
Quoted 2 lines

Do you agree that BE32 is not a concern here?

Yes. But that implies then that you should not be using big-endian instruction encodings at all, and simply use the _le variants for both LE and BE8

Ok. I understand what you're getting at now.

I believe the linker is the one that does the instruction endian swap to little endian. So everything is built as big-endian data and instructions in the assembler phase and then when the linker runs to generate the final vmlinux elf file it does the swaps to make instructions little endian. recordmcount runs on the object files and not the vmlinux file.

For example, the do_undefinstr() function in arch/arm/kernel/traps.c is one place we nop out. On an le host and an le build without this patch I see:

(This is all ARM, not thumb)

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   e52de004        push    {lr}            ; (str lr, [sp, #-4]!)
  14:   ebfffffe        bl      0 <__gnu_mcount_nc>

After this patch on an le host and le build I see:

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   e1a00000        nop                     ; (mov r0, r0)
  14:   e1a00000        nop                     ; (mov r0, r0)

So far so good. Similarly, with this patch and an le host and be build I see:

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   e1a00000        nop                     ; (mov r0, r0)
  14:   e1a00000        nop                     ; (mov r0, r0)

but with *_le instead of *_be used a be build I see:

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   0000a0e1        andeq   sl, r0, r1, ror #1
  14:   0000a0e1        andeq   sl, r0, r1, ror #1

I confirmed this by looking at the hexdump of the .exception.text section for the traps.o object file and the .text section of the vmlinux file. Basically objcopy the .exception.text of traps.o to get the first few instructions of the do_undefinstr() function:

$ hexdump -C traps.o 
00000000  e1 a0 c0 0d e9 2d d9 f0  e2 4c b0 04 e2 4d d0 8c

And then objcopy the .text section in vmlinux and seek to the same function offset (there are a bunch of zeroes in front of it for padding):

$ hexdump -C vmlinux
...
00001000  0d c0 a0 e1 f0 d9 2d e9  04 b0 4c e2 8c d0 4d e2

As can be seen everything is swapped from the original object file in big-endian to be in little endian.

Does that allay your concerns?

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw
Quoted 39 lines · Stephen Boyd
Quoted 31 lines · Ard Biesheuvel
Quoted 30 lines · Stephen Boyd
Quoted 7 lines · Ard Biesheuvel

scripts/recordmcount.c static int make_nop_x86(void *map, size_t const offset) · line 217

Quoted 3 lines · Stephen Boyd
scripts/recordmcount.c +2 -0
+static unsigned char ideal_nop4_arm_le[4] = { 0x00, 0x00, 0xa0, 0xe1 }; /* mov r0, r0 */
+static unsigned char ideal_nop4_arm_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; /* mov r0, r0 */

Shouldn't you be taking the difference between BE8 and BE32 into account here? IIRC, BE8 uses little endian encoding for instructions.

I admit I haven't tested on a pre-armv6 CPU so I haven't come across the case of a BE32 CPU. But from what I can tell that doesn't matter.

According to scripts/Makefile.build, cmd_record_mcount only runs the recordmcount program if CONFIG_FTRACE_MCOUNT_RECORD=y. That config is defined as:

config FTRACE_MCOUNT_RECORD
def_bool y
depends on DYNAMIC_FTRACE depends on HAVE_FTRACE_MCOUNT_RECORD

And in arch/arm/Kconfig we see that DYNAMIC_FTRACE is selected:

        select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU

which means that FTRACE_MCOUNT_RECORD can't be set when CPU_ENDIAN_BE32 is set.

Quoted 6 lines
Quoted 2 lines

Do you agree that BE32 is not a concern here?

Yes. But that implies then that you should not be using big-endian instruction encodings at all, and simply use the _le variants for both LE and BE8

Quoted 9 lines

Ok. I understand what you're getting at now.

I believe the linker is the one that does the instruction endian swap to little endian. So everything is built as big-endian data and instructions in the assembler phase and then when the linker runs to generate the final vmlinux elf file it does the swaps to make instructions little endian. recordmcount runs on the object files and not the vmlinux file.

Very interesting, I did not know that.

Quoted 57 lines

For example, the do_undefinstr() function in arch/arm/kernel/traps.c is one place we nop out. On an le host and an le build without this patch I see:

(This is all ARM, not thumb)

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   e52de004        push    {lr}            ; (str lr, [sp, #-4]!)
  14:   ebfffffe        bl      0 <__gnu_mcount_nc>

After this patch on an le host and le build I see:

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   e1a00000        nop                     ; (mov r0, r0)
  14:   e1a00000        nop                     ; (mov r0, r0)

So far so good. Similarly, with this patch and an le host and be build I see:

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   e1a00000        nop                     ; (mov r0, r0)
  14:   e1a00000        nop                     ; (mov r0, r0)

but with *_le instead of *_be used a be build I see:

00000000 <do_undefinstr>:

   0:   e1a0c00d        mov     ip, sp
   4:   e92dd9f0        push    {r4, r5, r6, r7, r8, fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4
   c:   e24dd08c        sub     sp, sp, #140    ; 0x8c
  10:   0000a0e1        andeq   sl, r0, r1, ror #1
  14:   0000a0e1        andeq   sl, r0, r1, ror #1

I confirmed this by looking at the hexdump of the .exception.text section for the traps.o object file and the .text section of the vmlinux file. Basically objcopy the .exception.text of traps.o to get the first few instructions of the do_undefinstr() function:

$ hexdump -C traps.o
00000000  e1 a0 c0 0d e9 2d d9 f0  e2 4c b0 04 e2 4d d0 8c

And then objcopy the .text section in vmlinux and seek to the same function offset (there are a bunch of zeroes in front of it for padding):

Quoted 9 lines
$ hexdump -C vmlinux
...
00001000  0d c0 a0 e1 f0 d9 2d e9  04 b0 4c e2 8c d0 4d e2

As can be seen everything is swapped from the original object file in big-endian to be in little endian.

Does that allay your concerns?

Yes, it does. Thanks

#10 lore raw
Quoted 5 lines · On Wed, 16 Nov 2016 11:48:38 +0000 Ard Biesheuvel <[email protected]>…
Quoted 3 lines

Does that allay your concerns?

Yes, it does. Thanks

Does this mean I can pull this patch into my queue then?

-- Steve

#11 lore raw
Quoted 11 lines · Steven Rostedt
Quoted 5 lines · On Wed, 16 Nov 2016 11:48:38 +0000 Ard Biesheuvel <[email protected]>…
Quoted 3 lines

Does that allay your concerns?

Yes, it does. Thanks

Does this mean I can pull this patch into my queue then?

Fine by me

Thanks,
Ard.