<feed xmlns='http://www.w3.org/2005/Atom'>
<title>wireguard-linux/tools/lib/bpf/linker.c, branch jd/bump-compilers</title>
<subtitle>WireGuard for the Linux kernel</subtitle>
<id>https://git.zx2c4.com/wireguard-linux/atom/tools/lib/bpf/linker.c?h=jd%2Fbump-compilers</id>
<link rel='self' href='https://git.zx2c4.com/wireguard-linux/atom/tools/lib/bpf/linker.c?h=jd%2Fbump-compilers'/>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/'/>
<updated>2024-06-21T18:00:17Z</updated>
<entry>
<title>libbpf: Checking the btf_type kind when fixing variable offsets</title>
<updated>2024-06-21T18:00:17Z</updated>
<author>
<name>Donglin Peng</name>
<email>dolinux.peng@gmail.com</email>
</author>
<published>2024-06-19T12:23:55Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=cc5083d1f3881624ad2de1f3cbb3a07e152cb254'/>
<id>urn:sha1:cc5083d1f3881624ad2de1f3cbb3a07e152cb254</id>
<content type='text'>
I encountered an issue when building the test_progs from the repository [1]:

  $ pwd
  /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/

  $ make test_progs V=1
  [...]
  ./tools/sbin/bpftool gen object ./ip_check_defrag.bpf.linked2.o ./ip_check_defrag.bpf.linked1.o
  libbpf: failed to find symbol for variable 'bpf_dynptr_slice' in section '.ksyms'
  Error: failed to link './ip_check_defrag.bpf.linked1.o': No such file or directory (2)
  [...]

Upon investigation, I discovered that the btf_types referenced in the '.ksyms'
section had a kind of BTF_KIND_FUNC instead of BTF_KIND_VAR:

  $ bpftool btf dump file ./ip_check_defrag.bpf.linked1.o
  [...]
  [2] DATASEC '.ksyms' size=0 vlen=2
        type_id=16 offset=0 size=0 (FUNC 'bpf_dynptr_from_skb')
        type_id=17 offset=0 size=0 (FUNC 'bpf_dynptr_slice')
  [...]
  [16] FUNC 'bpf_dynptr_from_skb' type_id=82 linkage=extern
  [17] FUNC 'bpf_dynptr_slice' type_id=85 linkage=extern
  [...]

For a detailed analysis, please refer to [2]. We can add a kind checking to
fix the issue.

  [1] https://github.com/eddyz87/bpf/tree/binsort-btf-dedup
  [2] https://lore.kernel.org/all/0c0ef20c-c05e-4db9-bad7-2cbc0d6dfae7@oracle.com/

Fixes: 8fd27bf69b86 ("libbpf: Add BPF static linker BTF and BTF.ext support")
Signed-off-by: Donglin Peng &lt;dolinux.peng@gmail.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Reviewed-by: Alan Maguire &lt;alan.maguire@oracle.com&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20240619122355.426405-1-dolinux.peng@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Make use of BTF field iterator in BPF linker code</title>
<updated>2024-06-05T14:54:32Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andrii@kernel.org</email>
</author>
<published>2024-06-05T00:16:26Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=2bce2c1cb2f0acbf619737a10575f99df0c43984'/>
<id>urn:sha1:2bce2c1cb2f0acbf619737a10575f99df0c43984</id>
<content type='text'>
Switch all BPF linker code dealing with iterating BTF type ID and string
offset fields to new btf_field_iter facilities.

Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Tested-by: Alan Maguire &lt;alan.maguire@oracle.com&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Acked-by: Jiri Olsa &lt;jolsa@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240605001629.4061937-3-andrii@kernel.org
</content>
</entry>
<entry>
<title>libbpf: Add missed btf_ext__raw_data() API</title>
<updated>2024-02-01T21:16:12Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andrii@kernel.org</email>
</author>
<published>2024-02-01T17:20:26Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=b9551da8cf3ade01a50316df8a618fd945723ee0'/>
<id>urn:sha1:b9551da8cf3ade01a50316df8a618fd945723ee0</id>
<content type='text'>
Another API that was declared in libbpf.map but actual implementation
was missing. btf_ext__get_raw_data() was intended as a discouraged alias
to consistently-named btf_ext__raw_data(), so make this an actuality.

