]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
objtool: Remove redundant 'len' field from struct section
authorJoe Lawrence <joe.lawrence@redhat.com>
Sun, 22 Aug 2021 22:50:37 +0000 (18:50 -0400)
committerJosh Poimboeuf <jpoimboe@redhat.com>
Tue, 5 Oct 2021 19:03:21 +0000 (12:03 -0700)
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 <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20210822225037.54620-3-joe.lawrence@redhat.com
Cc: Andy Lavr <andy.lavr@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
tools/objtool/check.c
tools/objtool/elf.c
tools/objtool/include/objtool/elf.h
tools/objtool/orc_gen.c
tools/objtool/special.c

index e5947fbb9e7a6d602686af947c5caf1f2158157f..06b5c164ae9318150aacdfd23a9a0fd90df49e39 100644 (file)
@@ -292,7 +292,7 @@ static int decode_instructions(struct objtool_file *file)
                    !strcmp(sec->name, ".entry.text"))
                        sec->noinstr = true;
 
-               for (offset = 0; offset < sec->len; offset += insn->len) {
+               for (offset = 0; offset < sec->sh.sh_size; offset += insn->len) {
                        insn = malloc(sizeof(*insn));
                        if (!insn) {
                                WARN("malloc failed");
@@ -307,7 +307,7 @@ static int decode_instructions(struct objtool_file *file)
                        insn->offset = offset;
 
                        ret = arch_decode_instruction(file->elf, sec, offset,
-                                                     sec->len - offset,
+                                                     sec->sh.sh_size - offset,
                                                      &insn->len, &insn->type,
                                                      &insn->immediate,
                                                      &insn->stack_ops);
@@ -349,9 +349,9 @@ static struct instruction *find_last_insn(struct objtool_file *file,
 {
        struct instruction *insn = NULL;
        unsigned int offset;
-       unsigned int end = (sec->len > 10) ? sec->len - 10 : 0;
+       unsigned int end = (sec->sh.sh_size > 10) ? sec->sh.sh_size - 10 : 0;
 
-       for (offset = sec->len - 1; offset >= end && !insn; offset--)
+       for (offset = sec->sh.sh_size - 1; offset >= end && !insn; offset--)
                insn = find_insn(file, sec, offset);
 
        return insn;
@@ -389,7 +389,7 @@ static int add_dead_ends(struct objtool_file *file)
                insn = find_insn(file, reloc->sym->sec, reloc->addend);
                if (insn)
                        insn = list_prev_entry(insn, list);
-               else if (reloc->addend == reloc->sym->sec->len) {
+               else if (reloc->addend == reloc->sym->sec->sh.sh_size) {
                        insn = find_last_insn(file, reloc->sym->sec);
                        if (!insn) {
                                WARN("can't find unreachable insn at %s+0x%x",
@@ -424,7 +424,7 @@ reachable:
                insn = find_insn(file, reloc->sym->sec, reloc->addend);
                if (insn)
                        insn = list_prev_entry(insn, list);
-               else if (reloc->addend == reloc->sym->sec->len) {
+               else if (reloc->addend == reloc->sym->sec->sh.sh_size) {
                        insn = find_last_insn(file, reloc->sym->sec);
                        if (!insn) {
                                WARN("can't find reachable insn at %s+0x%x",
@@ -1561,14 +1561,14 @@ static int read_unwind_hints(struct objtool_file *file)
                return -1;
        }
 
-       if (sec->len % sizeof(struct unwind_hint)) {
+       if (sec->sh.sh_size % sizeof(struct unwind_hint)) {
                WARN("struct unwind_hint size mismatch");
                return -1;
        }
 
        file->hints = true;
 
-       for (i = 0; i < sec->len / sizeof(struct unwind_hint); i++) {
+       for (i = 0; i < sec->sh.sh_size / sizeof(struct unwind_hint); i++) {
                hint = (struct unwind_hint *)sec->data->d_buf + i;
 
                reloc = find_reloc_by_dest(file->elf, sec, i * sizeof(*hint));
index 8676c759872810d1e7cff3f7e2c5adc061164700..b18f0055b50b8018624331bbae9181b0d2eb730c 100644 (file)
@@ -286,10 +286,9 @@ static int read_sections(struct elf *elf)
                                return -1;
                        }
                }
-               sec->len = sec->sh.sh_size;
 
                if (sec->sh.sh_flags & SHF_EXECINSTR)
-                       elf->text_size += sec->len;
+                       elf->text_size += sec->sh.sh_size;
 
                list_add_tail(&sec->list, &elf->sections);
                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)
        data->d_size = strlen(str) + 1;
        data->d_align = 1;
 
-       len = strtab->len;
-       strtab->len += data->d_size;
+       len = strtab->sh.sh_size;
+       strtab->sh.sh_size += data->d_size;
        strtab->changed = true;
 
        return len;
@@ -790,9 +789,9 @@ struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
        data->d_align = 1;
        data->d_type = ELF_T_SYM;
 
-       sym->idx = symtab->len / sizeof(sym->sym);
+       sym->idx = symtab->sh.sh_size / sizeof(sym->sym);
 
-       symtab->len += data->d_size;
+       symtab->sh.sh_size += data->d_size;
        symtab->changed = true;
 
        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)
                data->d_align = 4;
                data->d_type = ELF_T_WORD;
 
-               symtab_shndx->len += 4;
+               symtab_shndx->sh.sh_size += 4;
                symtab_shndx->changed = true;
        }
 
@@ -855,7 +854,6 @@ struct section *elf_create_section(struct elf *elf, const char *name,
        }
 
        sec->idx = elf_ndxscn(s);
-       sec->len = size;
        sec->changed = true;
 
        sec->data = elf_newdata(s);
index e34395047530996207733546dbb38b03ed413510..075d8291b8546bda92af6e735cf58ad202c27069 100644 (file)
@@ -38,7 +38,6 @@ struct section {
        Elf_Data *data;
        char *name;
        int idx;
-       unsigned int len;
        bool changed, text, rodata, noinstr;
 };
 
index dc9b7dd314b05fbc0780e5699931476cdfdbe6c6..b5865e2450cbb5568446e4a4aad53d14f4d724d6 100644 (file)
@@ -204,7 +204,7 @@ int orc_create(struct objtool_file *file)
 
                /* Add a section terminator */
                if (!empty) {
-                       orc_list_add(&orc_list, &null, sec, sec->len);
+                       orc_list_add(&orc_list, &null, sec, sec->sh.sh_size);
                        nr++;
                }
        }
index 83d5f969bcb00828d326c8827cae5782aa0c711c..06c3eacab3d53453706e795b01a02b781838a189 100644 (file)
@@ -159,13 +159,13 @@ int special_get_alts(struct elf *elf, struct list_head *alts)
                if (!sec)
                        continue;
 
-               if (sec->len % entry->size != 0) {
+               if (sec->sh.sh_size % entry->size != 0) {
                        WARN("%s size not a multiple of %d",
                             sec->name, entry->size);
                        return -1;
                }
 
-               nr_entries = sec->len / entry->size;
+               nr_entries = sec->sh.sh_size / entry->size;
 
                for (idx = 0; idx < nr_entries; idx++) {
                        alt = malloc(sizeof(*alt));