hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/scripts/mod/modpost.c
....@@ -1309,6 +1309,10 @@
13091309 if (relsym->st_name != 0)
13101310 return relsym;
13111311
1312
+ /*
1313
+ * Strive to find a better symbol name, but the resulting name may not
1314
+ * match the symbol referenced in the original code.
1315
+ */
13121316 relsym_secindex = get_secindex(elf, relsym);
13131317 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
13141318 if (get_secindex(elf, sym) != relsym_secindex)
....@@ -1613,7 +1617,7 @@
16131617
16141618 static int is_executable_section(struct elf_info* elf, unsigned int section_index)
16151619 {
1616
- if (section_index > elf->num_sections)
1620
+ if (section_index >= elf->num_sections)
16171621 fatal("section_index is outside elf->num_sections!\n");
16181622
16191623 return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
....@@ -1788,19 +1792,33 @@
17881792 #define R_ARM_THM_JUMP19 51
17891793 #endif
17901794
1795
+static int32_t sign_extend32(int32_t value, int index)
1796
+{
1797
+ uint8_t shift = 31 - index;
1798
+
1799
+ return (int32_t)(value << shift) >> shift;
1800
+}
1801
+
17911802 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
17921803 {
17931804 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1805
+ Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info);
1806
+ void *loc = reloc_location(elf, sechdr, r);
1807
+ uint32_t inst;
1808
+ int32_t offset;
17941809
17951810 switch (r_typ) {
17961811 case R_ARM_ABS32:
1797
- /* From ARM ABI: (S + A) | T */
1798
- r->r_addend = (int)(long)
1799
- (elf->symtab_start + ELF_R_SYM(r->r_info));
1812
+ inst = TO_NATIVE(*(uint32_t *)loc);
1813
+ r->r_addend = inst + sym->st_value;
18001814 break;
18011815 case R_ARM_PC24:
18021816 case R_ARM_CALL:
18031817 case R_ARM_JUMP24:
1818
+ inst = TO_NATIVE(*(uint32_t *)loc);
1819
+ offset = sign_extend32((inst & 0x00ffffff) << 2, 25);
1820
+ r->r_addend = offset + sym->st_value + 8;
1821
+ break;
18041822 case R_ARM_THM_CALL:
18051823 case R_ARM_THM_JUMP24:
18061824 case R_ARM_THM_JUMP19: