Re: [RFC 02/13] objtool: Create disassembly context
From: Josh Poimboeuf
Date: Tue Jun 10 2025 - 17:12:59 EST
On Fri, Jun 06, 2025 at 05:34:29PM +0200, Alexandre Chartre wrote:
> +struct disas_context *disas_context_create(struct objtool_file *file)
> +{
> + struct disas_context *dctx;
> +
> + dctx = malloc(sizeof(*dctx));
> + if (!dctx) {
> + WARN("failed too allocate disassembly context\n");
> + return NULL;
"too" -> "to".
Also, no newline needed for objtool warnings/error strings.
Also, might want to use WARN_GLIBC() here.
> +void disas_context_destroy(struct disas_context *dctx)
> +{
> + free(dctx);
> +}
In general we try to avoid freeing memory in objtool for performance
reasons, though this is the error path so I suppose it's harmless.
> -void disas_warned_funcs(struct objtool_file *file)
> +void disas_warned_funcs(struct disas_context *dctx)
> {
> struct symbol *sym;
> char *funcs = NULL, *tmp;
>
> - for_each_sym(file, sym) {
> + if (!dctx) {
> + ERROR("disassembly context is not defined");
> + return;
This will have come from the error in disas_context_create(), no need to
print an additional error.
> +++ b/tools/objtool/include/objtool/objtool.h
> @@ -47,6 +47,9 @@ int check(struct objtool_file *file);
> int orc_dump(const char *objname);
> int orc_create(struct objtool_file *file);
>
> -void disas_warned_funcs(struct objtool_file *file);
> +struct disas_context;
> +struct disas_context *disas_context_create(struct objtool_file *file);
> +void disas_context_destroy(struct disas_context *dctx);
> +void disas_warned_funcs(struct disas_context *dctx);
Can these go in a new disas.h file?
--
Josh