Re: [PATCH] objtool: Fix symbol creation

Josh Poimboeuf
2022-05-18T17:36:21Z

On Wed, May 18, 2022 at 09:41:52AM +0200, Peter Zijlstra wrote:
> +static int elf_update_symbol(struct elf *elf, struct section *symtab,
> + struct section *symtab_shndx, struct symbol *sym)
> {
> - Elf_Data *data, *shndx_data = NULL;
> - Elf32_Word first_non_local;
> - struct symbol *sym;
> - Elf_Scn *s;
> -
> - first_non_local = symtab->sh.sh_info;
> -
> - sym = find_symbol_by_index(elf, first_non_local);
> - if (!sym) {
> - WARN("no non-local symbols !?");
> - return first_non_local;
> - }
> + Elf_Data *symtab_data = NULL, *shndx_data = NULL;
> + Elf64_Xword entsize = symtab->sh.sh_entsize;
> + Elf32_Word shndx = sym->sec->idx;

So if it's a global UNDEF symbol then I think 'sym->sec' can be NULL and
this blows up?

> + for (;;) {
> + /* get next data descriptor for the relevant sections */
> + symtab_data = elf_getdata(s, symtab_data);
> + if (t)
> + shndx_data = elf_getdata(t, shndx_data);
> +
> + /* end-of-list */
> + if (!symtab_data) {
> + /* if @idx == 0, it's the next contiguous entry, create it */
> + if (!idx) {
> + void *buf;

Could just do the "index out of range warning" here to reduce the
indentation level.

> + /* setup extended section index magic and write the symbol */
> + if (shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) {

> + sym->sym.st_shndx = shndx;
> + if (!shndx_data)
> + shndx = 0;

I think this '0' is SHN_UNDEF?

Also shouldn't 'sym->sym.st_shndx' get the same value?

--
Josh