Skip to content

Commit 5681893

Browse files
iii-ianakryiko
authored andcommitted
libbpf: Support Debian in resolve_full_path()
attach_probe selftest fails on Debian-based distros with `failed to resolve full path for 'libc.so.6'`. The reason is that these distros embraced multiarch to the point where even for the "main" architecture they store libc in /lib/<triple>. This is configured in /etc/ld.so.conf and in theory it's possible to replicate the loader's parsing and processing logic in libbpf, however a much simpler solution is to just enumerate the known library paths. Signed-off-by: Ilya Leoshkevich <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent d298761 commit 5681893

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10707,15 +10707,53 @@ static long elf_find_func_offset(const char *binary_path, const char *name)
1070710707
return ret;
1070810708
}
1070910709

10710+
static const char *arch_specific_lib_paths(void)
10711+
{
10712+
/*
10713+
* Based on https://packages.debian.org/sid/libc6.
10714+
*
10715+
* Assume that the traced program is built for the same architecture
10716+
* as libbpf, which should cover the vast majority of cases.
10717+
*/
10718+
#if defined(__x86_64__)
10719+
return "/lib/x86_64-linux-gnu";
10720+
#elif defined(__i386__)
10721+
return "/lib/i386-linux-gnu";
10722+
#elif defined(__s390x__)
10723+
return "/lib/s390x-linux-gnu";
10724+
#elif defined(__s390__)
10725+
return "/lib/s390-linux-gnu";
10726+
#elif defined(__arm__) && defined(__SOFTFP__)
10727+
return "/lib/arm-linux-gnueabi";
10728+
#elif defined(__arm__) && !defined(__SOFTFP__)
10729+
return "/lib/arm-linux-gnueabihf";
10730+
#elif defined(__aarch64__)
10731+
return "/lib/aarch64-linux-gnu";
10732+
#elif defined(__mips__) && defined(__MIPSEL__) && _MIPS_SZLONG == 64
10733+
return "/lib/mips64el-linux-gnuabi64";
10734+
#elif defined(__mips__) && defined(__MIPSEL__) && _MIPS_SZLONG == 32
10735+
return "/lib/mipsel-linux-gnu";
10736+
#elif defined(__powerpc64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
10737+
return "/lib/powerpc64le-linux-gnu";
10738+
#elif defined(__sparc__) && defined(__arch64__)
10739+
return "/lib/sparc64-linux-gnu";
10740+
#elif defined(__riscv) && __riscv_xlen == 64
10741+
return "/lib/riscv64-linux-gnu";
10742+
#else
10743+
return NULL;
10744+
#endif
10745+
}
10746+
1071010747
/* Get full path to program/shared library. */
1071110748
static int resolve_full_path(const char *file, char *result, size_t result_sz)
1071210749
{
10713-
const char *search_paths[2];
10750+
const char *search_paths[3] = {};
1071410751
int i;
1071510752

1071610753
if (strstr(file, ".so")) {
1071710754
search_paths[0] = getenv("LD_LIBRARY_PATH");
1071810755
search_paths[1] = "/usr/lib64:/usr/lib";
10756+
search_paths[2] = arch_specific_lib_paths();
1071910757
} else {
1072010758
search_paths[0] = getenv("PATH");
1072110759
search_paths[1] = "/usr/bin:/usr/sbin";

0 commit comments

Comments
 (0)