Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: Fix implicit memfd_create() for bionic

Since memfd_create() is not consistently available across different
bionic libc implementations, using memfd_create() directly can break
some Android builds:

tools/lib/bpf/linker.c:576:7: error: implicit declaration of function 'memfd_create' [-Werror,-Wimplicit-function-declaration]
576 | fd = memfd_create(filename, 0);
| ^

To fix this, relocate and inline the sys_memfd_create() helper so that
it can be used in "linker.c". Similar issues were previously fixed by
commit 9fa5e1a180aa ("libbpf: Call memfd_create() syscall directly").

Fixes: 6d5e5e5d7ce1 ("libbpf: Extend linker API to support in-memory ELF files")
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250330211325.530677-1-cmllamas@google.com

authored by

Carlos Llamas and committed by
Andrii Nakryiko
75011ad6 06a22366

+10 -10
-9
tools/lib/bpf/libbpf.c
··· 1725 1725 return ERR_PTR(-ENOENT); 1726 1726 } 1727 1727 1728 - /* Some versions of Android don't provide memfd_create() in their libc 1729 - * implementation, so avoid complications and just go straight to Linux 1730 - * syscall. 1731 - */ 1732 - static int sys_memfd_create(const char *name, unsigned flags) 1733 - { 1734 - return syscall(__NR_memfd_create, name, flags); 1735 - } 1736 - 1737 1728 #ifndef MFD_CLOEXEC 1738 1729 #define MFD_CLOEXEC 0x0001U 1739 1730 #endif
+9
tools/lib/bpf/libbpf_internal.h
··· 667 667 return syscall(__NR_dup3, oldfd, newfd, flags); 668 668 } 669 669 670 + /* Some versions of Android don't provide memfd_create() in their libc 671 + * implementation, so avoid complications and just go straight to Linux 672 + * syscall. 673 + */ 674 + static inline int sys_memfd_create(const char *name, unsigned flags) 675 + { 676 + return syscall(__NR_memfd_create, name, flags); 677 + } 678 + 670 679 /* Point *fixed_fd* to the same file that *tmp_fd* points to. 671 680 * Regardless of success, *tmp_fd* is closed. 672 681 * Whatever *fixed_fd* pointed to is closed silently.
+1 -1
tools/lib/bpf/linker.c
··· 573 573 574 574 snprintf(filename, sizeof(filename), "mem:%p+%zu", buf, buf_sz); 575 575 576 - fd = memfd_create(filename, 0); 576 + fd = sys_memfd_create(filename, 0); 577 577 if (fd < 0) { 578 578 ret = -errno; 579 579 pr_warn("failed to create memfd '%s': %s\n", filename, errstr(ret));