Lines Matching +full:re +full:-
1 .. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
12 LLVM BPF backend records each relocation with the following 16-byte
31 Compiled with ``clang --target=bpf -O2 -c test.c``, the following is
32 the code with ``llvm-objdump -dr test.o``::
52 The following ``llvm-readelf -r test.o`` shows the binary values of the four
66 The following is the symbol table with ``llvm-readelf -s test.o``::
100 section offset for static variables/functions. The non-section-offset
115 10 R_BPF_64_32 call insn 32 r_offset + 4 (S + A) / 8 - 1
118 The actual to-be-relocated data (0 or section offset)
125 In another case, ``R_BPF_64_ABS64`` relocation type is used for normal 64-bit data.
126 The actual to-be-relocated data is stored at ``r_offset`` and the read/write data
130 Both ``R_BPF_64_ABS32`` and ``R_BPF_64_NODYLD32`` types are for 32-bit data.
139 ``(S + A) / 8 - 1``.
160 Compiled with ``clang --target=bpf -O2 -c test.c``, we will have
161 following code with `llvm-objdump -dr test.o``::
168 2: 85 10 00 00 ff ff ff ff call -1
195 so the ``call`` instruction offset is ``(0 + 0)/8 - 1 = -1``.
197 offset ``0x18``, so the ``call`` instruction offset is ``(0 + 0x18)/8 - 1 = 2``.
206 Compiled with ``clang --target=bpf -O2 -g -c test.c``, we will see a
208 ``llvm-readelf -r test.o``::
214 The relocation says the first 8-byte of ``.data`` section should be
217 With ``llvm-readelf`` output, we can see that dwarf sections have a bunch of
244 .. _btf-co-re-relocations:
247 CO-RE Relocations
250 From object file point of view CO-RE mechanism is implemented as a set
251 of CO-RE specific relocation records. These relocation records are not
256 CO-RE relocations are applied to BPF instructions to update immediate
269 There are several kinds of CO-RE relocations that could be split in
272 * Field-based - patch instruction with field related information, e.g.
276 * Type-based - patch instruction with type related information, e.g.
280 * Enum-based - patch instruction with enum related information, e.g.
286 .. code-block:: c
292 BPF_CORE_FIELD_SIGNED = 3, /* field signedness (0 - unsigned, 1 - signed) */
293 BPF_CORE_FIELD_LSHIFT_U64 = 4, /* bitfield-specific left bitshift */
294 BPF_CORE_FIELD_RSHIFT_U64 = 5, /* bitfield-specific right bitshift */
310 .. code-block:: c
313 is_signed = relo(s->f, BPF_CORE_FIELD_SIGNED)
314 off = relo(s->f, BPF_CORE_FIELD_BYTE_OFFSET)
315 sz = relo(s->f, BPF_CORE_FIELD_BYTE_SIZE)
316 l = relo(s->f, BPF_CORE_FIELD_LSHIFT_U64)
317 r = relo(s->f, BPF_CORE_FIELD_RSHIFT_U64)
347 CO-RE Relocation Record
352 .. code-block:: c
361 * ``insn_off`` - instruction offset (in bytes) within a code section
364 * ``type_id`` - BTF type ID of the "root" (containing) entity of a
367 * ``access_str_off`` - offset into corresponding .BTF string section.
370 * for field-based relocations, string encodes an accessed field using
376 .. code-block:: c
390 * Access to ``s->a`` would be encoded as ``0:0`` as well.
391 * Access to ``s->b`` would be encoded as ``0:1``:
403 * for type-based relocations, string is expected to be just "0";
405 * for enum value-based relocations, string contains an index of enum
408 * ``kind`` - one of ``enum bpf_core_relo_kind``.
410 .. _GEP: https://llvm.org/docs/LangRef.html#getelementptr-instruction
414 CO-RE Relocation Examples
419 .. code-block:: c
431 .. code-block::
448 .. code-block:: c
451 *g = s->a;
452 s->a = 1;
457 00: CO-RE <byte_off> [2] struct foo::a (0:0)
460 10: CO-RE <byte_off> [2] struct foo::a (0:0)
464 All relocation kinds could be requested via built-in functions.
465 E.g. field-based relocations:
467 .. code-block:: c
470 *g = __builtin_preserve_field_info(s->b, 0 /* field byte offset */);
471 *g = __builtin_preserve_field_info(s->b, 1 /* field byte size */);
472 *g = __builtin_preserve_field_info(s->b, 2 /* field existence */);
473 *g = __builtin_preserve_field_info(s->b, 3 /* field signedness */);
474 *g = __builtin_preserve_field_info(s->c, 4 /* bitfield left shift */);
475 *g = __builtin_preserve_field_info(s->c, 5 /* bitfield right shift */);
480 20: CO-RE <byte_off> [2] struct foo::b (0:1)
483 30: CO-RE <byte_sz> [2] struct foo::b (0:1)
486 40: CO-RE <field_exists> [2] struct foo::b (0:1)
489 50: CO-RE <signed> [2] struct foo::b (0:1)
492 60: CO-RE <lshift_u64> [2] struct foo::c (0:2)
495 70: CO-RE <rshift_u64> [2] struct foo::c (0:2)
500 Type-based relocations:
502 .. code-block:: c
514 88: CO-RE <type_exists> [2] struct foo
517 98: CO-RE <type_size> [2] struct foo
520 a8: CO-RE <type_matches> [2] struct foo
523 b8: CO-RE <local_type_id> [2] struct foo
526 d0: CO-RE <target_type_id> [2] struct foo
530 Enum-based relocations:
532 .. code-block:: c
541 f0: CO-RE <enumval_exists> [16] enum bar::U = 0
544 108: CO-RE <enumval_value> [16] enum bar::V = 1