Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Improve reloc naming

- The term "reloc" is overloaded to mean both "an instance of struct
reloc" and "a reloc section". Change the latter to "rsec".

- For variable names, use "sec" for regular sections and "rsec" for rela
sections to prevent them getting mixed up.

- For struct reloc variables, use "reloc" instead of "rel" everywhere
for consistency.

Link: https://lore.kernel.org/r/8b790e403df46f445c21003e7893b8f53b99a6f3.1685464332.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

+151 -149
+67 -67
tools/objtool/check.c
··· 494 494 { 495 495 struct symbol *sym, *func; 496 496 unsigned long off, end; 497 - struct reloc *rel; 497 + struct reloc *reloc; 498 498 int idx; 499 499 500 500 sym = find_symbol_by_name(file->elf, symname); ··· 504 504 off = sym->offset; 505 505 end = off + sym->len; 506 506 for (;;) { 507 - rel = find_reloc_by_dest_range(file->elf, sym->sec, off, end - off); 508 - if (!rel) 507 + reloc = find_reloc_by_dest_range(file->elf, sym->sec, off, end - off); 508 + if (!reloc) 509 509 break; 510 510 511 - func = rel->sym; 511 + func = reloc->sym; 512 512 if (func->type == STT_SECTION) 513 - func = find_symbol_by_offset(rel->sym->sec, rel->addend); 513 + func = find_symbol_by_offset(reloc->sym->sec, reloc->addend); 514 514 515 - idx = (rel->offset - sym->offset) / sizeof(unsigned long); 515 + idx = (reloc->offset - sym->offset) / sizeof(unsigned long); 516 516 517 517 objtool_pv_add(file, idx, func); 518 518 519 - off = rel->offset + 1; 519 + off = reloc->offset + 1; 520 520 if (off > end) 521 521 break; 522 522 } ··· 581 581 */ 582 582 static int add_dead_ends(struct objtool_file *file) 583 583 { 584 - struct section *sec; 584 + struct section *rsec; 585 585 struct reloc *reloc; 586 586 struct instruction *insn; 587 587 588 588 /* 589 589 * Check for manually annotated dead ends. 590 590 */ 591 - sec = find_section_by_name(file->elf, ".rela.discard.unreachable"); 592 - if (!sec) 591 + rsec = find_section_by_name(file->elf, ".rela.discard.unreachable"); 592 + if (!rsec) 593 593 goto reachable; 594 594 595 - list_for_each_entry(reloc, &sec->reloc_list, list) { 595 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 596 596 if (reloc->sym->type != STT_SECTION) { 597 - WARN("unexpected relocation symbol type in %s", sec->name); 597 + WARN("unexpected relocation symbol type in %s", rsec->name); 598 598 return -1; 599 599 } 600 600 insn = find_insn(file, reloc->sym->sec, reloc->addend); ··· 623 623 * GCC doesn't know the "ud2" is fatal, so it generates code as if it's 624 624 * not a dead end. 625 625 */ 626 - sec = find_section_by_name(file->elf, ".rela.discard.reachable"); 627 - if (!sec) 626 + rsec = find_section_by_name(file->elf, ".rela.discard.reachable"); 627 + if (!rsec) 628 628 return 0; 629 629 630 - list_for_each_entry(reloc, &sec->reloc_list, list) { 630 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 631 631 if (reloc->sym->type != STT_SECTION) { 632 - WARN("unexpected relocation symbol type in %s", sec->name); 632 + WARN("unexpected relocation symbol type in %s", rsec->name); 633 633 return -1; 634 634 } 635 635 insn = find_insn(file, reloc->sym->sec, reloc->addend); ··· 1044 1044 static void add_ignores(struct objtool_file *file) 1045 1045 { 1046 1046 struct instruction *insn; 1047 - struct section *sec; 1047 + struct section *rsec; 1048 1048 struct symbol *func; 1049 1049 struct reloc *reloc; 1050 1050 1051 - sec = find_section_by_name(file->elf, ".rela.discard.func_stack_frame_non_standard"); 1052 - if (!sec) 1051 + rsec = find_section_by_name(file->elf, ".rela.discard.func_stack_frame_non_standard"); 1052 + if (!rsec) 1053 1053 return; 1054 1054 1055 - list_for_each_entry(reloc, &sec->reloc_list, list) { 1055 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 1056 1056 switch (reloc->sym->type) { 1057 1057 case STT_FUNC: 1058 1058 func = reloc->sym; ··· 1065 1065 break; 1066 1066 1067 1067 default: 1068 - WARN("unexpected relocation symbol type in %s: %d", sec->name, reloc->sym->type); 1068 + WARN("unexpected relocation symbol type in %s: %d", 1069 + rsec->name, reloc->sym->type); 1069 1070 continue; 1070 1071 } 1071 1072 ··· 1285 1284 */ 1286 1285 static int add_ignore_alternatives(struct objtool_file *file) 1287 1286 { 1288 - struct section *sec; 1287 + struct section *rsec; 1289 1288 struct reloc *reloc; 1290 1289 struct instruction *insn; 1291 1290 1292 - sec = find_section_by_name(file->elf, ".rela.discard.ignore_alts"); 1293 - if (!sec) 1291 + rsec = find_section_by_name(file->elf, ".rela.discard.ignore_alts"); 1292 + if (!rsec) 1294 1293 return 0; 1295 1294 1296 - list_for_each_entry(reloc, &sec->reloc_list, list) { 1295 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 1297 1296 if (reloc->sym->type != STT_SECTION) { 1298 - WARN("unexpected relocation symbol type in %s", sec->name); 1297 + WARN("unexpected relocation symbol type in %s", rsec->name); 1299 1298 return -1; 1300 1299 } 1301 1300 ··· 2205 2204 static int read_unwind_hints(struct objtool_file *file) 2206 2205 { 2207 2206 struct cfi_state cfi = init_cfi; 2208 - struct section *sec, *relocsec; 2207 + struct section *sec; 2209 2208 struct unwind_hint *hint; 2210 2209 struct instruction *insn; 2211 2210 struct reloc *reloc; ··· 2215 2214 if (!sec) 2216 2215 return 0; 2217 2216 2218 - relocsec = sec->reloc; 2219 - if (!relocsec) { 2217 + if (!sec->rsec) { 2220 2218 WARN("missing .rela.discard.unwind_hints section"); 2221 2219 return -1; 2222 2220 } ··· 2295 2295 2296 2296 static int read_noendbr_hints(struct objtool_file *file) 2297 2297 { 2298 - struct section *sec; 2299 2298 struct instruction *insn; 2299 + struct section *rsec; 2300 2300 struct reloc *reloc; 2301 2301 2302 - sec = find_section_by_name(file->elf, ".rela.discard.noendbr"); 2303 - if (!sec) 2302 + rsec = find_section_by_name(file->elf, ".rela.discard.noendbr"); 2303 + if (!rsec) 2304 2304 return 0; 2305 2305 2306 - list_for_each_entry(reloc, &sec->reloc_list, list) { 2306 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 2307 2307 insn = find_insn(file, reloc->sym->sec, reloc->sym->offset + reloc->addend); 2308 2308 if (!insn) { 2309 2309 WARN("bad .discard.noendbr entry"); ··· 2318 2318 2319 2319 static int read_retpoline_hints(struct objtool_file *file) 2320 2320 { 2321 - struct section *sec; 2321 + struct section *rsec; 2322 2322 struct instruction *insn; 2323 2323 struct reloc *reloc; 2324 2324 2325 - sec = find_section_by_name(file->elf, ".rela.discard.retpoline_safe"); 2326 - if (!sec) 2325 + rsec = find_section_by_name(file->elf, ".rela.discard.retpoline_safe"); 2326 + if (!rsec) 2327 2327 return 0; 2328 2328 2329 - list_for_each_entry(reloc, &sec->reloc_list, list) { 2329 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 2330 2330 if (reloc->sym->type != STT_SECTION) { 2331 - WARN("unexpected relocation symbol type in %s", sec->name); 2331 + WARN("unexpected relocation symbol type in %s", rsec->name); 2332 2332 return -1; 2333 2333 } 2334 2334 ··· 2354 2354 2355 2355 static int read_instr_hints(struct objtool_file *file) 2356 2356 { 2357 - struct section *sec; 2357 + struct section *rsec; 2358 2358 struct instruction *insn; 2359 2359 struct reloc *reloc; 2360 2360 2361 - sec = find_section_by_name(file->elf, ".rela.discard.instr_end"); 2362 - if (!sec) 2361 + rsec = find_section_by_name(file->elf, ".rela.discard.instr_end"); 2362 + if (!rsec) 2363 2363 return 0; 2364 2364 2365 - list_for_each_entry(reloc, &sec->reloc_list, list) { 2365 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 2366 2366 if (reloc->sym->type != STT_SECTION) { 2367 - WARN("unexpected relocation symbol type in %s", sec->name); 2367 + WARN("unexpected relocation symbol type in %s", rsec->name); 2368 2368 return -1; 2369 2369 } 2370 2370 ··· 2377 2377 insn->instr--; 2378 2378 } 2379 2379 2380 - sec = find_section_by_name(file->elf, ".rela.discard.instr_begin"); 2381 - if (!sec) 2380 + rsec = find_section_by_name(file->elf, ".rela.discard.instr_begin"); 2381 + if (!rsec) 2382 2382 return 0; 2383 2383 2384 - list_for_each_entry(reloc, &sec->reloc_list, list) { 2384 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 2385 2385 if (reloc->sym->type != STT_SECTION) { 2386 - WARN("unexpected relocation symbol type in %s", sec->name); 2386 + WARN("unexpected relocation symbol type in %s", rsec->name); 2387 2387 return -1; 2388 2388 } 2389 2389 ··· 2401 2401 2402 2402 static int read_validate_unret_hints(struct objtool_file *file) 2403 2403 { 2404 - struct section *sec; 2404 + struct section *rsec; 2405 2405 struct instruction *insn; 2406 2406 struct reloc *reloc; 2407 2407 2408 - sec = find_section_by_name(file->elf, ".rela.discard.validate_unret"); 2409 - if (!sec) 2408 + rsec = find_section_by_name(file->elf, ".rela.discard.validate_unret"); 2409 + if (!rsec) 2410 2410 return 0; 2411 2411 2412 - list_for_each_entry(reloc, &sec->reloc_list, list) { 2412 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 2413 2413 if (reloc->sym->type != STT_SECTION) { 2414 - WARN("unexpected relocation symbol type in %s", sec->name); 2414 + WARN("unexpected relocation symbol type in %s", rsec->name); 2415 2415 return -1; 2416 2416 } 2417 2417 ··· 2430 2430 static int read_intra_function_calls(struct objtool_file *file) 2431 2431 { 2432 2432 struct instruction *insn; 2433 - struct section *sec; 2433 + struct section *rsec; 2434 2434 struct reloc *reloc; 2435 2435 2436 - sec = find_section_by_name(file->elf, ".rela.discard.intra_function_calls"); 2437 - if (!sec) 2436 + rsec = find_section_by_name(file->elf, ".rela.discard.intra_function_calls"); 2437 + if (!rsec) 2438 2438 return 0; 2439 2439 2440 - list_for_each_entry(reloc, &sec->reloc_list, list) { 2440 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 2441 2441 unsigned long dest_off; 2442 2442 2443 2443 if (reloc->sym->type != STT_SECTION) { 2444 2444 WARN("unexpected relocation symbol type in %s", 2445 - sec->name); 2445 + rsec->name); 2446 2446 return -1; 2447 2447 } 2448 2448 ··· 3342 3342 static inline const char *call_dest_name(struct instruction *insn) 3343 3343 { 3344 3344 static char pvname[19]; 3345 - struct reloc *rel; 3345 + struct reloc *reloc; 3346 3346 int idx; 3347 3347 3348 3348 if (insn_call_dest(insn)) 3349 3349 return insn_call_dest(insn)->name; 3350 3350 3351 - rel = insn_reloc(NULL, insn); 3352 - if (rel && !strcmp(rel->sym->name, "pv_ops")) { 3353 - idx = (rel->addend / sizeof(void *)); 3351 + reloc = insn_reloc(NULL, insn); 3352 + if (reloc && !strcmp(reloc->sym->name, "pv_ops")) { 3353 + idx = (reloc->addend / sizeof(void *)); 3354 3354 snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx); 3355 3355 return pvname; 3356 3356 } ··· 3361 3361 static bool pv_call_dest(struct objtool_file *file, struct instruction *insn) 3362 3362 { 3363 3363 struct symbol *target; 3364 - struct reloc *rel; 3364 + struct reloc *reloc; 3365 3365 int idx; 3366 3366 3367 - rel = insn_reloc(file, insn); 3368 - if (!rel || strcmp(rel->sym->name, "pv_ops")) 3367 + reloc = insn_reloc(file, insn); 3368 + if (!reloc || strcmp(reloc->sym->name, "pv_ops")) 3369 3369 return false; 3370 3370 3371 - idx = (arch_dest_reloc_offset(rel->addend) / sizeof(void *)); 3371 + idx = (arch_dest_reloc_offset(reloc->addend) / sizeof(void *)); 3372 3372 3373 3373 if (file->pv_ops[idx].clean) 3374 3374 return true; ··· 4410 4410 if (sec->sh.sh_flags & SHF_EXECINSTR) 4411 4411 continue; 4412 4412 4413 - if (!sec->reloc) 4413 + if (!sec->rsec) 4414 4414 continue; 4415 4415 4416 4416 /* ··· 4437 4437 strstr(sec->name, "__patchable_function_entries")) 4438 4438 continue; 4439 4439 4440 - list_for_each_entry(reloc, &sec->reloc->reloc_list, list) 4440 + list_for_each_entry(reloc, &sec->rsec->reloc_list, list) 4441 4441 warnings += validate_ibt_data_reloc(file, reloc); 4442 4442 } 4443 4443
+83 -81
tools/objtool/elf.c
··· 233 233 unsigned long offset, unsigned int len) 234 234 { 235 235 struct reloc *reloc, *r = NULL; 236 + struct section *rsec; 236 237 unsigned long o; 237 238 238 - if (!sec->reloc) 239 + rsec = sec->rsec; 240 + if (!rsec) 239 241 return NULL; 240 - 241 - sec = sec->reloc; 242 242 243 243 for_offset_range(o, offset, offset + len) { 244 244 elf_hash_for_each_possible(reloc, reloc, hash, 245 - sec_offset_hash(sec, o)) { 246 - if (reloc->sec != sec) 245 + sec_offset_hash(rsec, o)) { 246 + if (reloc->sec != rsec) 247 247 continue; 248 248 249 249 if (reloc->offset >= offset && reloc->offset < offset + len) { ··· 534 534 } 535 535 536 536 static struct section *elf_create_reloc_section(struct elf *elf, 537 - struct section *base, 537 + struct section *sec, 538 538 int reltype); 539 539 540 540 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, ··· 542 542 { 543 543 struct reloc *reloc; 544 544 545 - if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA)) 545 + if (!sec->rsec && !elf_create_reloc_section(elf, sec, SHT_RELA)) 546 546 return -1; 547 547 548 548 reloc = malloc(sizeof(*reloc)); ··· 552 552 } 553 553 memset(reloc, 0, sizeof(*reloc)); 554 554 555 - reloc->sec = sec->reloc; 555 + reloc->sec = sec->rsec; 556 556 reloc->offset = offset; 557 557 reloc->type = type; 558 558 reloc->sym = sym; 559 559 reloc->addend = addend; 560 560 561 561 list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list); 562 - list_add_tail(&reloc->list, &sec->reloc->reloc_list); 562 + list_add_tail(&reloc->list, &sec->rsec->reloc_list); 563 563 elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); 564 564 565 - sec->reloc->sh.sh_size += sec->reloc->sh.sh_entsize; 566 - sec->reloc->changed = true; 565 + sec->rsec->sh.sh_size += sec->rsec->sh.sh_entsize; 566 + sec->rsec->changed = true; 567 567 568 568 return 0; 569 569 } ··· 865 865 return elf_add_reloc(elf, sec, offset, type, sym, addend); 866 866 } 867 867 868 - static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) 868 + static int read_rel_reloc(struct section *rsec, int i, struct reloc *reloc, unsigned int *symndx) 869 869 { 870 - if (!gelf_getrel(sec->data, i, &reloc->rel)) { 870 + if (!gelf_getrel(rsec->data, i, &reloc->rel)) { 871 871 WARN_ELF("gelf_getrel"); 872 872 return -1; 873 873 } ··· 878 878 return 0; 879 879 } 880 880 881 - static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsigned int *symndx) 881 + static int read_rela_reloc(struct section *rsec, int i, struct reloc *reloc, unsigned int *symndx) 882 882 { 883 - if (!gelf_getrela(sec->data, i, &reloc->rela)) { 883 + if (!gelf_getrela(rsec->data, i, &reloc->rela)) { 884 884 WARN_ELF("gelf_getrela"); 885 885 return -1; 886 886 } ··· 894 894 static int read_relocs(struct elf *elf) 895 895 { 896 896 unsigned long nr_reloc, max_reloc = 0, tot_reloc = 0; 897 - struct section *sec; 897 + struct section *rsec; 898 898 struct reloc *reloc; 899 899 unsigned int symndx; 900 900 struct symbol *sym; ··· 903 903 if (!elf_alloc_hash(reloc, elf->text_size / 16)) 904 904 return -1; 905 905 906 - list_for_each_entry(sec, &elf->sections, list) { 907 - if ((sec->sh.sh_type != SHT_RELA) && 908 - (sec->sh.sh_type != SHT_REL)) 906 + list_for_each_entry(rsec, &elf->sections, list) { 907 + if ((rsec->sh.sh_type != SHT_RELA) && 908 + (rsec->sh.sh_type != SHT_REL)) 909 909 continue; 910 910 911 - sec->base = find_section_by_index(elf, sec->sh.sh_info); 912 - if (!sec->base) { 911 + rsec->base = find_section_by_index(elf, rsec->sh.sh_info); 912 + if (!rsec->base) { 913 913 WARN("can't find base section for reloc section %s", 914 - sec->name); 914 + rsec->name); 915 915 return -1; 916 916 } 917 917 918 - sec->base->reloc = sec; 918 + rsec->base->rsec = rsec; 919 919 920 920 nr_reloc = 0; 921 - sec->reloc_data = calloc(sec->sh.sh_size / sec->sh.sh_entsize, sizeof(*reloc)); 922 - if (!sec->reloc_data) { 921 + rsec->reloc_data = calloc(rsec->sh.sh_size / rsec->sh.sh_entsize, 922 + sizeof(*reloc)); 923 + if (!rsec->reloc_data) { 923 924 perror("calloc"); 924 925 return -1; 925 926 } 926 - for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { 927 - reloc = &sec->reloc_data[i]; 928 - switch (sec->sh.sh_type) { 927 + for (i = 0; i < rsec->sh.sh_size / rsec->sh.sh_entsize; i++) { 928 + reloc = &rsec->reloc_data[i]; 929 + switch (rsec->sh.sh_type) { 929 930 case SHT_REL: 930 - if (read_rel_reloc(sec, i, reloc, &symndx)) 931 + if (read_rel_reloc(rsec, i, reloc, &symndx)) 931 932 return -1; 932 933 break; 933 934 case SHT_RELA: 934 - if (read_rela_reloc(sec, i, reloc, &symndx)) 935 + if (read_rela_reloc(rsec, i, reloc, &symndx)) 935 936 return -1; 936 937 break; 937 938 default: return -1; 938 939 } 939 940 940 - reloc->sec = sec; 941 + reloc->sec = rsec; 941 942 reloc->idx = i; 942 943 reloc->sym = sym = find_symbol_by_index(elf, symndx); 943 944 if (!reloc->sym) { 944 945 WARN("can't find reloc entry symbol %d for %s", 945 - symndx, sec->name); 946 + symndx, rsec->name); 946 947 return -1; 947 948 } 948 949 949 950 list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list); 950 - list_add_tail(&reloc->list, &sec->reloc_list); 951 + list_add_tail(&reloc->list, &rsec->reloc_list); 951 952 elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); 952 953 953 954 nr_reloc++; ··· 1141 1140 return sec; 1142 1141 } 1143 1142 1144 - static struct section *elf_create_rel_reloc_section(struct elf *elf, struct section *base) 1143 + static struct section *elf_create_rel_reloc_section(struct elf *elf, 1144 + struct section *sec) 1145 1145 { 1146 1146 char *relocname; 1147 - struct section *sec; 1147 + struct section *rsec; 1148 1148 1149 - relocname = malloc(strlen(base->name) + strlen(".rel") + 1); 1149 + relocname = malloc(strlen(sec->name) + strlen(".rel") + 1); 1150 1150 if (!relocname) { 1151 1151 perror("malloc"); 1152 1152 return NULL; 1153 1153 } 1154 1154 strcpy(relocname, ".rel"); 1155 - strcat(relocname, base->name); 1155 + strcat(relocname, sec->name); 1156 1156 1157 - sec = elf_create_section(elf, relocname, sizeof(GElf_Rel), 0); 1157 + rsec = elf_create_section(elf, relocname, sizeof(GElf_Rel), 0); 1158 1158 free(relocname); 1159 - if (!sec) 1159 + if (!rsec) 1160 1160 return NULL; 1161 1161 1162 - base->reloc = sec; 1163 - sec->base = base; 1162 + sec->rsec = rsec; 1163 + rsec->base = sec; 1164 1164 1165 - sec->sh.sh_type = SHT_REL; 1166 - sec->sh.sh_addralign = 8; 1167 - sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; 1168 - sec->sh.sh_info = base->idx; 1169 - sec->sh.sh_flags = SHF_INFO_LINK; 1165 + rsec->sh.sh_type = SHT_REL; 1166 + rsec->sh.sh_addralign = 8; 1167 + rsec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; 1168 + rsec->sh.sh_info = sec->idx; 1169 + rsec->sh.sh_flags = SHF_INFO_LINK; 1170 1170 1171 - return sec; 1171 + return rsec; 1172 1172 } 1173 1173 1174 1174 static struct section *elf_create_rela_reloc_section(struct elf *elf, struct section *base) 1175 1175 { 1176 1176 char *relocname; 1177 - struct section *sec; 1177 + struct section *rsec; 1178 1178 int addrsize = elf_class_addrsize(elf); 1179 1179 1180 1180 relocname = malloc(strlen(base->name) + strlen(".rela") + 1); ··· 1187 1185 strcat(relocname, base->name); 1188 1186 1189 1187 if (addrsize == sizeof(u32)) 1190 - sec = elf_create_section(elf, relocname, sizeof(Elf32_Rela), 0); 1188 + rsec = elf_create_section(elf, relocname, sizeof(Elf32_Rela), 0); 1191 1189 else 1192 - sec = elf_create_section(elf, relocname, sizeof(GElf_Rela), 0); 1190 + rsec = elf_create_section(elf, relocname, sizeof(GElf_Rela), 0); 1193 1191 free(relocname); 1194 - if (!sec) 1192 + if (!rsec) 1195 1193 return NULL; 1196 1194 1197 - base->reloc = sec; 1198 - sec->base = base; 1195 + base->rsec = rsec; 1196 + rsec->base = base; 1199 1197 1200 - sec->sh.sh_type = SHT_RELA; 1201 - sec->sh.sh_addralign = addrsize; 1202 - sec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; 1203 - sec->sh.sh_info = base->idx; 1204 - sec->sh.sh_flags = SHF_INFO_LINK; 1198 + rsec->sh.sh_type = SHT_RELA; 1199 + rsec->sh.sh_addralign = addrsize; 1200 + rsec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx; 1201 + rsec->sh.sh_info = base->idx; 1202 + rsec->sh.sh_flags = SHF_INFO_LINK; 1205 1203 1206 - return sec; 1204 + return rsec; 1207 1205 } 1208 1206 1209 1207 static struct section *elf_create_reloc_section(struct elf *elf, ··· 1217 1215 } 1218 1216 } 1219 1217 1220 - static int elf_rebuild_rel_reloc_section(struct section *sec) 1218 + static int elf_rebuild_rel_reloc_section(struct section *rsec) 1221 1219 { 1222 1220 struct reloc *reloc; 1223 1221 int idx = 0; 1224 1222 void *buf; 1225 1223 1226 1224 /* Allocate a buffer for relocations */ 1227 - buf = malloc(sec->sh.sh_size); 1225 + buf = malloc(rsec->sh.sh_size); 1228 1226 if (!buf) { 1229 1227 perror("malloc"); 1230 1228 return -1; 1231 1229 } 1232 1230 1233 - sec->data->d_buf = buf; 1234 - sec->data->d_size = sec->sh.sh_size; 1235 - sec->data->d_type = ELF_T_REL; 1231 + rsec->data->d_buf = buf; 1232 + rsec->data->d_size = rsec->sh.sh_size; 1233 + rsec->data->d_type = ELF_T_REL; 1236 1234 1237 1235 idx = 0; 1238 - list_for_each_entry(reloc, &sec->reloc_list, list) { 1236 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 1239 1237 reloc->rel.r_offset = reloc->offset; 1240 1238 reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); 1241 - if (!gelf_update_rel(sec->data, idx, &reloc->rel)) { 1239 + if (!gelf_update_rel(rsec->data, idx, &reloc->rel)) { 1242 1240 WARN_ELF("gelf_update_rel"); 1243 1241 return -1; 1244 1242 } ··· 1248 1246 return 0; 1249 1247 } 1250 1248 1251 - static int elf_rebuild_rela_reloc_section(struct section *sec) 1249 + static int elf_rebuild_rela_reloc_section(struct section *rsec) 1252 1250 { 1253 1251 struct reloc *reloc; 1254 1252 int idx = 0; 1255 1253 void *buf; 1256 1254 1257 1255 /* Allocate a buffer for relocations with addends */ 1258 - buf = malloc(sec->sh.sh_size); 1256 + buf = malloc(rsec->sh.sh_size); 1259 1257 if (!buf) { 1260 1258 perror("malloc"); 1261 1259 return -1; 1262 1260 } 1263 1261 1264 - sec->data->d_buf = buf; 1265 - sec->data->d_size = sec->sh.sh_size; 1266 - sec->data->d_type = ELF_T_RELA; 1262 + rsec->data->d_buf = buf; 1263 + rsec->data->d_size = rsec->sh.sh_size; 1264 + rsec->data->d_type = ELF_T_RELA; 1267 1265 1268 1266 idx = 0; 1269 - list_for_each_entry(reloc, &sec->reloc_list, list) { 1267 + list_for_each_entry(reloc, &rsec->reloc_list, list) { 1270 1268 reloc->rela.r_offset = reloc->offset; 1271 1269 reloc->rela.r_addend = reloc->addend; 1272 1270 reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); 1273 - if (!gelf_update_rela(sec->data, idx, &reloc->rela)) { 1271 + if (!gelf_update_rela(rsec->data, idx, &reloc->rela)) { 1274 1272 WARN_ELF("gelf_update_rela"); 1275 1273 return -1; 1276 1274 } ··· 1280 1278 return 0; 1281 1279 } 1282 1280 1283 - static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) 1281 + static int elf_rebuild_reloc_section(struct elf *elf, struct section *rsec) 1284 1282 { 1285 - switch (sec->sh.sh_type) { 1286 - case SHT_REL: return elf_rebuild_rel_reloc_section(sec); 1287 - case SHT_RELA: return elf_rebuild_rela_reloc_section(sec); 1283 + switch (rsec->sh.sh_type) { 1284 + case SHT_REL: return elf_rebuild_rel_reloc_section(rsec); 1285 + case SHT_RELA: return elf_rebuild_rela_reloc_section(rsec); 1288 1286 default: return -1; 1289 1287 } 1290 1288 } ··· 1310 1308 1311 1309 int elf_write_reloc(struct elf *elf, struct reloc *reloc) 1312 1310 { 1313 - struct section *sec = reloc->sec; 1311 + struct section *rsec = reloc->sec; 1314 1312 1315 - if (sec->sh.sh_type == SHT_REL) { 1313 + if (rsec->sh.sh_type == SHT_REL) { 1316 1314 reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); 1317 1315 reloc->rel.r_offset = reloc->offset; 1318 1316 1319 - if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { 1317 + if (!gelf_update_rel(rsec->data, reloc->idx, &reloc->rel)) { 1320 1318 WARN_ELF("gelf_update_rel"); 1321 1319 return -1; 1322 1320 } ··· 1325 1323 reloc->rela.r_addend = reloc->addend; 1326 1324 reloc->rela.r_offset = reloc->offset; 1327 1325 1328 - if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { 1326 + if (!gelf_update_rela(rsec->data, reloc->idx, &reloc->rela)) { 1329 1327 WARN_ELF("gelf_update_rela"); 1330 1328 return -1; 1331 1329 }
+1 -1
tools/objtool/include/objtool/elf.h
··· 33 33 struct rb_root_cached symbol_tree; 34 34 struct list_head symbol_list; 35 35 struct list_head reloc_list; 36 - struct section *base, *reloc; 36 + struct section *base, *rsec; 37 37 struct symbol *sym; 38 38 Elf_Data *data; 39 39 char *name;