Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1324884 > unrolled thread
| Started by | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| First post | 2016-02-03 04:50 +0100 |
| Last post | 2016-02-03 13:50 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 5/5] MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs Paul Burton <paul.burton@imgtec.com> - 2016-02-03 04:50 +0100
Re: [PATCH 5/5] MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs James Hogan <james.hogan@imgtec.com> - 2016-02-03 13:50 +0100
| From | Paul Burton <paul.burton@imgtec.com> |
|---|---|
| Date | 2016-02-03 04:50 +0100 |
| Subject | [PATCH 5/5] MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs |
| Message-ID | <qXWC5-4X7-5@gated-at.bofh.it> |
MIPS32r6 code makes use of rel-stye relocations & may contain the new
relocations R_MIPS_PC21_S2 or R_MIPS_PC26_S2 which were introduced with
MIPSr6. Implement support for those relocations such that we can load
MIPS32r6 kernel modules.
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---
arch/mips/kernel/module.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
index f2de9b8..d62fd56 100644
--- a/arch/mips/kernel/module.c
+++ b/arch/mips/kernel/module.c
@@ -194,6 +194,56 @@ static int apply_r_mips_pc16_rel(struct module *me, u32 *location, Elf_Addr v)
return 0;
}
+static int apply_r_mips_pc21_rel(struct module *me, u32 *location, Elf_Addr v)
+{
+ long offset;
+
+ if (v % 4) {
+ pr_err("module %s: dangerous R_MIPS_PC21 REL relocation\n",
+ me->name);
+ return -ENOEXEC;
+ }
+
+ /* retrieve & sign extend implicit addend */
+ offset = *location & 0x1fffff;
+ offset |= (offset & BIT(20)) ? (~0l & ~0x1fffffl) : 0;
+
+ offset += ((long)v - (long)location) >> 2;
+ if ((offset >> 20) > 0 || (offset >> 20) < -1) {
+ pr_err("module %s: relocation overflow\n", me->name);
+ return -ENOEXEC;
+ }
+
+ *location = (*location & ~0x001fffff) | (offset & 0x001fffff);
+
+ return 0;
+}
+
+static int apply_r_mips_pc26_rel(struct module *me, u32 *location, Elf_Addr v)
+{
+ long offset;
+
+ if (v % 4) {
+ pr_err("module %s: dangerous R_MIPS_PC26 REL relocation\n",
+ me->name);
+ return -ENOEXEC;
+ }
+
+ /* retrieve & sign extend implicit addend */
+ offset = *location & 0x3ffffff;
+ offset |= (offset & BIT(25)) ? (~0l & ~0x3ffffffl) : 0;
+
+ offset += ((long)v - (long)location) >> 2;
+ if ((offset >> 25) > 0 || (offset >> 25) < -1) {
+ pr_err("module %s: relocation overflow\n", me->name);
+ return -ENOEXEC;
+ }
+
+ *location = (*location & ~0x03ffffff) | (offset & 0x03ffffff);
+
+ return 0;
+}
+
static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
Elf_Addr v) = {
[R_MIPS_NONE] = apply_r_mips_none,
@@ -202,6 +252,8 @@ static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
[R_MIPS_HI16] = apply_r_mips_hi16_rel,
[R_MIPS_LO16] = apply_r_mips_lo16_rel,
[R_MIPS_PC16] = apply_r_mips_pc16_rel,
+ [R_MIPS_PC21_S2] = apply_r_mips_pc21_rel,
+ [R_MIPS_PC26_S2] = apply_r_mips_pc26_rel,
};
int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
--
2.7.0
[toc] | [next] | [standalone]
| From | James Hogan <james.hogan@imgtec.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Message-ID | <qY52H-212-37@gated-at.bofh.it> |
| In reply to | #1324884 |
[Multipart message — attachments visible in raw view] — view raw
On Wed, Feb 03, 2016 at 03:44:45AM +0000, Paul Burton wrote:
> MIPS32r6 code makes use of rel-stye relocations & may contain the new
> relocations R_MIPS_PC21_S2 or R_MIPS_PC26_S2 which were introduced with
> MIPSr6. Implement support for those relocations such that we can load
> MIPS32r6 kernel modules.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Looks good to me,
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cheers
James
>
> ---
>
> arch/mips/kernel/module.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
>
> diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
> index f2de9b8..d62fd56 100644
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -194,6 +194,56 @@ static int apply_r_mips_pc16_rel(struct module *me, u32 *location, Elf_Addr v)
> return 0;
> }
>
> +static int apply_r_mips_pc21_rel(struct module *me, u32 *location, Elf_Addr v)
> +{
> + long offset;
> +
> + if (v % 4) {
> + pr_err("module %s: dangerous R_MIPS_PC21 REL relocation\n",
> + me->name);
> + return -ENOEXEC;
> + }
> +
> + /* retrieve & sign extend implicit addend */
> + offset = *location & 0x1fffff;
> + offset |= (offset & BIT(20)) ? (~0l & ~0x1fffffl) : 0;
> +
> + offset += ((long)v - (long)location) >> 2;
> + if ((offset >> 20) > 0 || (offset >> 20) < -1) {
> + pr_err("module %s: relocation overflow\n", me->name);
> + return -ENOEXEC;
> + }
> +
> + *location = (*location & ~0x001fffff) | (offset & 0x001fffff);
> +
> + return 0;
> +}
> +
> +static int apply_r_mips_pc26_rel(struct module *me, u32 *location, Elf_Addr v)
> +{
> + long offset;
> +
> + if (v % 4) {
> + pr_err("module %s: dangerous R_MIPS_PC26 REL relocation\n",
> + me->name);
> + return -ENOEXEC;
> + }
> +
> + /* retrieve & sign extend implicit addend */
> + offset = *location & 0x3ffffff;
> + offset |= (offset & BIT(25)) ? (~0l & ~0x3ffffffl) : 0;
> +
> + offset += ((long)v - (long)location) >> 2;
> + if ((offset >> 25) > 0 || (offset >> 25) < -1) {
> + pr_err("module %s: relocation overflow\n", me->name);
> + return -ENOEXEC;
> + }
> +
> + *location = (*location & ~0x03ffffff) | (offset & 0x03ffffff);
> +
> + return 0;
> +}
> +
> static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
> Elf_Addr v) = {
> [R_MIPS_NONE] = apply_r_mips_none,
> @@ -202,6 +252,8 @@ static int (*reloc_handlers_rel[]) (struct module *me, u32 *location,
> [R_MIPS_HI16] = apply_r_mips_hi16_rel,
> [R_MIPS_LO16] = apply_r_mips_lo16_rel,
> [R_MIPS_PC16] = apply_r_mips_pc16_rel,
> + [R_MIPS_PC21_S2] = apply_r_mips_pc21_rel,
> + [R_MIPS_PC26_S2] = apply_r_mips_pc26_rel,
> };
>
> int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
> --
> 2.7.0
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web