[DTrace-devel] [PATCH] Add reloc support for the add immediate instruction

Kris Van Hees kris.van.hees at oracle.com
Wed Mar 9 23:49:44 UTC 2022


On Wed, Mar 09, 2022 at 06:41:01PM -0500, Eugene Loh via DTrace-devel wrote:
> Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
> but any tests?

No tests possible because it requires code to be added to the code generator
to actually trigger this relocation, and that is not possible without having
the support for it in the assembler.  The associative array support will be
making use of this feature and that serves as the test.
> 
> On 3/9/22 4:42 PM, Kris Van Hees via DTrace-devel wrote:
> > This patch also reworks a somewhat ugly compound conditional statement
> > into a switch statement.
> > 
> > Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> > ---
> >   libdtrace/dt_as.c | 35 +++++++++++++++++++----------------
> >   1 file changed, 19 insertions(+), 16 deletions(-)
> > 
> > diff --git a/libdtrace/dt_as.c b/libdtrace/dt_as.c
> > index 8ae7bd96..a634b855 100644
> > --- a/libdtrace/dt_as.c
> > +++ b/libdtrace/dt_as.c
> > @@ -279,6 +279,7 @@ dt_as(dt_pcb_t *pcb)
> >   		case BPF_ST | BPF_MEM | BPF_W:		/* stw */
> >   		case BPF_ST | BPF_MEM | BPF_DW:		/* stdw */
> >   		case BPF_ALU64 | BPF_MOV | BPF_K:	/* mov */
> > +		case BPF_ALU64 | BPF_ADD | BPF_K:	/* add */
> >   			if (idp->di_flags & DT_IDFLG_BPF)
> >   				brel++;
> >   			else
> > @@ -486,27 +487,29 @@ fail:
> >   			if (!nodef)
> >   				dt_as_undef(idp, i);
> > -			if (dip->di_instr.code ==
> > -					(BPF_LD | BPF_IMM | BPF_DW))
> > -				rp->dofr_type = R_BPF_64_64;
> > -			else if (dip->di_instr.code ==
> > -					(BPF_ST | BPF_MEM | BPF_W))
> > -				rp->dofr_type = R_BPF_64_32;
> > -			else if (dip->di_instr.code ==
> > -					(BPF_ST | BPF_MEM | BPF_DW))
> > -				rp->dofr_type = R_BPF_64_32;
> > -			else if (dip->di_instr.code ==
> > -					(BPF_ALU64 | BPF_MOV | BPF_K))
> > -				rp->dofr_type = R_BPF_64_32;
> > -			else if (dip->di_instr.code ==
> > -					(BPF_JMP | BPF_CALL) &&
> > -				 dip->di_instr.src_reg == BPF_PSEUDO_CALL)
> > +			switch (dip->di_instr.code) {
> > +			case BPF_ST | BPF_MEM | BPF_W:		/* stw */
> > +			case BPF_ST | BPF_MEM | BPF_DW:		/* stdw */
> > +			case BPF_ALU64 | BPF_MOV | BPF_K:	/* mov */
> > +			case BPF_ALU64 | BPF_ADD | BPF_K:	/* add */
> >   				rp->dofr_type = R_BPF_64_32;
> > -			else
> > +				break;
> > +			case BPF_LD | BPF_IMM | BPF_DW:		/* lddw */
> > +				rp->dofr_type = R_BPF_64_64;
> > +				break;
> > +			case BPF_JMP | BPF_CALL:	/* call */
> > +				if (dip->di_instr.src_reg == BPF_PSEUDO_CALL) {
> > +					rp->dofr_type = R_BPF_64_32;
> > +					break;
> > +				}
> > +
> > +				/* fall-through */
> > +			default:
> >   				xyerror(D_UNKNOWN, "unexpected asm relocation "
> >   					"for opcode 0x%x (@%d, %s)\n",
> >   					dip->di_instr.code, i - 1,
> >   					idp->di_name);
> > +			}
> >   			soff = dt_strtab_insert(dtp->dt_ccstab, idp->di_name);
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list