Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Musl libc compatibility #4385

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/mount_zfs/mount_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <libzfs.h>
#include <locale.h>
#include <getopt.h>
#include <fcntl.h>

#define ZS_COMMENT 0x00000000 /* comment */
#define ZS_ZFSUTIL 0x00000001 /* caller is zfs(8) */
Expand Down
4 changes: 2 additions & 2 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
#include <math.h>
#include <sys/fs/zfs.h>
#include <libnvpair.h>
#ifdef __GNUC__
#ifdef __GLIBC__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. But can you add a link to the commit comment explaining why GLIBC should be used instead of GNUC. My guess is that GNUC was used here since that's what recommenced fron by gcc documentation.

https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execinfo.h and backtrace() are GNU extensions provided by glibc and not by gcc so the change is correct.

The mentioned gcc documentation does not mention backtrace() or execinfo.h as far I can see.

An alternative way to solve it would be to do a configure check for it and use HAVE_EXECINFO_H and HAVE_BACKTRACE.

#include <execinfo.h> /* for backtrace() */
#endif

Expand Down Expand Up @@ -490,7 +490,7 @@ _umem_logging_init(void)
static void sig_handler(int signo)
{
struct sigaction action;
#ifdef __GNUC__ /* backtrace() is a GNU extension */
#ifdef __GLIBC__ /* backtrace() is a GNU extension */
int nptrs;
void *buffer[BACKTRACE_SZ];

Expand Down
2 changes: 1 addition & 1 deletion include/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ extern void delay(clock_t ticks);
#define maxclsyspri -20
#define defclsyspri 0

#define CPU_SEQID (pthread_self() & (max_ncpus - 1))
#define CPU_SEQID ((uintptr_t)pthread_self() & (max_ncpus - 1))

#define kcred NULL
#define CRED() NULL
Expand Down
1 change: 1 addition & 0 deletions lib/libspl/include/devid.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef _LIBSPL_DEVID_H
#define _LIBSPL_DEVID_H

#include <sys/types.h>
#include <stdlib.h>

typedef int ddi_devid_t;
Expand Down
5 changes: 5 additions & 0 deletions lib/libspl/include/sys/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
#define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
#endif

typedef long long hrtime_t;
typedef struct timespec timestruc_t;
typedef struct timespec timespec_t;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@behlendorf ive moved the typedefs as you suggested in previous commit, and i have changed longlong_t to long long as longlong_t is not defined by any standard so musl does not support it.


extern hrtime_t gethrtime(void);
extern void gethrestime(timestruc_t *);

Expand Down
4 changes: 0 additions & 4 deletions lib/libspl/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ typedef longlong_t diskaddr_t;
typedef ulong_t pgcnt_t; /* number of pages */
typedef long spgcnt_t; /* signed number of pages */

typedef longlong_t hrtime_t;
typedef struct timespec timestruc_t;
typedef struct timespec timespec_t;

typedef short pri_t;

typedef int zoneid_t;
Expand Down
4 changes: 4 additions & 0 deletions lib/libspl/timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <langinfo.h>
#include "statcommon.h"

#ifndef _DATE_FMT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer to move this into our own langinfo.h header that uses #include_next <langinfo.h>. The new file should be under CDDL 1.0 only, rather than unbound to be consistent with how all new files are added.

#define _DATE_FMT "%+"
#endif

/*
* Print timestamp as decimal reprentation of time_t value (-T u was specified)
* or in date(1) format (-T d was specified).
Expand Down