2 * Copyright (C) 2017 Linaro, Ltd. <ard.biesheuvel@linaro.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 #include <linux/module.h>
14 #define SYM64_ABS_VAL 0xffff880000cccccc
15 #define SYM32_ABS_VAL 0xf800cccc
16 #define SYM16_ABS_VAL 0xf8cc
18 #define __SET_ABS(name, val) asm(".globl " #name "; .set "#name ", " #val)
19 #define SET_ABS(name, val) __SET_ABS(name, val)
21 SET_ABS(sym64_abs
, SYM64_ABS_VAL
);
22 SET_ABS(sym32_abs
, SYM32_ABS_VAL
);
23 SET_ABS(sym16_abs
, SYM16_ABS_VAL
);
25 asmlinkage u64
absolute_data64(void);
26 asmlinkage u64
absolute_data32(void);
27 asmlinkage u64
absolute_data16(void);
28 asmlinkage u64
signed_movw(void);
29 asmlinkage u64
unsigned_movw(void);
30 asmlinkage u64
relative_adrp(void);
31 asmlinkage u64
relative_adr(void);
32 asmlinkage u64
relative_data64(void);
33 asmlinkage u64
relative_data32(void);
34 asmlinkage u64
relative_data16(void);
41 { "R_AARCH64_ABS64", absolute_data64
, UL(SYM64_ABS_VAL
) },
42 { "R_AARCH64_ABS32", absolute_data32
, UL(SYM32_ABS_VAL
) },
43 { "R_AARCH64_ABS16", absolute_data16
, UL(SYM16_ABS_VAL
) },
44 { "R_AARCH64_MOVW_SABS_Gn", signed_movw
, UL(SYM64_ABS_VAL
) },
45 { "R_AARCH64_MOVW_UABS_Gn", unsigned_movw
, UL(SYM64_ABS_VAL
) },
46 #ifndef CONFIG_ARM64_ERRATUM_843419
47 { "R_AARCH64_ADR_PREL_PG_HI21", relative_adrp
, (u64
)&sym64_rel
},
49 { "R_AARCH64_ADR_PREL_LO21", relative_adr
, (u64
)&sym64_rel
},
50 { "R_AARCH64_PREL64", relative_data64
, (u64
)&sym64_rel
},
51 { "R_AARCH64_PREL32", relative_data32
, (u64
)&sym64_rel
},
52 { "R_AARCH64_PREL16", relative_data16
, (u64
)&sym64_rel
},
55 static int reloc_test_init(void)
59 pr_info("Relocation test:\n");
60 pr_info("-------------------------------------------------------\n");
62 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
63 u64 ret
= funcs
[i
].f();
65 pr_info("%-31s 0x%016llx %s\n", funcs
[i
].name
, ret
,
66 ret
== funcs
[i
].expect
? "pass" : "fail");
67 if (ret
!= funcs
[i
].expect
)
68 pr_err("Relocation failed, expected 0x%016llx, not 0x%016llx\n",
69 funcs
[i
].expect
, ret
);
74 static void reloc_test_exit(void)
78 module_init(reloc_test_init
);
79 module_exit(reloc_test_exit
);
81 MODULE_LICENSE("GPL v2");