Re: [PATCH v4 11/28] objtool: Trace instruction state changes during function validation

From: Alexandre Chartre

Date: Mon Nov 17 2025 - 02:36:03 EST



On 11/14/25 22:21, Josh Poimboeuf wrote:
On Thu, Nov 13, 2025 at 05:49:00PM +0100, Alexandre Chartre wrote:
+/*
+ * Return the name of a register. Note that the same static buffer
+ * is returned if the name is dynamically generated.
+ */
+static const char *cfi_reg_name(unsigned int reg)
+{
+ static char rname_buffer[CFI_REG_NAME_MAXLEN];
+
+ switch (reg) {
+ case CFI_UNDEFINED:
+ return "<undefined>";
+ case CFI_CFA:
+ return "cfa";
+ case CFI_SP_INDIRECT:
+ return "(sp)";
+ case CFI_BP_INDIRECT:
+ return "(bp)";
+ }
+
+ if (snprintf(rname_buffer, CFI_REG_NAME_MAXLEN, "r%d", reg) == 1)
+ return NULL;

An snprintf() error would either be -1 (error) or ">=
CFI_REG_NAME_MAXLEN" (truncation).

Also maybe return "(error)" or so, so the caller doesn't need to check
the return value.

Right, I will fix that.

+static void trace_cfi_reg(const char *prefix, int reg, const char *fmt,
+ int base_prev, int offset_prev,
+ int base_next, int offset_next)
+{
+ const char *rname;
+
+ if (base_prev == base_next && offset_prev == offset_next)
+ return;
+
+ if (prefix)
+ TRACE("%s:", prefix);
+
+ rname = cfi_reg_name(reg);
+
+ if (base_next == CFI_UNDEFINED) {
+ TRACE("%1$s=<undef> ", rname);
+ } else {
+ TRACE(fmt, rname,
+ cfi_reg_name(base_next), offset_next);

Since cfi_reg_name() can reuse the same static local buffer, rname and
cfi_reg_name(base_next) might point to the same string?


Yes, good catch. I will fix.

Thanks,

alex.