1.99.13 fails to build on systems with musl C-library
Data recovery and protection tool
Brought to you by:
garloff
1.99.13 fails to build on my amd64-musl box:
# ./autogen.sh
# ./configure
# make
# gcc -Os -Wall -g -D_FORTIFY_SOURCE=2 -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DGEN_DEP -msse4.2 -maes -mavx2 -mvaes -mavx2 -mrdrnd -MM ./*.c >.dep
gcc -Os -Wall -g -D_FORTIFY_SOURCE=2 -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DGEN_DEP -D__AES__ -D__SSE4_1__ -D__SSSE3__ -D__SSE3__ -D__SSE2__ -D__SSE__ -D__MMX__ -DNO_WARN_X86_INTRINSICS -I . -MM ./*.c >.dep
In file included from ./find_nonzero.h:13,
from ./dd_rescue.c:118:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
./dd_rescue.c:205:3: error: #error __WORDSIZE undefined
205 | # error __WORDSIZE undefined
| ^~~~~
./fiemap.c:229:2: error: #error __WORDSIZE undefined
229 | #error __WORDSIZE undefined
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./file_zblock.c:16:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./find_nonzero.c:11:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./find_nonzero_arm.c:7:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./find_nonzero_arm64.c:7:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./find_nonzero_avx.c:11:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./find_nonzero_sse2.c:7:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./libddr_crypt.c:18:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
./libddr_crypt.c:65:2: error: #error __WORDSIZE unknown
65 | #error __WORDSIZE unknown
| ^~~~~
./libddr_hash.c:414:2: error: #error __WORDSIZE unknown
414 | #error __WORDSIZE unknown
| ^~~~~
./libddr_lzo.c:48:2: error: #error __WORDSIZE unknown
48 | #error __WORDSIZE unknown
| ^~~~~
./libddr_null.c:98:2: error: #error __WORDSIZE unknown
98 | #error __WORDSIZE unknown
| ^~~~~
./sha512.c:175:2: error: #error __WORDSIZE unknown
175 | #error __WORDSIZE unknown
| ^~~~~
In file included from ./find_nonzero.h:13,
from ./test_aes.c:5:
./ffs.h:61:3: error: #error Need to define __WORDSIZE
61 | # error Need to define __WORDSIZE
| ^~~~~
Makefile:240: .dep: No such file or directory
make: *** [Makefile:235: .dep] Error 1
Gentoo has a workaround for this (https://gitweb.gentoo.org/repo/gentoo.git/commit/sys-fs/dd-rescue?id=2dff586ec1e93dae97dd97cfa2e310edbd633515) by forcing ac_cv_func_fallocate64=yes and RPM_OPT_FLAGS="${CFLAGS} ${CPPFLAGS} -D_LARGEFILE64_SOURCE". A more detailed explanation in the workaround.
With the workaround 1.99.13 builds and runs fine on musl-1.2.4. Starting with musl-1.2.5 I however run into a new problem:
[...]
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -DVERSION=\"1.99.13\" -D__COMPILER__="\"clang version 18.1.8+libcxx\"" -DID=\"DD_RESCUE_1_99_13\" -fPIC -o libddr_hash.po -c libddr_hash.c
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -fPIC -o md5.po -c md5.c
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -fPIC -o sha256.po -c sha256.c
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -fPIC -o sha512.po -c sha512.c
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -fPIC -o sha1.po -c sha1.c
In file included from libddr_hash.c:17:
In file included from ./ddr_plugin.h:24:
./ddr_ctrl.h:10:9: warning: '_GNU_SOURCE' macro redefined
[-Wmacro-redefined]
10 | #define _GNU_SOURCE
| ^
libddr_hash.c:11:10: note: previous definition is here
11 | # define _GNU_SOURCE 1
| ^
fatal: not a git repository (or any parent up to mount point /var)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -DVERSION=\"1.99.13\" -D__COMPILER__="\"clang version 18.1.8+libcxx\"" -DID=\"DD_RESCUE_1_99_13\" -fPIC -o pbkdf2.po -c pbkdf2.c
libddr_hash.c:848:20: warning: implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
848 | .handles_sparse = 1,
| ^
fatal: not a git repository (or any parent up to mount point /var)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -DVERSION=\"1.99.13\" -D__COMPILER__="\"clang version 18.1.8+libcxx\"" -DID=\"DD_RESCUE_1_99_13\" -fPIC -o checksum_file.po -c checksum_file.c
fatal: not a git repository (or any parent up to mount point /var)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
checksum_file.c:64:14: error: call to undeclared function 'basename'; ISO
C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
64 | char* bnm = basename((char*)nm);
| ^
checksum_file.c:64:8: error: incompatible integer to pointer conversion
initializing 'char *' with an expression of type 'int' [-Wint-conversion]
64 | char* bnm = basename((char*)nm);
| ^ ~~~~~~~~~~~~~~~~~~~
checksum_file.c:156:14: error: call to undeclared function 'basename'; ISO
C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
156 | char* bnm = basename(nm);
| ^
checksum_file.c:156:8: error: incompatible integer to pointer conversion
initializing 'char *' with an expression of type 'int' [-Wint-conversion]
156 | char* bnm = basename(nm);
| ^ ~~~~~~~~~~~~
4 errors generated.
clang -Os -march=x86-64-v2 -pipe -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -I . -DHAVE_AESNI -DNO_AVX2 -DVERSION=\"1.99.13\" -D__COMPILER__="\"clang version 18.1.8+libcxx\"" -DID=\"DD_RESCUE_1_99_13\" -fPIC -o libddr_null.po -c libddr_null.c
make: *** [Makefile:282: checksum_file.po] Error 1
make: *** Waiting for unfinished jobs....
libddr_null.c:47:32: warning: implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
47 | ddr_plug.changes_output_len = 1;
| ^ ~
libddr_null.c:49:32: warning: implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
49 | ddr_plug.changes_output_len = 1;
| ^ ~
libddr_null.c:56:28: warning: implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
56 | ddr_plug.changes_output = 1;
| ^ ~
libddr_null.c:58:28: warning: implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
58 | ddr_plug.changes_output = 1;
| ^ ~
libddr_null.c:124:20: warning: implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
124 | .handles_sparse = 1,
| ^
5 warnings generated.
2 warnings generated.
* ERROR: sys-fs/dd-rescue-1.99.13-r1::gentoo failed (compile phase):
This is Gentoo downstream bug report #937492.
Thanks for reporting!
The basename() function is declared in libgen.h, I now test for it and include it.
The ddr_ctrl.h file in my tree does NOT contain #define _GNU_SOURCE, so I wonder where that comes from.
Please check whether the current git state (DD_RESCUE_1_99_BRANCH) works well.
Thanks for looking into this!
I had trouble getting the repo (git clone git://git.code.sf.net/p/ddrescue/code ddrescue-code) as the link provided by sourceforge does not give me branches but only the master repo with commits up to 2017 (?). But this may be very well my git skills lacking...
So I used the SF webinterface to generate me a snapshot of DD_RESCUE_1_99_BRANCH. But I still get the same errors:
__WORDSIZE I did not address. It should be defined by the C library, but musl might not do it? Can you grep through the include headers? I can try to find something in the official documentation ...
Looks like I addressed all the other issues, though.
__WORDSIZE is defined in two places in musl:
and
Thanks for the insight!
The headers in bits/ are not supposed to be included directly...
If you could find out, which headers in include, include/sys or maybe include/Linux pull them in, that would be helpful.
(Sorry, I don't have a musl system at hand. Or well, maybe I can grep through openwrt build system...)
Ok, didn't know that. But looks like the solution is straightforward:
or
I added a test for sys/user.h existence and include in places where __WORDSIZE is being used.
Feedback welcome!
This works now on your latest git. Thanks!
Next thing I run into is:
If I replace
loff_twithoff_tin fmt_no.h, fmt_no.c, fstrim.h, fstrim.c the build continues and I run later info:Last edit: Erhard F. 2024-08-18
loff_t should be declared in sys/types.h if _GNU_SOURCE is defined, off64_t if _LARGEFILE64_SOURCE is defined. Does it work that way with musl?
In sys/types.h (git.musl-libc.org) only off64_t is defined.
In fcntl.h (git.musl-libc.org) both, loff_t and off64_t are defined.
I have done some work on an Alpine chroot on Android (with UserLand).
I found a number of compile issues:
Things compile without any extra effort now on Alpine. Do you want to check latest git against your environment?
I can confirm that latest git DD_RESCUE_1_99_BRANCH builds fine now on my musl 1.2.4 and musl 1.2.5 boxes.
Many thanks for your efforts!
Thanks for testing and confirming!
Does it also pass the make check target?
I will push this also into OBS (openSuSE'sOopen Build Service) to have it built for many different distributions and architectures. There is a small risk that it breaks on 32bit architectures, as I have changed the checks and defines for LFS (Large File Support) functions ...
This is the output I captured via
make check &> check_output.txt.If you are interested whether it builds on 32bit I could test on my i686 box (glibc) and ppc32 box (glibc, musl) too. ;-)
Checking is appreciated.
Logfile looks good though cut-off.
make check exits with a failure code in case of issues. Whether that happens is actually all I need to know.
OBS project at https://build.opensuse.org/package/show/home:garloff:storage/dd_rescue
Just for the record: I pushed a few more changes to git:
The fact that basename() may change the argument and may return a pointer to a buffer that might be overwritten requires us to use strdup(basename(strdupa(nm))) in some cases. To add insult oto injury, strdupa() does not exist on BIONIC and thus needs to be open-coded (which is straight-forward -- if we can rely on GNU extensions).
So I submitted to the NIH and opencoded basename in mybasename.h, avoiding all these memory allocation pains just for safety.
(In fairnesss, glibc does NOT do stupid things, and other C libs probably not either. But we can only rely on POSIX, sigh.)
Current builds fine on musl 1.2.4 and 1.2.5.
On my musl 1.2.5 box make check fails like this:
I'll check i686 and ppc32 next.
Ok, 32bit building & testing went fine on i686 glibc and ppc32 glibc. Only testfailure on ppc32 musl 1.2.4:
I have seen this also on aarch64 musl. No reported error, but an exit code of 1 from this exact same test. Will need to study code to understand how this can happen.
OK, this is due to errno not being cleared always.
Fix in git (aa22c34).
Thanks! Tests pass now flawlessly on ppc32 musl .
All those changes now in place are probably a good excuse to do a new point release? ;-)
Done on my homepage, and tagged with DD_RESCUE_1_99_14
I pushed one more change to configure.ac after the release.
There was a conflict to set _FORTIFY_SOURCE in configure with flags passed in by the build system e.g. on openSUSE Tumbleweed. Removed it.
I think this issue can be closed.
Thanks for your work and for the new release!
Seems you need to close the issue; I don't see any option or button to accomplish myself...