tree-wide: assorted fixes/workarounds for supporting musl (#39687)

This commit is contained in:
Yu Watanabe
2025-11-14 00:16:50 +09:00
committed by GitHub
10 changed files with 37 additions and 28 deletions
+3 -3
View File
@@ -34,11 +34,11 @@ static int get_runpath_from_dynamic(const ElfW(Dyn) *d, ElfW(Addr) bias, const c
break;
case DT_STRTAB:
/* On MIPS and RISC-V DT_STRTAB records an offset, not a valid address, so it has to be adjusted
* using the bias calculated earlier. */
/* On MIPS, RISC-V, or with musl, DT_STRTAB records an offset, not a valid address,
* so it has to be adjusted using the bias calculated earlier. */
if (d->d_un.d_val != 0)
strtab = (const char *) ((uintptr_t) d->d_un.d_val
#if defined(__mips__) || defined(__riscv)
#if defined(__mips__) || defined(__riscv) || !defined(__GLIBC__)
+ bias
#endif
);
+11 -5
View File
@@ -39,12 +39,18 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t));
# error Unknown timex member size
#endif
#if SIZEOF_RLIM_T == 8
# define RLIM_FMT "%" PRIu64
#elif SIZEOF_RLIM_T == 4
# define RLIM_FMT "%" PRIu32
#ifdef __GLIBC__
# if SIZEOF_RLIM_T == 8
# define RLIM_FMT "%" PRIu64
# elif SIZEOF_RLIM_T == 4
# define RLIM_FMT "%" PRIu32
# else
# error Unknown rlim_t size
# endif
#else
# error Unknown rlim_t size
/* Assume musl, and it unconditionally uses unsigned long long. */
assert_cc(SIZEOF_RLIM_T == 8);
# define RLIM_FMT "%llu"
#endif
#if SIZEOF_DEV_T == 8
+3 -3
View File
@@ -94,8 +94,8 @@ bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
if (hyphen)
return false;
if (p-s > HOST_NAME_MAX) /* Note that HOST_NAME_MAX is 64 on Linux, but DNS allows domain names up to
* 255 characters */
/* Note that host name max is 64 on Linux, but DNS allows domain names up to 255 characters. */
if (p - s > (ssize_t) LINUX_HOST_NAME_MAX)
return false;
return true;
@@ -107,7 +107,7 @@ char* hostname_cleanup(char *s) {
assert(s);
for (p = s, d = s, dot = hyphen = true; *p && d - s < HOST_NAME_MAX; p++)
for (p = s, d = s, dot = hyphen = true; *p && d - s < (ssize_t) LINUX_HOST_NAME_MAX; p++)
if (*p == '.') {
if (dot || hyphen)
continue;
+3
View File
@@ -4,6 +4,9 @@
#include "basic-forward.h"
#include "strv.h"
/* HOST_NAME_MAX should be 64 on linux, but musl uses the one by POSIX (255). */
#define LINUX_HOST_NAME_MAX CONST_MIN((size_t) HOST_NAME_MAX, (size_t) 64)
char* get_default_hostname_raw(void);
bool valid_ldh_char(char c) _const_;