From 8812a3315d97c4d0e6043f31d9a9fe5799cd0f25 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 26 Jan 2019 11:59:27 -0600 Subject: [PATCH] libs/libc/machine/arm: Fix the minor issue in libc arm machine folder; MOVW/MOVT should use zero(not sign) extension. --- libs/libc/machine/arm/arm/arch_elf.c | 5 ++--- libs/libc/machine/arm/armv6-m/arch_elf.c | 13 ++++--------- libs/libc/machine/arm/armv7-a/arch_elf.c | 5 ++--- libs/libc/machine/arm/armv7-a/gnu/arch_memcpy.S | 2 +- libs/libc/machine/arm/armv7-m/arch_elf.c | 13 ++++--------- libs/libc/machine/arm/armv7-m/gnu/arch_memcpy.S | 2 +- libs/libc/machine/arm/armv7-r/arch_elf.c | 5 ++--- libs/libc/machine/arm/armv7-r/gnu/arch_memcpy.S | 2 +- 8 files changed, 17 insertions(+), 30 deletions(-) diff --git a/libs/libc/machine/arm/arm/arch_elf.c b/libs/libc/machine/arm/arm/arch_elf.c index 7ac3ce31923..6cd8b4f2e23 100644 --- a/libs/libc/machine/arm/arm/arch_elf.c +++ b/libs/libc/machine/arm/arm/arch_elf.c @@ -170,7 +170,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, case R_ARM_CALL: case R_ARM_JUMP24: { - binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n", + binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%p' st_value=%08lx\n", ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t *)addr), sym, (long)sym->st_value); @@ -181,7 +181,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, } offset += sym->st_value - addr; - if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) + if (offset & 3 || offset < (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) { berr("ERROR: PC24 [%d] relocation out of range, offset=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); @@ -240,7 +240,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, offset = *(uint32_t *)addr; offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); - offset = (offset ^ 0x8000) - 0x8000; offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS) diff --git a/libs/libc/machine/arm/armv6-m/arch_elf.c b/libs/libc/machine/arm/armv6-m/arch_elf.c index 2e9170eed84..900aacac6cd 100644 --- a/libs/libc/machine/arm/armv6-m/arch_elf.c +++ b/libs/libc/machine/arm/armv6-m/arch_elf.c @@ -166,7 +166,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, case R_ARM_CALL: case R_ARM_JUMP24: { - binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n", + binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%p' st_value=%08lx\n", ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t *)addr), sym, (long)sym->st_value); @@ -177,7 +177,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, } offset += sym->st_value - addr; - if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) + if (offset & 3 || offset < (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) { berr("ERROR: ERROR: PC24 [%d] relocation out of range, offset=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); @@ -296,9 +296,9 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, /* Check the range of the offset */ - if (offset <= (int32_t)0xff000000 || offset >= (int32_t)0x01000000) + if (offset < (int32_t)0xff000000 || offset >= (int32_t)0x01000000) { - berr("ERROR: ERROR: JUMP24 [%d] relocation out of range, branch taget=%08lx\n", + berr("ERROR: ERROR: JUMP24 [%d] relocation out of range, branch target=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); return -EINVAL; @@ -357,7 +357,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, offset = *(uint32_t *)addr; offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); - offset = (offset ^ 0x8000) - 0x8000; offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS) @@ -417,10 +416,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, ((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */ (lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */ - /* Sign extend */ - - offset = (offset ^ 0x8000) - 0x8000; - /* And perform the relocation */ binfo(" offset=%08lx branch target=%08lx\n", diff --git a/libs/libc/machine/arm/armv7-a/arch_elf.c b/libs/libc/machine/arm/armv7-a/arch_elf.c index a1ace2c5297..0cbdd4165e3 100644 --- a/libs/libc/machine/arm/armv7-a/arch_elf.c +++ b/libs/libc/machine/arm/armv7-a/arch_elf.c @@ -160,7 +160,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, case R_ARM_CALL: case R_ARM_JUMP24: { - binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n", + binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%p' st_value=%08lx\n", ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t *)addr), sym, (long)sym->st_value); @@ -171,7 +171,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, } offset += sym->st_value - addr; - if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) + if (offset & 3 || offset < (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) { berr("ERROR: PC24 [%d] relocation out of range, offset=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); @@ -230,7 +230,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, offset = *(uint32_t *)addr; offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); - offset = (offset ^ 0x8000) - 0x8000; offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS) diff --git a/libs/libc/machine/arm/armv7-a/gnu/arch_memcpy.S b/libs/libc/machine/arm/armv7-a/gnu/arch_memcpy.S index a693255fd61..271b4140ad4 100644 --- a/libs/libc/machine/arm/armv7-a/gnu/arch_memcpy.S +++ b/libs/libc/machine/arm/armv7-a/gnu/arch_memcpy.S @@ -1,5 +1,5 @@ /************************************************************************************ - * libs/libc/machine/arm/armv7-a/arm_memcpy.S + * libs/libc/machine/arm/armv7-a/arch_memcpy.S * ARMv7-A optimized memcpy. * * Adapted for use with ARMv7-A and NuttX by: diff --git a/libs/libc/machine/arm/armv7-m/arch_elf.c b/libs/libc/machine/arm/armv7-m/arch_elf.c index 45f5c4fec6d..67153942073 100644 --- a/libs/libc/machine/arm/armv7-m/arch_elf.c +++ b/libs/libc/machine/arm/armv7-m/arch_elf.c @@ -154,7 +154,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, case R_ARM_CALL: case R_ARM_JUMP24: { - binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n", + binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%p' st_value=%08lx\n", ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t *)addr), sym, (long)sym->st_value); @@ -165,7 +165,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, } offset += sym->st_value - addr; - if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) + if (offset & 3 || offset < (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) { berr("ERROR: ERROR: PC24 [%d] relocation out of range, offset=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); @@ -296,9 +296,9 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, /* Check the range of the offset */ - if (offset <= (int32_t)0xff000000 || offset >= (int32_t)0x01000000) + if (offset < (int32_t)0xff000000 || offset >= (int32_t)0x01000000) { - berr("ERROR: ERROR: JUMP24 [%d] relocation out of range, branch taget=%08lx\n", + berr("ERROR: ERROR: JUMP24 [%d] relocation out of range, branch target=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); return -EINVAL; @@ -357,7 +357,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, offset = *(uint32_t *)addr; offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); - offset = (offset ^ 0x8000) - 0x8000; offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS) @@ -417,10 +416,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, ((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */ (lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */ - /* Sign extend */ - - offset = (offset ^ 0x8000) - 0x8000; - /* And perform the relocation */ binfo(" offset=%08lx branch target=%08lx\n", diff --git a/libs/libc/machine/arm/armv7-m/gnu/arch_memcpy.S b/libs/libc/machine/arm/armv7-m/gnu/arch_memcpy.S index 7ea6a81eabf..6c1b62f7fb2 100644 --- a/libs/libc/machine/arm/armv7-m/gnu/arch_memcpy.S +++ b/libs/libc/machine/arm/armv7-m/gnu/arch_memcpy.S @@ -1,5 +1,5 @@ /************************************************************************************ - * libs/libc/machine/arm/armv7-m/gnu/up_memcpy.S + * libs/libc/machine/arm/armv7-m/gnu/arch_memcpy.S * * armv7m-optimized memcpy, contributed by Mike Smith. Apparently in the public * domain and is re-released here under the modified BSD license: diff --git a/libs/libc/machine/arm/armv7-r/arch_elf.c b/libs/libc/machine/arm/armv7-r/arch_elf.c index efee7e96fa9..693dc1daca1 100644 --- a/libs/libc/machine/arm/armv7-r/arch_elf.c +++ b/libs/libc/machine/arm/armv7-r/arch_elf.c @@ -172,7 +172,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, case R_ARM_CALL: case R_ARM_JUMP24: { - binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n", + binfo("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%p' st_value=%08lx\n", ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t *)addr), sym, (long)sym->st_value); @@ -183,7 +183,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, } offset += sym->st_value - addr; - if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) + if (offset & 3 || offset < (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) { berr("ERROR: ERROR: PC24 [%d] relocation out of range, offset=%08lx\n", ELF32_R_TYPE(rel->r_info), offset); @@ -242,7 +242,6 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, offset = *(uint32_t *)addr; offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); - offset = (offset ^ 0x8000) - 0x8000; offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS) diff --git a/libs/libc/machine/arm/armv7-r/gnu/arch_memcpy.S b/libs/libc/machine/arm/armv7-r/gnu/arch_memcpy.S index 6b1efa9f146..c4a7cbd2ed7 100644 --- a/libs/libc/machine/arm/armv7-r/gnu/arch_memcpy.S +++ b/libs/libc/machine/arm/armv7-r/gnu/arch_memcpy.S @@ -1,5 +1,5 @@ /************************************************************************************ - * libs/libc/marchine/arm/armv7-r/arm_memcpy.S + * libs/libc/marchine/arm/armv7-r/arch_memcpy.S * ARMv7-R optimized memcpy. * * Adapted for use with ARMv7-R and NuttX by: