Now that none of addend_*_rel() returns a meaningful value (the return value is always 0), change all of them to return the value of r_addend.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -1257,21 +1257,18 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, · 1256 unmodified lines | |||
| 1257 | tosec, taddr); | 1257 | tosec, taddr); |
| 1258 | } | 1258 | } |
| 1259 | 1259 | ||
| 1260 | static int addend_386_rel(uint32_t *location, Elf_Rela *r) | 1260 | static Elf_Addr addend_386_rel(uint32_t *location, Elf_Rela *r) |
| 1261 | { | 1261 | { |
| 1262 | unsigned int r_typ = ELF_R_TYPE(r->r_info); | 1262 | unsigned int r_typ = ELF_R_TYPE(r->r_info); |
| 1263 | 1263 | ||
| 1264 | switch (r_typ) { | 1264 | switch (r_typ) { |
| 1265 | case R_386_32: | 1265 | case R_386_32: |
| 1266 | r->r_addend = TO_NATIVE(*location); | 1266 | return TO_NATIVE(*location); |
| 1267 | break; | ||
| 1268 | case R_386_PC32: | 1267 | case R_386_PC32: |
| 1269 | r->r_addend = TO_NATIVE(*location) + 4; | 1268 | return TO_NATIVE(*location) + 4; |
| 1270 | break; | ||
| 1271 | default: | ||
| 1272 | r->r_addend = (Elf_Addr)(-1); | ||
| 1273 | } | 1269 | } |
| 1274 | return 0; | 1270 | |
| 1271 | return (Elf_Addr)(-1); | ||
| 1275 | } | 1272 | } |
| 1276 | 1273 | ||
| 1277 | #ifndef R_ARM_CALL | 1274 | #ifndef R_ARM_CALL |
| @@ -1315,7 +1312,7 @@ static int32_t sign_extend32(int32_t value, int index) · 37 unmodified lines | |||
| 1315 | return (int32_t)(value << shift) >> shift; | 1312 | return (int32_t)(value << shift) >> shift; |
| 1316 | } | 1313 | } |
| 1317 | 1314 | ||
| 1318 | static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) | 1315 | static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) |
| 1319 | { | 1316 | { |
| 1320 | unsigned int r_typ = ELF_R_TYPE(r->r_info); | 1317 | unsigned int r_typ = ELF_R_TYPE(r->r_info); |
| 1321 | uint32_t inst, upper, lower, sign, j1, j2; | 1318 | uint32_t inst, upper, lower, sign, j1, j2; |
| @@ -1325,22 +1322,19 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) · 3 unmodified lines | |||
| 1325 | case R_ARM_ABS32: | 1322 | case R_ARM_ABS32: |
| 1326 | case R_ARM_REL32: | 1323 | case R_ARM_REL32: |
| 1327 | inst = TO_NATIVE(*(uint32_t *)loc); | 1324 | inst = TO_NATIVE(*(uint32_t *)loc); |
| 1328 | r->r_addend = inst + sym->st_value; | 1325 | return inst + sym->st_value; |
| 1329 | break; | ||
| 1330 | case R_ARM_MOVW_ABS_NC: | 1326 | case R_ARM_MOVW_ABS_NC: |
| 1331 | case R_ARM_MOVT_ABS: | 1327 | case R_ARM_MOVT_ABS: |
| 1332 | inst = TO_NATIVE(*(uint32_t *)loc); | 1328 | inst = TO_NATIVE(*(uint32_t *)loc); |
| 1333 | offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff), | 1329 | offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff), |
| 1334 | 15); | 1330 | 15); |
| 1335 | r->r_addend = offset + sym->st_value; | 1331 | return offset + sym->st_value; |
| 1336 | break; | ||
| 1337 | case R_ARM_PC24: | 1332 | case R_ARM_PC24: |
| 1338 | case R_ARM_CALL: | 1333 | case R_ARM_CALL: |
| 1339 | case R_ARM_JUMP24: | 1334 | case R_ARM_JUMP24: |
| 1340 | inst = TO_NATIVE(*(uint32_t *)loc); | 1335 | inst = TO_NATIVE(*(uint32_t *)loc); |
| 1341 | offset = sign_extend32((inst & 0x00ffffff) << 2, 25); | 1336 | offset = sign_extend32((inst & 0x00ffffff) << 2, 25); |
| 1342 | r->r_addend = offset + sym->st_value + 8; | 1337 | return offset + sym->st_value + 8; |
| 1343 | break; | ||
| 1344 | case R_ARM_THM_MOVW_ABS_NC: | 1338 | case R_ARM_THM_MOVW_ABS_NC: |
| 1345 | case R_ARM_THM_MOVT_ABS: | 1339 | case R_ARM_THM_MOVT_ABS: |
| 1346 | upper = TO_NATIVE(*(uint16_t *)loc); | 1340 | upper = TO_NATIVE(*(uint16_t *)loc); |
| @@ -1350,8 +1344,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) · 3 unmodified lines | |||
| 1350 | ((lower & 0x7000) >> 4) | | 1344 | ((lower & 0x7000) >> 4) | |
| 1351 | (lower & 0x00ff), | 1345 | (lower & 0x00ff), |
| 1352 | 15); | 1346 | 15); |
| 1353 | r->r_addend = offset + sym->st_value; | 1347 | return offset + sym->st_value; |
| 1354 | break; | ||
| 1355 | case R_ARM_THM_JUMP19: | 1348 | case R_ARM_THM_JUMP19: |
| 1356 | /* | 1349 | /* |
| 1357 | * Encoding T3: | 1350 | * Encoding T3: |
| @@ -1372,8 +1365,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) · 14 unmodified lines | |||
| 1372 | ((upper & 0x03f) << 12) | | 1365 | ((upper & 0x03f) << 12) | |
| 1373 | ((lower & 0x07ff) << 1), | 1366 | ((lower & 0x07ff) << 1), |
| 1374 | 20); | 1367 | 20); |
| 1375 | r->r_addend = offset + sym->st_value + 4; | 1368 | return offset + sym->st_value + 4; |
| 1376 | break; | ||
| 1377 | case R_ARM_THM_CALL: | 1369 | case R_ARM_THM_CALL: |
| 1378 | case R_ARM_THM_JUMP24: | 1370 | case R_ARM_THM_JUMP24: |
| 1379 | /* | 1371 | /* |
| @@ -1399,15 +1391,13 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) · 19 unmodified lines | |||
| 1399 | ((upper & 0x03ff) << 12) | | 1391 | ((upper & 0x03ff) << 12) | |
| 1400 | ((lower & 0x07ff) << 1), | 1392 | ((lower & 0x07ff) << 1), |
| 1401 | 24); | 1393 | 24); |
| 1402 | r->r_addend = offset + sym->st_value + 4; | 1394 | return offset + sym->st_value + 4; |
| 1403 | break; | ||
| 1404 | default: | ||
| 1405 | r->r_addend = (Elf_Addr)(-1); | ||
| 1406 | } | 1395 | } |
| 1407 | return 0; | 1396 | |
| 1397 | return (Elf_Addr)(-1); | ||
| 1408 | } | 1398 | } |
| 1409 | 1399 | ||
| 1410 | static int addend_mips_rel(uint32_t *location, Elf_Rela *r) | 1400 | static Elf_Addr addend_mips_rel(uint32_t *location, Elf_Rela *r) |
| 1411 | { | 1401 | { |
| 1412 | unsigned int r_typ = ELF_R_TYPE(r->r_info); | 1402 | unsigned int r_typ = ELF_R_TYPE(r->r_info); |
| 1413 | uint32_t inst; | 1403 | uint32_t inst; |
| @@ -1415,18 +1405,13 @@ static int addend_mips_rel(uint32_t *location, Elf_Rela *r) · 1 unmodified line | |||
| 1415 | inst = TO_NATIVE(*location); | 1405 | inst = TO_NATIVE(*location); |
| 1416 | switch (r_typ) { | 1406 | switch (r_typ) { |
| 1417 | case R_MIPS_LO16: | 1407 | case R_MIPS_LO16: |
| 1418 | r->r_addend = inst & 0xffff; | 1408 | return inst & 0xffff; |
| 1419 | break; | ||
| 1420 | case R_MIPS_26: | 1409 | case R_MIPS_26: |
| 1421 | r->r_addend = (inst & 0x03ffffff) << 2; | 1410 | return (inst & 0x03ffffff) << 2; |
| 1422 | break; | ||
| 1423 | case R_MIPS_32: | 1411 | case R_MIPS_32: |
| 1424 | r->r_addend = inst; | 1412 | return inst; |
| 1425 | break; | ||
| 1426 | default: | ||
| 1427 | r->r_addend = (Elf_Addr)(-1); | ||
| 1428 | } | 1413 | } |
| 1429 | return 0; | 1414 | return (Elf_Addr)(-1); |
| 1430 | } | 1415 | } |
| 1431 | 1416 | ||
| 1432 | #ifndef EM_RISCV | 1417 | #ifndef EM_RISCV |
| @@ -1513,6 +1498,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, · 80 unmodified lines | |||
| 1513 | 1498 | ||
| 1514 | for (rel = start; rel < stop; rel++) { | 1499 | for (rel = start; rel < stop; rel++) { |
| 1515 | Elf_Sym *tsym; | 1500 | Elf_Sym *tsym; |
| 1501 | Elf_Addr taddr = 0; | ||
| 1516 | void *loc; | 1502 | void *loc; |
| 1517 | 1503 | ||
| 1518 | r.r_offset = TO_NATIVE(rel->r_offset); | 1504 | r.r_offset = TO_NATIVE(rel->r_offset); |
| @@ -1531,27 +1517,26 @@ static void section_rel(struct module *mod, struct elf_info *elf, · 12 unmodified lines | |||
| 1531 | r.r_info = TO_NATIVE(rel->r_info); | 1517 | r.r_info = TO_NATIVE(rel->r_info); |
| 1532 | r_sym = ELF_R_SYM(r.r_info); | 1518 | r_sym = ELF_R_SYM(r.r_info); |
| 1533 | #endif | 1519 | #endif |
| 1534 | r.r_addend = 0; | ||
| 1535 | 1520 | ||
| 1536 | loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); | 1521 | loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); |
| 1537 | tsym = elf->symtab_start + r_sym; | 1522 | tsym = elf->symtab_start + r_sym; |
| 1538 | 1523 | ||
| 1539 | switch (elf->hdr->e_machine) { | 1524 | switch (elf->hdr->e_machine) { |
| 1540 | case EM_386: | 1525 | case EM_386: |
| 1541 | addend_386_rel(loc, &r); | 1526 | taddr = addend_386_rel(loc, &r); |
| 1542 | break; | 1527 | break; |
| 1543 | case EM_ARM: | 1528 | case EM_ARM: |
| 1544 | addend_arm_rel(loc, tsym, &r); | 1529 | taddr = addend_arm_rel(loc, tsym, &r); |
| 1545 | break; | 1530 | break; |
| 1546 | case EM_MIPS: | 1531 | case EM_MIPS: |
| 1547 | addend_mips_rel(loc, &r); | 1532 | taddr = addend_mips_rel(loc, &r); |
| 1548 | break; | 1533 | break; |
| 1549 | default: | 1534 | default: |
| 1550 | fatal("Please add code to calculate addend for this architecture\n"); | 1535 | fatal("Please add code to calculate addend for this architecture\n"); |
| 1551 | } | 1536 | } |
| 1552 | 1537 | ||
| 1553 | check_section_mismatch(mod, elf, tsym, | 1538 | check_section_mismatch(mod, elf, tsym, |
| 1554 | fsecndx, fromsec, r.r_offset, r.r_addend); | 1539 | fsecndx, fromsec, r.r_offset, taddr); |
| 1555 | } | 1540 | } |
| 1556 | } | 1541 | } |
| 1557 | 1542 | ||