bcachefs-tools: Fix compilation on musl libc
PATCH 1/1 bcachefs-tools: Fix compilation on musl libc
Currently there is not a __attribute_const__ defined anywhere in linux/sort.c, which results in compilation failure on musl libc systems. The compiler also does not necessarily guarantee the macro and has only worked on glibc because of possible leakage from the header, sys/cdefs.h, which just happened to define __attribute_const__ in the same way that bcachefs-tools defines it. linux/compiler.h has also been included in files that use __attribute_const__ or __always_inline without explicit including for futureproofing.
This was narrowed down as the cause by noting that linux/compiler.h is not included anywhere in linux/sort.c, yet it was compiling successfully on glibc. Then, the preprocessor definitions were printed out using the gcc args: -E -dM.
To view the difference, the command:
$ gcc -I./include -E -dM linux/sort.c
on glibc and musl systems will reveal the discrepancy.
Expected output:
#define __attribute_const__ __attribute__ ((__const__))
On musl there is no output.
--- libbcachefs/bkey.h | 1 + libbcachefs/bset.c | 1 + libbcachefs/btree_iter.h | 1 + libbcachefs/eytzinger.c | 1 + libbcachefs/fs-io-direct.c | 1 + libbcachefs/six.c | 1 + libbcachefs/str_hash.h | 1 + libbcachefs/subvolume.c | 1 + linux/mempool.c | 1 + linux/sort.c | 1 + 10 files changed, 10 insertions(+)
libbcachefs/bkey.h +1 -0
@@ -3,6 +3,7 @@#define _BCACHEFS_BKEY_H#include <linux/bug.h> +#include <linux/compiler.h> #include "bcachefs_format.h" #include "bkey_types.h" #include "btree_types.h"
libbcachefs/bset.c +1 -0
@@ -17,6 +17,7 @@#include <linux/console.h> #include <linux/random.h> #include <linux/prefetch.h> +#include <linux/compiler.h> static inline void __bch2_btree_node_iter_advance (struct btree_node_iter *,struct btree *);
libbcachefs/btree_iter.h +1 -0
@@ -2,6 +2,7 @@#ifndef _BCACHEFS_BTREE_ITER_H#define _BCACHEFS_BTREE_ITER_H +#include <linux/compiler.h> #include "bset.h" #include "btree_types.h" #include "trace.h"
libbcachefs/eytzinger.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/compiler.h> #include "eytzinger.h" /**
libbcachefs/fs-io-direct.c +1 -0
@@ -14,6 +14,7 @@#include <linux/pagemap.h> #include <linux/prefetch.h> #include <linux/task_io_accounting_ops.h> +#include <linux/compiler.h> /* O_DIRECT reads */
libbcachefs/six.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/compiler.h> #include <linux/export.h> #include <linux/log2.h> #include <linux/percpu.h>
libbcachefs/str_hash.h +1 -0
@@ -12,6 +12,7 @@#include "super.h" #include <linux/crc32c.h> +#include <linux/compiler.h> #include <crypto/hash.h> #include <crypto/sha2.h>
libbcachefs/subvolume.c +1 -0
@@ -10,6 +10,7 @@#include "subvolume.h" #include <linux/random.h> +#include <linux/compiler.h> static int bch2_subvolume_delete (struct btree_trans *,u32 );
linux/mempool.c +1 -0
@@ -18,6 +18,7 @@#include <linux/mempool.h> #include <linux/mempool.h> #include <linux/sched.h> +#include <linux/compiler.h> #if defined(CONFIG_DEBUG_SLAB ) || defined(CONFIG_SLUB_DEBUG_ON ) static void poison_error(mempool_t *pool, void *element, size_t size,
linux/sort.c +1 -0
@@ -15,6 +15,7 @@#include <linux/types.h> #include <linux/export.h> #include <linux/sort.h> +#include <linux/compiler.h> /** * is_aligned - is this pointer & size okay for word-wide copying?
Signature · 1 line
2.44.0