koverstreet / bcachefs-tools

http://bcachefs.org
GNU General Public License v2.0
123 stars 90 forks source link

musl build failure: linux/sort.c:32:1: error: unknown type name '__attribute_const__' #248

Closed ernsteiswuerfel closed 4 months ago

ernsteiswuerfel commented 8 months ago

Eagerly trying to build bcachefs-tools-1.6.4 on Gentoo musl/clang with musl 1.2.5 as #213 should be fixed when building against 1.2.5.

But now I run into another build failure:

[...]
clang-17  -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -Os -march=bdver2 -pipe -std=gnu11   -MMD -Wall -fPIC -Wno-pointer-sign -Wno-deprecated-declarations -fno-strict-aliasing -fno-delete-null-pointer-checks -I. -Ic_src -Iinclude -Iraid -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LGPL_SOURCE -DRCU_MEMBARRIER -DZSTD_STATIC_LINKING_ONLY -DFUSE_USE_VERSION=35 -DNO_BCACHEFS_CHARDEV -DNO_BCACHEFS_FS -DNO_BCACHEFS_SYSFS -DVERSION_STRING='"1.6.4"' -D__SANE_USERSPACE_TYPES__  -Wno-unused-but-set-variable -Wno-missing-braces -Wno-zero-length-array -Wno-shift-overflow -Wno-enum-conversion -Wno-gnu-variable-sized-type-not-at-end -I/usr/include/blkid -I/usr/include/uuid -c -o linux/siphash.o linux/siphash.c
    [CC]     linux/sort.o
clang-17  -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -Os -march=bdver2 -pipe -std=gnu11   -MMD -Wall -fPIC -Wno-pointer-sign -Wno-deprecated-declarations -fno-strict-aliasing -fno-delete-null-pointer-checks -I. -Ic_src -Iinclude -Iraid -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LGPL_SOURCE -DRCU_MEMBARRIER -DZSTD_STATIC_LINKING_ONLY -DFUSE_USE_VERSION=35 -DNO_BCACHEFS_CHARDEV -DNO_BCACHEFS_FS -DNO_BCACHEFS_SYSFS -DVERSION_STRING='"1.6.4"' -D__SANE_USERSPACE_TYPES__  -Wno-unused-but-set-variable -Wno-missing-braces -Wno-zero-length-array -Wno-shift-overflow -Wno-enum-conversion -Wno-gnu-variable-sized-type-not-at-end -I/usr/include/blkid -I/usr/include/uuid -c -o linux/sort.o linux/sort.c
linux/sort.c:32:1: error: unknown type name '__attribute_const__'
   32 | __attribute_const__ __always_inline
      | ^
linux/sort.c:183:1: error: unknown type name '__attribute_const__'
  183 | __attribute_const__ __always_inline
      | ^
linux/sort.c:183:21: error: 'inline' can only appear on functions
  183 | __attribute_const__ __always_inline
      |                     ^
/usr/include/linux/stddef.h:8:25: note: expanded from macro
      '__always_inline'
    8 | #define __always_inline __inline__
      |                         ^
linux/sort.c:184:14: error: expected ';' after top level declarator
  184 | static size_t parent(size_t i, unsigned int lsbit, size_t size)
      |              ^
      |              ;
linux/sort.c:271:8: error: call to undeclared function 'parent'; ISO C99
      and later do not support implicit function declarations
      [-Wimplicit-function-declaration]
  271 |                         b = parent(b, lsbit, size);
      |                             ^
5 errors generated.
make: *** [Makefile:173: linux/sort.o] Error 1

The error above is from Gentoos bcachefs-tools-1.6.4 ebuild but building bcachefs-tools from git-master also gives me:

[...]
 # make
Makefile:113: skipping systemd integration
    [CC]     linux/sort.o
linux/sort.c:32:20: error: expected ';' before '__inline__'
   32 | __attribute_const__ __always_inline
      |                    ^
      |                    ;
linux/sort.c:183:20: error: expected ';' before '__inline__'
  183 | __attribute_const__ __always_inline
      |                    ^
      |                    ;
make: *** [Makefile:173: linux/sort.o] Error 1

bcachefs-tools-1.6.4:20240303-133310.log

Kangie commented 6 months ago

https://lore.kernel.org/linux-bcachefs/20240425135033.1163353-1-csfore@posteo.net/

koverstreet commented 6 months ago

That doesn't look like it the right fix - we're already pulling in compiler.h via kernel.h, did anyone test that?

csfore commented 6 months ago

Are you referring to the futureproofing fixes? Since sort.c doesn't include kernel.h anywhere (even indirectly), I could drop those though and re-submit just the fix itself if that's preferred. Regarding testing, I tested both musl and glibc and both compiled fine with the patch.

ray-adams commented 4 months ago

Edit: After updating to musl-1.2.5-r1 on musl/llvm and compiling bcachefs-tools I no longer have this issue. Maybe OP can try compiling bcachefs-tools-1.7.0?

Keep in mind first you would have to include the following patch:

--- a/linux/sort.c
+++ b/linux/sort.c
@@ -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?

After doing that you still get another compiler error which I have reported in #300 . But its at the linker stage so we are getting close.

ray-adams commented 4 months ago

Edit: After updating to musl-1.2.5-r1 on musl/llvm and compiling bcachefs-tools I no longer have this issue. Maybe OP can try compiling bcachefs-tools-1.7.0?

Keep in mind first you would have to include the following patch:

--- a/linux/sort.c
+++ b/linux/sort.c
@@ -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?

After doing that you still get another compiler error which I have reported in #300 . But its at the linker stage so we are getting close.

The patch I have stated above no longer needs to be used for versions >=1.9.0.

ray-adams commented 4 months ago

This bug can be closed as its now possible to compile bcachefs-tools-1.9.1 on gentoo by passing -C default-linker-libraries after obtaining >=musl-1.2.5.

ernsteiswuerfel commented 4 months ago

@ray-adams Correct. I only hit #300 now.