Skip to content

Commit fe255fe

Browse files
joe-lawrencejpoimboe
authored andcommitted
objtool: Remove redundant 'len' field from struct section
The section structure already contains sh_size, so just remove the extra 'len' member that requires extra mirroring and potential confusion. Suggested-by: Josh Poimboeuf <[email protected]> Signed-off-by: Joe Lawrence <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: Andy Lavr <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Cc: [email protected]
1 parent dc02368 commit fe255fe

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

tools/objtool/check.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int decode_instructions(struct objtool_file *file)
292292
!strcmp(sec->name, ".entry.text"))
293293
sec->noinstr = true;
294294

295-
for (offset = 0; offset < sec->len; offset += insn->len) {
295+
for (offset = 0; offset < sec->sh.sh_size; offset += insn->len) {
296296
insn = malloc(sizeof(*insn));
297297
if (!insn) {
298298
WARN("malloc failed");
@@ -307,7 +307,7 @@ static int decode_instructions(struct objtool_file *file)
307307
insn->offset = offset;
308308

309309
ret = arch_decode_instruction(file->elf, sec, offset,
310-
sec->len - offset,
310+
sec->sh.sh_size - offset,
311311
&insn->len, &insn->type,
312312
&insn->immediate,
313313
&insn->stack_ops);
@@ -349,9 +349,9 @@ static struct instruction *find_last_insn(struct objtool_file *file,
349349
{
350350
struct instruction *insn = NULL;
351351
unsigned int offset;
352-
unsigned int end = (sec->len > 10) ? sec->len - 10 : 0;
352+
unsigned int end = (sec->sh.sh_size > 10) ? sec->sh.sh_size - 10 : 0;
353353

354-
for (offset = sec->len - 1; offset >= end && !insn; offset--)
354+
for (offset = sec->sh.sh_size - 1; offset >= end && !insn; offset--)
355355
insn = find_insn(file, sec, offset);
356356

357357
return insn;
@@ -389,7 +389,7 @@ static int add_dead_ends(struct objtool_file *file)
389389
insn = find_insn(file, reloc->sym->sec, reloc->addend);
390390
if (insn)
391391
insn = list_prev_entry(insn, list);
392-
else if (reloc->addend == reloc->sym->sec->len) {
392+
else if (reloc->addend == reloc->sym->sec->sh.sh_size) {
393393
insn = find_last_insn(file, reloc->sym->sec);
394394
if (!insn) {
395395
WARN("can't find unreachable insn at %s+0x%x",
@@ -424,7 +424,7 @@ static int add_dead_ends(struct objtool_file *file)
424424
insn = find_insn(file, reloc->sym->sec, reloc->addend);
425425
if (insn)
426426
insn = list_prev_entry(insn, list);
427-
else if (reloc->addend == reloc->sym->sec->len) {
427+
else if (reloc->addend == reloc->sym->sec->sh.sh_size) {
428428
insn = find_last_insn(file, reloc->sym->sec);
429429
if (!insn) {
430430
WARN("can't find reachable insn at %s+0x%x",
@@ -1561,14 +1561,14 @@ static int read_unwind_hints(struct objtool_file *file)
15611561
return -1;
15621562
}
15631563

1564-
if (sec->len % sizeof(struct unwind_hint)) {
1564+
if (sec->sh.sh_size % sizeof(struct unwind_hint)) {
15651565
WARN("struct unwind_hint size mismatch");
15661566
return -1;
15671567
}
15681568

15691569
file->hints = true;
15701570

1571-
for (i = 0; i < sec->len / sizeof(struct unwind_hint); i++) {
1571+
for (i = 0; i < sec->sh.sh_size / sizeof(struct unwind_hint); i++) {
15721572
hint = (struct unwind_hint *)sec->data->d_buf + i;
15731573

15741574
reloc = find_reloc_by_dest(file->elf, sec, i * sizeof(*hint));

tools/objtool/elf.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,9 @@ static int read_sections(struct elf *elf)
286286
return -1;
287287
}
288288
}
289-
sec->len = sec->sh.sh_size;
290289

291290
if (sec->sh.sh_flags & SHF_EXECINSTR)
292-
elf->text_size += sec->len;
291+
elf->text_size += sec->sh.sh_size;
293292

294293
list_add_tail(&sec->list, &elf->sections);
295294
elf_hash_add(section, &sec->hash, sec->idx);
@@ -734,8 +733,8 @@ static int elf_add_string(struct elf *elf, struct section *strtab, char *str)
734733
data->d_size = strlen(str) + 1;
735734
data->d_align = 1;
736735

737-
len = strtab->len;
738-
strtab->len += data->d_size;
736+
len = strtab->sh.sh_size;
737+
strtab->sh.sh_size += data->d_size;
739738
strtab->changed = true;
740739

741740
return len;
@@ -790,9 +789,9 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
790789
data->d_align = 1;
791790
data->d_type = ELF_T_SYM;
792791

793-
sym->idx = symtab->len / sizeof(sym->sym);
792+
sym->idx = symtab->sh.sh_size / sizeof(sym->sym);
794793

795-
symtab->len += data->d_size;
794+
symtab->sh.sh_size += data->d_size;
796795
symtab->changed = true;
797796

798797
symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
@@ -814,7 +813,7 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
814813
data->d_align = 4;
815814
data->d_type = ELF_T_WORD;
816815

817-
symtab_shndx->len += 4;
816+
symtab_shndx->sh.sh_size += 4;
818817
symtab_shndx->changed = true;
819818
}
820819

@@ -855,7 +854,6 @@ struct section *elf_create_section(struct elf *elf, const char *name,
855854
}
856855

857856
sec->idx = elf_ndxscn(s);
858-
sec->len = size;
859857
sec->changed = true;
860858

861859
sec->data = elf_newdata(s);

tools/objtool/include/objtool/elf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct section {
3838
Elf_Data *data;
3939
char *name;
4040
int idx;
41-
unsigned int len;
4241
bool changed, text, rodata, noinstr;
4342
};
4443

tools/objtool/orc_gen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int orc_create(struct objtool_file *file)
204204

205205
/* Add a section terminator */
206206
if (!empty) {
207-
orc_list_add(&orc_list, &null, sec, sec->len);
207+
orc_list_add(&orc_list, &null, sec, sec->sh.sh_size);
208208
nr++;
209209
}
210210
}

tools/objtool/special.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ int special_get_alts(struct elf *elf, struct list_head *alts)
159159
if (!sec)
160160
continue;
161161

162-
if (sec->len % entry->size != 0) {
162+
if (sec->sh.sh_size % entry->size != 0) {
163163
WARN("%s size not a multiple of %d",
164164
sec->name, entry->size);
165165
return -1;
166166
}
167167

168-
nr_entries = sec->len / entry->size;
168+
nr_entries = sec->sh.sh_size / entry->size;
169169

170170
for (idx = 0; idx < nr_entries; idx++) {
171171
alt = malloc(sizeof(*alt));

0 commit comments

Comments
 (0)