LoongArch: Add support for ldconfig.
[glibc.git] / sysdeps / unix / sysv / linux / loongarch / dl-cache.h
blob05219c62723ea7f96b46fc0cc5f845889e54bb38
1 /* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <ldconfig.h>
20 #include <assert.h>
22 #if defined __loongarch_double_float
23 # define _DL_CACHE_DEFAULT_ID (FLAG_LARCH_FLOAT_ABI_DOUBLE | FLAG_ELF_LIBC6)
24 #else
25 # define _DL_CACHE_DEFAULT_ID (FLAG_LARCH_FLOAT_ABI_SOFT | FLAG_ELF_LIBC6)
26 #endif
28 #define _dl_cache_check_flags(flags) \
29 ((flags) == _DL_CACHE_DEFAULT_ID)
31 /* If given a path to one of our library directories, adds every library
32 directory via add_dir (), otherwise just adds the giver directory. On
33 LoongArch, libraries can be found in paths ending in:
34 - /lib64
35 - /lib64/sf
36 so this will add all of those paths. */
38 #define add_system_dir(dir) \
39 do \
40 { \
41 static const char* lib_dirs[] = { \
42 "/lib64", \
43 "/lib64/sf", \
44 NULL, \
45 }; \
46 const size_t lib_len = sizeof ("/lib") - 1; \
47 size_t len = strlen (dir); \
48 char path[len + 6]; \
49 const char **ptr; \
51 memcpy (path, dir, len + 1); \
53 for (ptr = lib_dirs; *ptr != NULL; ptr++) \
54 { \
55 const char *lib_dir = *ptr; \
56 size_t dir_len = strlen (lib_dir); \
58 if (len >= dir_len \
59 && !memcmp (path + len - dir_len, lib_dir, dir_len)) \
60 { \
61 len -= dir_len - lib_len; \
62 path[len] = '\0'; \
63 break; \
64 } \
65 } \
66 add_dir (path); \
67 if (len >= lib_len \
68 && !memcmp (path + len - lib_len, "/lib", lib_len)) \
69 for (ptr = lib_dirs; *ptr != NULL; ptr++) \
70 { \
71 const char *lib_dir = *ptr; \
72 size_t dir_len = strlen (lib_dir); \
74 assert (dir_len >= lib_len); \
75 memcpy (path + len, lib_dir + lib_len, \
76 dir_len - lib_len + 1); \
77 add_dir (path); \
78 } \
79 } while (0)
82 #include_next <dl-cache.h>