Fixes: 20eccf29e297 ("libbpf: hide and discourage inconsistently named getters")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20240201172027.604869-5-andrii@kernel.org
</content>
</entry>
<entry>
<title>libbpf: Skip DWARF sections in linker sanity check</title>
<updated>2023-12-21T09:05:15Z</updated>
<author>
<name>Alyssa Ross</name>
<email>hi@alyssa.is</email>
</author>
<published>2023-12-19T11:03:24Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=812d8bf87678f77055b575d20636fdbbbf15edaf'/>
<id>urn:sha1:812d8bf87678f77055b575d20636fdbbbf15edaf</id>
<content type='text'>
clang can generate (with -g -Wa,--compress-debug-sections) 4-byte
aligned DWARF sections that declare themselves to be 8-byte aligned in
the section header.  Since DWARF sections are dropped during linking
anyway, just skip running the sanity checks on them.

Reported-by: Sergei Trofimovich &lt;slyich@gmail.com&gt;
Suggested-by: Andrii Nakryiko &lt;andrii.nakryiko@gmail.com&gt;
Signed-off-by: Alyssa Ross &lt;hi@alyssa.is&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Closes: https://lore.kernel.org/bpf/ZXcFRJVKbKxtEL5t@nz.home/
Link: https://lore.kernel.org/bpf/20231219110324.8989-1-hi@alyssa.is
</content>
</entry>
<entry>
<title>libbpf: Add pr_warn() for EINVAL cases in linker_sanity_check_elf</title>
<updated>2023-12-09T01:11:18Z</updated>
<author>
<name>Sergei Trofimovich</name>
<email>slyich@gmail.com</email>
</author>
<published>2023-12-08T21:51:00Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=32fa058398624166dd04ff4af49cfef69c94abbc'/>
<id>urn:sha1:32fa058398624166dd04ff4af49cfef69c94abbc</id>
<content type='text'>
Before the change on `i686-linux` `systemd` build failed as:

    $ bpftool gen object src/core/bpf/socket_bind/socket-bind.bpf.o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    Error: failed to link 'src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o': Invalid argument (22)

After the change it fails as:

    $ bpftool gen object src/core/bpf/socket_bind/socket-bind.bpf.o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    libbpf: ELF section #9 has inconsistent alignment addr=8 != d=4 in src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    Error: failed to link 'src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o': Invalid argument (22)

Now it's slightly easier to figure out what is wrong with an ELF file.

Signed-off-by: Sergei Trofimovich &lt;slyich@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20231208215100.435876-1-slyich@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Fix double-free when linker processes empty sections</title>
<updated>2023-03-28T03:02:15Z</updated>
<author>
<name>Eduard Zingerman</name>
<email>eddyz87@gmail.com</email>
</author>
<published>2023-03-28T00:47:38Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=d08ab82f59d55b0e5acfeb453081278dfc33f232'/>
<id>urn:sha1:d08ab82f59d55b0e5acfeb453081278dfc33f232</id>
<content type='text'>
Double-free error in bpf_linker__free() was reported by James Hilliard.
The error is caused by miss-use of realloc() in extend_sec().
The error occurs when two files with empty sections of the same name
are linked:
- when first file is processed:
  - extend_sec() calls realloc(dst-&gt;raw_data, dst_align_sz)
    with dst-&gt;raw_data == NULL and dst_align_sz == 0;
  - dst-&gt;raw_data is set to a special pointer to a memory block of
    size zero;
- when second file is processed:
  - extend_sec() calls realloc(dst-&gt;raw_data, dst_align_sz)
    with dst-&gt;raw_data == &lt;special pointer&gt; and dst_align_sz == 0;
  - realloc() "frees" dst-&gt;raw_data special pointer and returns NULL;
  - extend_sec() exits with -ENOMEM, and the old dst-&gt;raw_data value
    is preserved (it is now invalid);
  - eventually, bpf_linker__free() attempts to free dst-&gt;raw_data again.

