[Mesa-dev] [PATCH 1/4] radeon: Teach radeon_elf_read() how to parse reloc information

Michel Dänzer michel at daenzer.net
Thu Jan 8 01:21:22 PST 2015


On 08.01.2015 06:03, Tom Stellard wrote:
> @@ -75,6 +76,34 @@ static void parse_symbol_table(Elf_Data *symbol_table_data,
>  	}
>  }
>  
> +static void parse_relocs(Elf *elf, Elf_Data *relocs, Elf_Data *symbols,
> +			unsigned symbol_sh_link,
> +			struct radeon_shader_binary *binary)
> +{
> +	unsigned i;
> +
> +	if (!relocs || !symbols || !binary->reloc_count) {
> +		return;
> +	}
> +	binary->relocs = CALLOC(binary->reloc_count,
> +			sizeof(struct radeon_shader_reloc));
> +	for (i = 0; i < binary->reloc_count; i++) {
> +		GElf_Sym symbol;
> +		GElf_Rel rel;
> +		unsigned offset;
> +		char *symbol_name;
> +		struct radeon_shader_reloc *reloc = &binary->relocs[i];
> +
> +		gelf_getrel(relocs, i, &rel);
> +		gelf_getsym(symbols, GELF_R_SYM(rel.r_info), &symbol);
> +		symbol_name = elf_strptr(elf, symbol_sh_link, symbol.st_name);
> +
> +		reloc->offset = rel.r_offset;
> +		reloc->name = MALLOC(strlen(symbol_name) + 1);
> +		strcpy(reloc->name, symbol_name);
> +	}
> +}

You could use strdup instead of MALLOC and strcpy.

I don't see any code freeing the memory allocated here, so it's probably
leaked.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the mesa-dev mailing list