[DTrace-devel] [PATCH 3/6] bpf: implement additional relocation types

Kris Van Hees kris.van.hees at oracle.com
Thu Jan 30 23:14:55 UTC 2025


On Thu, Jan 30, 2025 at 05:53:01PM -0500, Eugene Loh wrote:
> Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
> and an explanation in the commit msg what motivates this patch?

Sure, though I think it is actually quite obvious for anyone looking at the
documented BPF relocation types, and the relocations generated by gcc for
BPF code.

> On 1/28/25 01:31, Kris Van Hees wrote:
> > Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> > ---
> >   include/port.h     | 6 ++++++
> >   libdtrace/dt_as.c  | 2 +-
> >   libdtrace/dt_cc.c  | 3 ++-
> >   libdtrace/dt_dis.c | 9 ++++++++-
> >   4 files changed, 17 insertions(+), 3 deletions(-)
> > 
> > diff --git a/include/port.h b/include/port.h
> > index 6ce8611e..0aadacb8 100644
> > --- a/include/port.h
> > +++ b/include/port.h
> > @@ -88,6 +88,12 @@ pid_t gettid(void);
> >   #ifndef R_BPF_64_64
> >   #define R_BPF_64_64		1
> >   #endif
> > +#ifndef R_BPF_64_ABS64
> > +#define R_BPF_64_ABS64		2
> > +#endif
> > +#ifndef R_BPF_64_ABS32
> > +#define R_BPF_64_ABS32		3
> > +#endif
> >   #ifndef R_BPF_64_32
> >   #define R_BPF_64_32		10
> >   #endif
> > diff --git a/libdtrace/dt_as.c b/libdtrace/dt_as.c
> > index a634b855..d3126f9a 100644
> > --- a/libdtrace/dt_as.c
> > +++ b/libdtrace/dt_as.c
> > @@ -492,7 +492,7 @@ fail:
> >   			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;
> > +				rp->dofr_type = R_BPF_64_ABS32;
> >   				break;
> >   			case BPF_LD | BPF_IMM | BPF_DW:		/* lddw */
> >   				rp->dofr_type = R_BPF_64_64;
> > diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
> > index eebd923c..29cfbd84 100644
> > --- a/libdtrace/dt_cc.c
> > +++ b/libdtrace/dt_cc.c
> > @@ -1266,7 +1266,8 @@ dt_link_resolve(dtrace_hdl_t *dtp, dtrace_difo_t *dp)
> >   		if (rp->dofr_type == R_BPF_64_64) {
> >   			buf[ioff].imm = val & 0xffffffff;
> >   			buf[ioff + 1].imm = val >> 32;
> > -		} else if (rp->dofr_type == R_BPF_64_32)
> > +		} else if (rp->dofr_type == R_BPF_64_32 ||
> > +			   rp->dofr_type == R_BPF_64_ABS32)
> >   			buf[ioff].imm = (uint32_t)val;
> >   	}
> >   }
> > diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
> > index d983c099..b2e66754 100644
> > --- a/libdtrace/dt_dis.c
> > +++ b/libdtrace/dt_dis.c
> > @@ -639,6 +639,12 @@ dt_dis_rtab(const char *rtag, const dtrace_difo_t *dp, FILE *fp,
> >   		case R_BPF_64_32:
> >   			tstr = "R_BPF_INSN_DISP32";
> >   			break;
> > +		case R_BPF_64_ABS64:
> > +			tstr = "R_BPF_DATA_64";
> > +			break;
> > +		case R_BPF_64_ABS32:
> > +			tstr = "R_BPF_DATA_32";
> > +			break;
> >   		default:
> >   			tstr = "R_???";
> >   		}
> > @@ -853,7 +859,8 @@ dt_dis_difo(const dtrace_difo_t *dp, FILE *fp, const dt_ident_t *idp,
> >   		for (; cnt; cnt--, rp++) {
> >   			if (rp->dofr_offset < i * sizeof(uint64_t))
> >   				continue;
> > -			if (rp->dofr_offset == i * sizeof(uint64_t))
> > +			if (rp->dofr_offset >= i * sizeof(uint64_t) &&
> > +			    rp->dofr_offset < (i + 1) * sizeof(uint64_t))
> >   				rname = dt_difo_getstr(dp, rp->dofr_name);
> >   			break;



More information about the DTrace-devel mailing list