Commit cd1824f
committed
modpost: detect section mismatch for R_ARM_THM_{MOVW_ABS_NC,MOVT_ABS}
When CONFIG_THUMB2_KERNEL is enabled, modpost fails to detect some
types of section mismatches.
[test code]
#include <linux/init.h>
int __initdata foo;
int get_foo(void) { return foo; }
It is apparently a bad reference, but modpost does not report anything.
The test code above produces the following relocations.
Relocation section '.rel.text' at offset 0x1e8 contains 2 entries:
Offset Info Type Sym.Value Sym. Name
00000000 0000052f R_ARM_THM_MOVW_AB 00000000 .LANCHOR0
00000004 00000530 R_ARM_THM_MOVT_AB 00000000 .LANCHOR0
Currently, R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_ABS are just skipped.
Add code to handle them. I checked arch/arm/kernel/module.c to learn
how the offset is encoded in the instruction.
One more thing to note for Thumb instructions - the st_value is an odd
value, so you need to mask the bit 0 to get the offset. Otherwise, you
will get an off-by-one error in the nearest symbol look-up.
It is documented in "ELF for the ARM Architecture" [1]:
In addition to the normal rules for symbol values the following rules
shall also apply to symbols of type STT_FUNC:
* If the symbol addresses an Arm instruction, its value is the
address of the instruction (in a relocatable object, the offset
of the instruction from the start of the section containing it).
* If the symbol addresses a Thumb instruction, its value is the
address of the instruction with bit zero set (in a relocatable
object, the section offset with bit zero set).
* For the purposes of relocation the value used shall be the address
of the instruction (st_value & ~1).
[1]: https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>1 parent b1a9651 commit cd1824f
1 file changed
+26
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
1085 | | - | |
| 1085 | + | |
| 1086 | + | |
1086 | 1087 | | |
1087 | 1088 | | |
1088 | 1089 | | |
1089 | 1090 | | |
1090 | 1091 | | |
1091 | 1092 | | |
1092 | 1093 | | |
1093 | | - | |
1094 | | - | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
1095 | 1105 | | |
1096 | | - | |
| 1106 | + | |
1097 | 1107 | | |
1098 | 1108 | | |
1099 | 1109 | | |
| |||
1266 | 1276 | | |
1267 | 1277 | | |
1268 | 1278 | | |
1269 | | - | |
| 1279 | + | |
1270 | 1280 | | |
1271 | 1281 | | |
1272 | 1282 | | |
| |||
1288 | 1298 | | |
1289 | 1299 | | |
1290 | 1300 | | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
1291 | 1312 | | |
1292 | 1313 | | |
1293 | 1314 | | |
| |||
0 commit comments