From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E768821FF24 for ; Wed, 6 Aug 2025 21:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754514593; cv=none; b=YxR1UCgfABEAypZ0DEQ3CJDOCZxA8KTnEWu6E238iQXbl/j5PzheqTnsqFM0dUcWKFZye75gmvUXYfUX+eBLsJoC9/Cgqvb9UJgAzOp1U/X/arj2mobDt11urE5yFx6p+3PhSB5qzbzEcIhOsqkZIVuNviKJ16wtT9vlRNRIuWM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754514593; c=relaxed/simple; bh=sKHY4F9olfk7KN/7Ro9gMf4O20t37mefSlqpuVxU44A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=pcTkoeHixP4IUFQWkfvz1YZ45/ZSU+Lw57/iRbQ51Cx9RTZafeuTmGrsecdWqLRBPb++3ei3GuMEsJ64XcLtIc57kUorrDGvgbaSQH/mxUnqlgt2rohLYAvTnQUd2QdUZ4hP61zgikQOn38voADPd/IppwIDkspjVXiq7qgEtZo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gentoo.org; spf=pass smtp.mailfrom=gentoo.org; arc=none smtp.client-ip=140.211.166.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gentoo.org Received: from mop.sam.mop (unknown [82.8.138.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sam) by smtp.gentoo.org (Postfix) with ESMTPSA id 95F86340EE5; Wed, 06 Aug 2025 21:09:50 +0000 (UTC) From: Sam James To: Sean Young Cc: James Le Cuirot , linux-media@vger.kernel.org Subject: Re: [PATCH] meson: Allow BPF code to be built with GCC In-Reply-To: Organization: Gentoo References: <20250803081759.13952-1-chewi@gentoo.org> <87y0rxyfnj.fsf@gentoo.org> <8734a54cx5.fsf@gentoo.org> User-Agent: mu4e 1.12.12; emacs 31.0.50 Date: Wed, 06 Aug 2025 22:09:47 +0100 Message-ID: <87bjos17j8.fsf@gentoo.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Sean Young writes: > On Tue, Aug 05, 2025 at 11:32:54PM +0100, Sam James wrote: >> Sam James writes: >> >> > Sean Young writes: >> > >> >> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote: >> >>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote: >> >>> > Disclaimer: I haven't actually tested the result of the GCC build. >> >>> >> >>> Let me test this. >> >> >> >> It doesn't work: >> >> >> >> # ir-keytable -p ./imon_rsc.o >> >> Protocols changed to >> >> symbol has unknown section 6 >> >> bpf_load_program() err=Permission denied >> >> 0: R1=ctx() R10=fp0 >> >> 0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx() >> >> 1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000???? >> >> 2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0 >> >> 3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16) >> >> 5: (07) r2 += -4 ; R2_w=fp-4 >> >> 6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16) >> >> 7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16) >> >> 8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16) >> >> 9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx() >> >> 10: (bf) r1 = r0 ; >> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; >> >> 0xffffffff)) >> >> R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; >> >> 0xffffffff)) >> >> 11: (bf) r2 = r0 ; >> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; >> >> 0xffffffff)) >> >> R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; >> >> 0xffffffff)) >> >> 12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000)) >> >> 13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000)) >> >> 14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000)) >> >> 15: (16) if w1 == 0x3000000 goto pc+31 47: >> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) >> >> R1=0x3000000 >> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; >> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000???? >> >> 47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) >> >> 48: (16) if w5 == 0x1 goto pc+7 56: >> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) >> >> R1=0x3000000 >> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; >> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0 >> >> fp-8=0000???? >> >> 56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff)) >> >> 57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff)) >> >> 58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16) >> >> 59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) >> >> 60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1)) >> >> 61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16) >> >> 62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf)) >> >> 63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14) >> >> 64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf)) >> >> 65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c)) >> >> 66: (18) r2 = 0x3c ; R2_w=60 >> >> 68: (18) r9 = 0x0 ; R9_w=0 >> >> 70: (0f) r2 += r3 ; >> >> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0; >> >> 0x7c)) >> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; >> >> 0x3c)) >> >> 71: (0f) r9 += r3 ; >> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; >> >> 0x3c)) >> >> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; >> >> 0x3c)) >> >> 72: (81) r2 = *(s32 *)(r2 +0) >> >> R2 invalid mem access 'scalar' >> >> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1 >> > >> > I'll have a look. Thanks. >> >> OK, I can't reproduce it yet because I don't have the hardware (using >> loopback doesn't seem to be sufficient, even with Clang). >> >> Could you get the full bpf-* gcc invocation with `ninja --verbose`, and >> then append -save-temps to it, and attach the .i it makes? > > Works fine with rc-loopback. > Huh, okay. I couldn't get the verify failure to spit out. > The problem is that gcc compiles this down to a lookup table which is then > stored in the .rodata section. > > https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/imon_rsc.c#n97 > > Then ir-keytable fails to load and relocate the rodata section. Note the > error: > > symbol has unknown section 6 > > section 6 is the rodata section. > > ir-keytable simply has no handling for .rodata right now. I am not sure how > bpf handles .rodata (if at all), needs more investigation. I'd spotted that and naively assumed it was unrelated given I couldn't get the verify failure even with Clang. Mea culpa! > > > Sean sam