This patch fixes the bug by avoiding -ENOMEM exit for dst_align_sz == 0.
The fix was suggested by Andrii Nakryiko &lt;andrii.nakryiko@gmail.com&gt;.

Reported-by: James Hilliard &lt;james.hilliard1@gmail.com&gt;
Signed-off-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Tested-by: James Hilliard &lt;james.hilliard1@gmail.com&gt;
Link: https://lore.kernel.org/bpf/CADvTj4o7ZWUikKwNTwFq0O_AaX+46t_+Ca9gvWMYdWdRtTGeHQ@mail.gmail.com/
Link: https://lore.kernel.org/bpf/20230328004738.381898-3-eddyz87@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Cleanup linker_append_elf_relos</title>
<updated>2023-03-01T19:13:11Z</updated>
<author>
<name>Viktor Malik</name>
<email>vmalik@redhat.com</email>
</author>
<published>2023-03-01T08:53:55Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=4672129127eed0d16ab1b4b70b4e49014e49e8bb'/>
<id>urn:sha1:4672129127eed0d16ab1b4b70b4e49014e49e8bb</id>
<content type='text'>
Clang Static Analyser (scan-build) reports some unused symbols and dead
assignments in the linker_append_elf_relos function. Clean these up.

Signed-off-by: Viktor Malik &lt;vmalik@redhat.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/c5c8fe9f411b69afada8399d23bb048ef2a70535.1677658777.git.vmalik@redhat.com
</content>
</entry>
<entry>
<title>libbpf: Add enum64 support for bpf linking</title>
<updated>2022-06-07T17:20:43Z</updated>
<author>
<name>Yonghong Song</name>
<email>yhs@fb.com</email>
</author>
<published>2022-06-07T06:26:42Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=6ec7d79be202db14bd0ceeb9ed32908bcaae27fa'/>
<id>urn:sha1:6ec7d79be202db14bd0ceeb9ed32908bcaae27fa</id>
<content type='text'>
Add BTF_KIND_ENUM64 support for bpf linking, which is
very similar to BTF_KIND_ENUM.

Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Yonghong Song &lt;yhs@fb.com&gt;
Link: https://lore.kernel.org/r/20220607062642.3721494-1-yhs@fb.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix is_pow_of_2</title>
<updated>2022-06-03T21:53:33Z</updated>
<author>
<name>Yuze Chi</name>
<email>chiyuze@google.com</email>
</author>
<published>2022-06-03T05:51:56Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=611edf1bacc51355ccb497915695db7f869cb382'/>
<id>urn:sha1:611edf1bacc51355ccb497915695db7f869cb382</id>
<content type='text'>
Move the correct definition from linker.c into libbpf_internal.h.

Fixes: 0087a681fa8c ("libbpf: Automatically fix up BPF_MAP_TYPE_RINGBUF size, if necessary")
Reported-by: Yuze Chi &lt;chiyuze@google.com&gt;
Signed-off-by: Yuze Chi &lt;chiyuze@google.com&gt;
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20220603055156.2830463-1-irogers@google.com
</content>
</entry>
<entry>
<title>libbpf: Fix using invalidated memory in bpf_linker</title>
<updated>2021-11-25T23:15:03Z</updated>
<author>
<name>Andrii Nakryiko</name>
<email>andrii@kernel.org</email>
</author>
<published>2021-11-24T00:23:18Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-linux/commit/?id=593835377f24ca1bb98008ec1dc3baefe491ad6e'/>
<id>urn:sha1:593835377f24ca1bb98008ec1dc3baefe491ad6e</id>
<content type='text'>
add_dst_sec() can invalidate bpf_linker's section index making
dst_symtab pointer pointing into unallocated memory. Reinitialize
dst_symtab pointer on each iteration to make sure it's always valid.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20211124002325.1737739-7-andrii@kernel.org
</content>
</entry>
</feed>
