On Sunday, 5 January 2025 at 14:17:29 UTC, data pulverizer wrote:
```d
//hello_world.d

@system:
@nogc:
extern(C):

@(ldc.attributes.section("license")) __gshared immutable(char)[3] LICENSE = "GPL";

import core.stdc.stdlib;
import core.stdc.stdarg;
import ldc.attributes;

long bpf_trace_printk(const(char)* fmt, uint fmt_size, ...);
@(ldc.attributes.section("xdp_md")) struct xdp_md;

@(ldc.attributes.section("xdp")) int xdp_prog(xdp_md* ctx)
{
    bpf_trace_printk("Hello, eBPF!\n", 14);
    return 0;
}
```

Just fix

```d
@system:
@nogc:
nothrow:
extern(C):

import ldc.attributes;

@(ldc.attributes.section("license"))
__gshared immutable(char)[4] LICENSE = "GPL\0";

struct xdp_md
{
    uint data;
    uint data_end;
    uint data_meta;
    uint ingress_ifindex;
    uint rx_queue_index;
    uint egress_ifindex;
}

enum int BPF_FUNC_trace_printk = 6;

alias BpfTracePrintk =
extern(C) long function(const(char)* fmt, uint fmt_size, ...) @nogc nothrow;

enum BpfTracePrintk bpf_trace_printk = cast(BpfTracePrintk)BPF_FUNC_trace_printk;

enum int XDP_PASS = 2;

@(ldc.attributes.section("xdp"))
int xdp_prog(xdp_md* ctx)
{
    bpf_trace_printk("Hello, eBPF!\n", 14);
    return XDP_PASS;
}
```

Build:

```sh
ldc2 -c -O2 -release -betterC --nogc -fno-moduleinfo --march=bpf hello_world.d -of=hello_world_d.o llvm-objcopy --remove-section .eh_frame --remove-section .rel.eh_frame hello_world_d.o
```
  • Issue eBPF kerne... data pulverizer via Digitalmars-d-learn
    • Re: Issue e... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Iss... data pulverizer via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... data pulverizer via Digitalmars-d-learn
            • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Issue e... Alexander Zhirov via Digitalmars-d-learn

Reply via email to