JayDDee / cpuminer-opt

Optimized multi algo CPU miner
Other
763 stars 541 forks source link

cpu-miner.c:(.text+0x8cf8): undefined reference to `set_incl' #420

Open sumariva opened 3 months ago

sumariva commented 3 months ago

Hello, I trying to compile cpuminer-opt version 23.15, lateste, at date March, 28, 2014. I made adjustments on configure to give proper directories and linker files as process failed during build.

I finally could reach the last step, but got stop on linker faults. The output of GCC is below. Those all looks like related to internal source code, not dependencies:

cpuminer-cpu-miner.o: In function `cpu_capability':
cpu-miner.c:(.text+0x8cf8): undefined reference to `set_incl'
cpu-miner.c:(.text+0x8d0a): undefined reference to `set_incl'
cpu-miner.c:(.text+0x8d1c): undefined reference to `set_incl'
cpu-miner.c:(.text+0x8d2e): undefined reference to `set_incl'
cpu-miner.c:(.text+0x8d40): undefined reference to `set_incl'
cpuminer-cpu-miner.o:cpu-miner.c:(.text+0x8d52): more undefined references to `set_incl' follow
algo/m7m/cpuminer-m7m.o: In function `swit2_':
m7m.c:(.text+0xfd): undefined reference to `exp_n'
m7m.c:(.text+0x124): undefined reference to `exp_n'
algo/x11/cpuminer-timetravel-gate.o: In function `tt8_next_permutation':
timetravel-gate.c:(.text+0x1ba): undefined reference to `tt_swap'
timetravel-gate.c:(.text+0x1cd): undefined reference to `reverse'
timetravel-gate.c:(.text+0x1ec): undefined reference to `reverse'
algo/x11/cpuminer-timetravel10-gate.o: In function `tt10_next_permutation':
timetravel10-gate.c:(.text+0x1ba): undefined reference to `tt10_swap'
timetravel10-gate.c:(.text+0x1cd): undefined reference to `reverse'
timetravel10-gate.c:(.text+0x1ec): undefined reference to `reverse'
collect2: error: ld returned 1 exit status
Makefile:2160: recipe for target 'cpuminer' failed

Any hints?

JayDDee commented 3 months ago

This is typically a missing package. Review the build procedure and following it, make note of any deviations. Also provide your CPU model, OS, GCC version and any other relevant details.

sumariva commented 3 months ago

I could pass over the missing definition of 'set_incl' by changing the function declaration to be static. I do not know if this is a g++ behaviour exceptional to the standard C++ compilers. Any problems turning the declaration static?

Below the gcc available:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)

CPU info:

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz
stepping        : 11
microcode       : 0xbc
flags           : fpu de tsc msr pae cx8 apic sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl pni ssse3 cx16 hypervisor lahf_lm dtherm
bugs            : null_seg cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit

Update, using the static, also worked for the declared function 'exp_n' at file algo/m7m/m7m.c. Also, worked for function reverse and tt_swap at file at file algo/x11/cpuminer-timetravel-gate.c.

Need to change function reverse and tt10_swap at file algo/x11/timetravel10-gate.c

Now compilation worked fine.

JayDDee commented 3 months ago

It was never a problem before, even when GCC-6 was new. They all seem to be inline functions that aren't static. I have no idea why this matters. In fact it seems backward. Defining a function static is more restrictive as it says the function is only to be used within the file and doesn't need to be linkable by other files. Are you doing anything off-script? All dev has been on Ubuntu starting from 14-04 (GCC-4.8), probably earlier, so Debian should be a piece of cake. Why you and why now?

Edit: Some speculation The errors are at link time so the linker is looking for compiled versions of these functions but there aren't any because they should should have been inlined at compile time. It seems the linker doesn't know the functions were inlined but adding the static declaration directs the linker not to try to link those functions. This seems like an options mismatch between the compiler & linker or maybe a bug. Did you compile & link seperately?

Edit: these inline functions are not static but did not error: util.c:inline bool valid_hash( const void *hash, const void *target ) util.c:inline bool valid_hash( const void *hash, const void *target ) util.c:inline double nbits_to_diff( uint32_t nbits )

sumariva commented 3 months ago

No, I just downloaded current's versions of automake, autoconf, m4, and libtool and compiled those dependencies, using the generate make, in my home folder. Then, I could execute the configure generation.

During the configure execution, it did not detect several things and compilation stopped on some errors that I could figure out by error messages. So, I grabbed a current curl and compiled it in my home folder too. So it could find curl/curl.h Now, the compilation advanced until the link stage and reported those missing symbols plus some that I imagined be at zlib. Changed configure again to add -lz and some more symbols were resolved. Finally, only those inline symbols were missing. Below is mine configure's command line: LIBS="-lcurl -lz" LDFLAGS="-L$HOME/lib" CPP_FLAGS="-I$HOME/include" CFLAGS="-I$HOME/include" ./configure --prefix=$HOME --includedir=$HOME/include

After editing those files to add "static", the make finished the build process with success.

I been long time without using GCC. I imagined this be some changes in C dialects. I know gcc has some switches to change that. That is why I asked help. I see some _GNU_SOURCE macros on some headers files. I do not know if need some macro to adjust the source code to GCC standards. At this GNU GCC, it shows the static inline declaration: https://gcc.gnu.org/onlinedocs/gcc/extensions-to-the-c-language-family/an-inline-function-is-as-fast-as-a-macro.html

JayDDee commented 3 months ago

What do you mean no? That's WAY off script! Just use the default build procedure as I suggested in my first reply.

sumariva commented 3 months ago

I mean that I followed your build procedure, as possible, as described at INSTALL_LINUX. Unfortunately, I do not have root access to execute sudo. So, I compiled it in my user space folder. I extracted the source code, untar, ran build.sh. But that script failed because of missing aclocal.

Then I started building all dependencies required to make build.sh execute. I replied all arguments that I supplied to configure execute and make the build process, run until finish. The good news is that the source code can be compiled at user space!

JayDDee commented 3 months ago

My best guess is there's something in your custom environment causing the error. As I previously mentioned there seems to be confusion between the compiler (inlining the function code) and the linker (linking a discrete function via a pointer). It seems the linker was looking for a function pointer but the compiler never created one because all instances of the function were inlined. A static function doesn't have linkage so the linker doesn't look for it.

I haven't found any documentation recommending inlined functions be static or that there may be problems if not static.

You have found a workaround for your environment and this workaround happens to be how most inline functions in cpuminer are defined. I'll make the changes to make them consistent.

sumariva commented 3 months ago

But in the case of gcc, does not it make the two things at the same run, compile and link? All that I can suggest is to create a kind of preprocessor macro. Case a GCC compiler, use the static inline, a kind of

ifdef GNU_COMPILER

define sinline static inline

else

define sinline inline

endif

I do not know if there is some m4 macro for this kind of thing.

JayDDee commented 3 months ago

But in the case of gcc, does not it make the two things at the same run, compile and link?

I am not a GCC expert so this is based on general compiler theory. The compile phase reads the source files and creates the .o files. The link phase reads the .o files to resolve all external references to build the executable. Creating function pointers and inlining of fucntions is done at compile time, resolving function pointers is done at link time. Based on the error message and that it came from the linker it suggests the linker was looking for a function pointer that wasn't created at compile time. The compiler assumed the function pointer was not needed because all instances of the function would be inlined yet the linker looked for one. I noticed this error did not occur for inline functions declared in a .h and implemented in a .c. All errors were for inline functions fully defined the .h. Since this is the only time this problem has ever been reported I can only assume it's somwhow related to your custom environment. Unfortunately I can't help with that. I have no idea how autoconf, m4 etc work together, I just try not to break it.

Edit: My technical description above was a little off, it applies only to compiling source code, not header declarations. Header files are inlcuded in each caller's source file at compile time, there is no .o generated from a .h.

I kinda like the idea of defining all inline functions static in a .h. It guarantees they will be inlined because there's no other way than to have the source code in the included .h. Otherwise the compiler may choose not to inline for whatever reason.

jwakely commented 3 months ago

I do not know if this is a g++ behaviour exceptional to the standard C++ compilers.

Why are you using g++ to compile this, it's C code?

The meaning of inline is different in C and C++, so it's not surprising that C code using inline causes problems when compiled as C++.

jwakely commented 3 months ago

If you are using gcc not g++ then the problem is likely related to https://gcc.gnu.org/gcc-5/porting_to.html#inline

sumariva commented 3 months ago

Good point you noted about .c files been compiled with GCC but the linker used g++!!! This is the compiler that created the .o file:

gcc -DHAVE_CONFIG_H -I.  -fno-strict-aliasing -I./compat/jansson -I.  -Wno-pointer-sign -Wno-pointer-to-int-cast   -I/home/cristiano.sumariva/include  -MT algo/m7m/cpuminer-m7m.o -MD -MP -MF algo/m7m/.deps/cpuminer-m7m.Tpo -c -o algo/m7m/cpuminer-m7m.o `test -f 'algo/m7m/m7m.c' || echo './'`algo/m7m/m7m.c
mv -f algo/m7m/.deps/cpuminer-m7m.Tpo algo/m7m/.deps/cpuminer-m7m.Po

Yes, it was gcc. Below the invoked line that make issued. It invoked g++ on linking.

Note that all this make process has been built by the configure and tools. g++ -g -O2 -L/home/cristiano.sumariva/lib -L/home/cristiano.sumariva/lib -o cpuminer cpuminer-cpu-miner.o cpuminer-util.o cpuminer-api.o cpuminer-sysinfos.o cpuminer-algo-gate-api.o cpuminer-malloc-huge.o algo/argon2d/cpuminer-argon2d-gate.o algo/argon2d/blake2/cpuminer-blake2b.o algo/argon2d/argon2d/cpuminer-argon2.o algo/argon2d/argon2d/cpuminer-core.o algo/argon2d/argon2d/cpuminer-opt.o algo/argon2d/argon2d/cpuminer-argon2d_thread.o algo/argon2d/argon2d/cpuminer-encoding.o algo/blake/cpuminer-sph_blake.o algo/blake/cpuminer-blake256-hash.o algo/blake/cpuminer-blake512-hash.o algo/blake/cpuminer-blake-gate.o algo/blake/cpuminer-blake.o algo/blake/cpuminer-blake-4way.o algo/blake/cpuminer-sph_blake2b.o algo/blake/cpuminer-sph-blake2s.o algo/blake/cpuminer-blake2s-hash.o algo/blake/cpuminer-blake2s.o algo/blake/cpuminer-blake2b-hash.o algo/blake/cpuminer-blake2b.o algo/blake/cpuminer-blakecoin-gate.o algo/blake/cpuminer-mod_blakecoin.o algo/blake/cpuminer-blakecoin.o algo/blake/cpuminer-blakecoin-4way.o algo/blake/cpuminer-pentablake-gate.o algo/blake/cpuminer-pentablake-4way.o algo/blake/cpuminer-pentablake.o algo/bmw/cpuminer-sph_bmw.o algo/bmw/cpuminer-bmw256-hash-4way.o algo/bmw/cpuminer-bmw512-hash-4way.o algo/bmw/cpuminer-bmw256.o algo/bmw/cpuminer-bmw512-gate.o algo/bmw/cpuminer-bmw512.o algo/bmw/cpuminer-bmw512-4way.o algo/cubehash/cpuminer-cubehash_sse2.o algo/cubehash/cpuminer-cube-hash-2way.o algo/cubehash/cpuminer-sph_cubehash.o algo/echo/cpuminer-sph_echo.o algo/echo/cpuminer-echo-hash-4way.o algo/echo/aes_ni/cpuminer-hash.o algo/gost/cpuminer-sph_gost.o algo/groestl/cpuminer-groestl-gate.o algo/groestl/cpuminer-groestl512-hash-4way.o algo/groestl/cpuminer-groestl256-hash-4way.o algo/groestl/cpuminer-sph_groestl.o algo/groestl/cpuminer-groestl.o algo/groestl/cpuminer-groestl-4way.o algo/groestl/cpuminer-myrgr-gate.o algo/groestl/cpuminer-myrgr-4way.o algo/groestl/cpuminer-myr-groestl.o algo/groestl/aes_ni/cpuminer-hash-groestl.o algo/groestl/aes_ni/cpuminer-hash-groestl256.o algo/fugue/cpuminer-sph_fugue.o algo/fugue/cpuminer-fugue-aesni.o algo/hamsi/cpuminer-sph_hamsi.o algo/hamsi/cpuminer-hamsi-hash-4way.o algo/haval/cpuminer-haval.o algo/haval/cpuminer-haval-hash-4way.o algo/jh/cpuminer-sph_jh.o algo/jh/cpuminer-jh-hash-4way.o algo/jh/cpuminer-jha-gate.o algo/jh/cpuminer-jha-4way.o algo/jh/cpuminer-jha.o algo/keccak/cpuminer-sph_keccak.o algo/keccak/cpuminer-keccak.o algo/keccak/cpuminer-keccak-hash-4way.o algo/keccak/cpuminer-keccak-4way.o algo/keccak/cpuminer-keccak-gate.o algo/keccak/cpuminer-sha3d-4way.o algo/keccak/cpuminer-sha3d.o algo/lanehash/cpuminer-lane.o algo/luffa/cpuminer-luffa_for_sse2.o algo/luffa/cpuminer-luffa-hash-2way.o algo/luffa/cpuminer-sph_luffa.o algo/lyra2/cpuminer-lyra2.o algo/lyra2/cpuminer-sponge.o algo/lyra2/cpuminer-sponge-2way.o algo/lyra2/cpuminer-lyra2-hash-2way.o algo/lyra2/cpuminer-lyra2-gate.o algo/lyra2/cpuminer-lyra2rev2.o algo/lyra2/cpuminer-lyra2rev2-4way.o algo/lyra2/cpuminer-lyra2rev3.o algo/lyra2/cpuminer-lyra2rev3-4way.o algo/lyra2/cpuminer-lyra2re.o algo/lyra2/cpuminer-lyra2z-4way.o algo/lyra2/cpuminer-lyra2z330.o algo/lyra2/cpuminer-lyra2h.o algo/lyra2/cpuminer-lyra2h-4way.o algo/lyra2/cpuminer-allium-4way.o algo/lyra2/cpuminer-phi2-4way.o algo/lyra2/cpuminer-phi2.o algo/m7m/cpuminer-m7m.o algo/m7m/cpuminer-magimath.o algo/nist5/cpuminer-nist5-gate.o algo/nist5/cpuminer-nist5-4way.o algo/nist5/cpuminer-nist5.o algo/nist5/cpuminer-zr5.o algo/panama/cpuminer-panama-hash-4way.o algo/panama/cpuminer-sph_panama.o algo/quark/cpuminer-quark-gate.o algo/quark/cpuminer-quark.o algo/quark/cpuminer-quark-4way.o algo/quark/cpuminer-anime-gate.o algo/quark/cpuminer-anime.o algo/quark/cpuminer-anime-4way.o algo/quark/cpuminer-hmq1725-gate.o algo/quark/cpuminer-hmq1725-4way.o algo/quark/cpuminer-hmq1725.o algo/qubit/cpuminer-qubit-gate.o algo/qubit/cpuminer-qubit.o algo/qubit/cpuminer-qubit-2way.o algo/qubit/cpuminer-deep-gate.o algo/qubit/cpuminer-deep-2way.o algo/qubit/cpuminer-deep.o algo/ripemd/cpuminer-sph_ripemd.o algo/ripemd/cpuminer-ripemd-hash-4way.o algo/ripemd/cpuminer-lbry-gate.o algo/ripemd/cpuminer-lbry.o algo/ripemd/cpuminer-lbry-4way.o algo/scrypt/cpuminer-scrypt.o algo/scrypt/cpuminer-scrypt-core-4way.o algo/scrypt/cpuminer-neoscrypt.o algo/sha/cpuminer-sha1.o algo/sha/cpuminer-sha1-hash.o algo/sha/cpuminer-sha256-hash.o algo/sha/cpuminer-sph_sha2.o algo/sha/cpuminer-sph_sha2big.o algo/sha/cpuminer-sha256-hash-4way.o algo/sha/cpuminer-sha512-hash-4way.o algo/sha/cpuminer-hmac-sha256-hash.o algo/sha/cpuminer-hmac-sha256-hash-4way.o algo/sha/cpuminer-sha256d.o algo/sha/cpuminer-sha256d-4way.o algo/sha/cpuminer-sha256t-gate.o algo/sha/cpuminer-sha256t-4way.o algo/sha/cpuminer-sha256q-4way.o algo/sha/cpuminer-sha256q.o algo/sha/cpuminer-sha512256d-4way.o algo/sha/cpuminer-sha256dt.o algo/shabal/cpuminer-sph_shabal.o algo/shabal/cpuminer-shabal-hash-4way.o algo/shavite/cpuminer-sph_shavite.o algo/shavite/cpuminer-sph-shavite-aesni.o algo/shavite/cpuminer-shavite-hash-2way.o algo/shavite/cpuminer-shavite-hash-4way.o algo/shavite/cpuminer-shavite.o algo/simd/cpuminer-nist.o algo/simd/cpuminer-vector.o algo/simd/cpuminer-sph_simd.o algo/simd/cpuminer-simd-hash-2way.o algo/skein/cpuminer-sph_skein.o algo/skein/cpuminer-skein-hash-4way.o algo/skein/cpuminer-skein.o algo/skein/cpuminer-skein-4way.o algo/skein/cpuminer-skein-gate.o algo/skein/cpuminer-skein2.o algo/skein/cpuminer-skein2-4way.o algo/sm3/cpuminer-sm3.o algo/sm3/cpuminer-sm3-hash-4way.o algo/swifftx/cpuminer-swifftx.o algo/tiger/cpuminer-sph_tiger.o algo/verthash/cpuminer-verthash-gate.o algo/verthash/cpuminer-Verthash.o algo/verthash/cpuminer-fopen_utf8.o algo/verthash/tiny_sha3/cpuminer-sha3.o algo/verthash/tiny_sha3/cpuminer-sha3-4way.o algo/whirlpool/cpuminer-sph_whirlpool.o algo/whirlpool/cpuminer-whirlpool-gate.o algo/whirlpool/cpuminer-whirlpool.o algo/whirlpool/cpuminer-whirlpoolx.o algo/x11/cpuminer-x11-gate.o algo/x11/cpuminer-x11.o algo/x11/cpuminer-x11-4way.o algo/x11/cpuminer-x11gost-gate.o algo/x11/cpuminer-x11gost.o algo/x11/cpuminer-x11gost-4way.o algo/x11/cpuminer-c11-gate.o algo/x11/cpuminer-c11.o algo/x11/cpuminer-c11-4way.o algo/x11/cpuminer-tribus-gate.o algo/x11/cpuminer-tribus.o algo/x11/cpuminer-tribus-4way.o algo/x11/cpuminer-timetravel-gate.o algo/x11/cpuminer-timetravel.o algo/x11/cpuminer-timetravel-4way.o algo/x11/cpuminer-timetravel10-gate.o algo/x11/cpuminer-timetravel10.o algo/x11/cpuminer-timetravel10-4way.o algo/x11/cpuminer-x11evo.o algo/x11/cpuminer-x11evo-4way.o algo/x11/cpuminer-x11evo-gate.o algo/x12/cpuminer-x12-gate.o algo/x12/cpuminer-x12.o algo/x12/cpuminer-x12-4way.o algo/x13/cpuminer-x13-gate.o algo/x13/cpuminer-x13.o algo/x13/cpuminer-x13-4way.o algo/x13/cpuminer-x13sm3-gate.o algo/x13/cpuminer-x13sm3.o algo/x13/cpuminer-x13sm3-4way.o algo/x13/cpuminer-phi1612-gate.o algo/x13/cpuminer-phi1612.o algo/x13/cpuminer-phi1612-4way.o algo/x13/cpuminer-skunk-gate.o algo/x13/cpuminer-skunk-4way.o algo/x13/cpuminer-skunk.o algo/x13/cpuminer-x13bcd-4way.o algo/x13/cpuminer-x13bcd.o algo/x14/cpuminer-x14-gate.o algo/x14/cpuminer-x14.o algo/x14/cpuminer-x14-4way.o algo/x14/cpuminer-veltor-gate.o algo/x14/cpuminer-veltor.o algo/x14/cpuminer-veltor-4way.o algo/x14/cpuminer-polytimos-gate.o algo/x14/cpuminer-polytimos.o algo/x14/cpuminer-polytimos-4way.o algo/x14/cpuminer-axiom.o algo/x15/cpuminer-x15-gate.o algo/x15/cpuminer-x15.o algo/x15/cpuminer-x15-4way.o algo/x16/cpuminer-x16r-gate.o algo/x16/cpuminer-x16r.o algo/x16/cpuminer-x16r-4way.o algo/x16/cpuminer-x16rv2.o algo/x16/cpuminer-x16rv2-4way.o algo/x16/cpuminer-x16rt.o algo/x16/cpuminer-x16rt-4way.o algo/x16/cpuminer-hex.o algo/x16/cpuminer-x20r.o algo/x16/cpuminer-x21s-4way.o algo/x16/cpuminer-x21s.o algo/x16/cpuminer-minotaur.o algo/x17/cpuminer-x17-gate.o algo/x17/cpuminer-x17.o algo/x17/cpuminer-x17-4way.o algo/x17/cpuminer-xevan-gate.o algo/x17/cpuminer-xevan.o algo/x17/cpuminer-xevan-4way.o algo/x17/cpuminer-sonoa-gate.o algo/x17/cpuminer-sonoa-4way.o algo/x17/cpuminer-sonoa.o algo/x22/cpuminer-x22i-4way.o algo/x22/cpuminer-x22i.o algo/x22/cpuminer-x22i-gate.o algo/x22/cpuminer-x25x.o algo/x22/cpuminer-x25x-4way.o algo/yespower/cpuminer-yespower-gate.o algo/yespower/cpuminer-yespower-blake2b.o algo/yespower/crypto/cpuminer-hmac-blake2b.o algo/yespower/cpuminer-yescrypt-r8g.o algo/yespower/cpuminer-yespower-opt.o algo/yespower/cpuminer-yespower-ref.o algo/yespower/cpuminer-yespower-blake2b-ref.o asm/cpuminer-neoscrypt_asm.o compat/jansson/libjansson.a -lpthread -lgmp -lcurl -lz

And the error:

algo/m7m/cpuminer-m7m.o: In function `swit2_':
m7m.c:(.text+0xfd): undefined reference to `exp_n'
m7m.c:(.text+0x124): undefined reference to `exp_n'
collect2: error: ld returned 1 exit status
Makefile:2160: recipe for target 'cpuminer' failed

But going into file algo/m7m/m7m.c and just putting static before inline, at function declaration, all works fine. So all this code is c or a mix of C and C++? Github reports 0.5% c++.

jwakely commented 3 months ago

If you are using gcc not g++ then the problem is likely related to https://gcc.gnu.org/gcc-5/porting_to.html#inline

So then it's probably this ^^

That link explains how to make code written using gnu-inline semantics (the default in GCC 4.x) valid for C99 inline semantics (the default in GCC 5 and later).

sumariva commented 3 months ago

I added the "extern" decoration before unit name, at the .c source file and it also compiled without problems. Maybe this C99 semantics is causing the error. This may be an special case if using gcc/g++. A GNU thing.

JayDDee commented 3 months ago

So all this code is c or a mix of C and C++? Github reports 0.5% c++.

That's a good question. The only c++ code is magimath.cpp. It isn't used anywhere but if the file is deleted the compile will fail. The file can be empty, it can be renamed, but a .cpp file must be present. It seems it triggers something that affects the build. Here.s the error without magimath.cpp, note gcc was used, with magimath g++ is used.

gcc -Wno-pointer-sign -Wno-pointer-to-int-cast -O3 -march=native -Wall -Iyes/include -Lyes/lib -Lyes/lib -o cpuminer cpuminer-cpu-miner.o cpuminer-util.o cpuminer-api.o cpuminer-sysinfos.o cpuminer-algo-gate-api.o cpuminer-malloc-huge.o algo/argon2d/cpuminer-argon2d-gate.o algo/argon2d/blake2/cpuminer-blake2b.o algo/argon2d/argon2d/cpuminer-argon2.o algo/argon2d/argon2d/cpuminer-core.o algo/argon2d/argon2d/cpuminer-opt.o algo/argon2d/argon2d/cpuminer-argon2d_thread.o algo/argon2d/argon2d/cpuminer-encoding.o algo/blake/cpuminer-sph_blake.o algo/blake/cpuminer-blake256-hash.o algo/blake/cpuminer-blake512-hash.o algo/blake/cpuminer-blake-gate.o algo/blake/cpuminer-blake.o algo/blake/cpuminer-blake-4way.o algo/blake/cpuminer-sph_blake2b.o algo/blake/cpuminer-sph-blake2s.o algo/blake/cpuminer-blake2s-hash.o algo/blake/cpuminer-blake2s.o algo/blake/cpuminer-blake2b-hash.o algo/blake/cpuminer-blake2b.o algo/blake/cpuminer-blakecoin-gate.o algo/blake/cpuminer-mod_blakecoin.o algo/blake/cpuminer-blakecoin.o algo/blake/cpuminer-blakecoin-4way.o algo/blake/cpuminer-pentablake-gate.o algo/blake/cpuminer-pentablake-4way.o algo/blake/cpuminer-pentablake.o algo/bmw/cpuminer-sph_bmw.o algo/bmw/cpuminer-bmw256-hash-4way.o algo/bmw/cpuminer-bmw512-hash-4way.o algo/bmw/cpuminer-bmw256.o algo/bmw/cpuminer-bmw512-gate.o algo/bmw/cpuminer-bmw512.o algo/bmw/cpuminer-bmw512-4way.o algo/cubehash/cpuminer-cubehash_sse2.o algo/cubehash/cpuminer-cube-hash-2way.o algo/cubehash/cpuminer-sph_cubehash.o algo/echo/cpuminer-sph_echo.o algo/echo/cpuminer-echo-hash-4way.o algo/echo/aes_ni/cpuminer-hash.o algo/gost/cpuminer-sph_gost.o algo/groestl/cpuminer-groestl-gate.o algo/groestl/cpuminer-groestl512-hash-4way.o algo/groestl/cpuminer-groestl256-hash-4way.o algo/groestl/cpuminer-sph_groestl.o algo/groestl/cpuminer-groestl.o algo/groestl/cpuminer-groestl-4way.o algo/groestl/cpuminer-myrgr-gate.o algo/groestl/cpuminer-myrgr-4way.o algo/groestl/cpuminer-myr-groestl.o algo/groestl/aes_ni/cpuminer-hash-groestl.o algo/groestl/aes_ni/cpuminer-hash-groestl256.o algo/fugue/cpuminer-sph_fugue.o algo/fugue/cpuminer-fugue-aesni.o algo/hamsi/cpuminer-sph_hamsi.o algo/hamsi/cpuminer-hamsi-hash-4way.o algo/haval/cpuminer-haval.o algo/haval/cpuminer-haval-hash-4way.o algo/jh/cpuminer-sph_jh.o algo/jh/cpuminer-jh-hash-4way.o algo/jh/cpuminer-jha-gate.o algo/jh/cpuminer-jha-4way.o algo/jh/cpuminer-jha.o algo/keccak/cpuminer-sph_keccak.o algo/keccak/cpuminer-keccak.o algo/keccak/cpuminer-keccak-hash-4way.o algo/keccak/cpuminer-keccak-4way.o algo/keccak/cpuminer-keccak-gate.o algo/keccak/cpuminer-sha3d-4way.o algo/keccak/cpuminer-sha3d.o algo/lanehash/cpuminer-lane.o algo/luffa/cpuminer-luffa_for_sse2.o algo/luffa/cpuminer-luffa-hash-2way.o algo/luffa/cpuminer-sph_luffa.o algo/lyra2/cpuminer-lyra2.o algo/lyra2/cpuminer-sponge.o algo/lyra2/cpuminer-sponge-2way.o algo/lyra2/cpuminer-lyra2-hash-2way.o algo/lyra2/cpuminer-lyra2-gate.o algo/lyra2/cpuminer-lyra2rev2.o algo/lyra2/cpuminer-lyra2rev2-4way.o algo/lyra2/cpuminer-lyra2rev3.o algo/lyra2/cpuminer-lyra2rev3-4way.o algo/lyra2/cpuminer-lyra2re.o algo/lyra2/cpuminer-lyra2z-4way.o algo/lyra2/cpuminer-lyra2z330.o algo/lyra2/cpuminer-lyra2h.o algo/lyra2/cpuminer-lyra2h-4way.o algo/lyra2/cpuminer-allium-4way.o algo/lyra2/cpuminer-phi2-4way.o algo/lyra2/cpuminer-phi2.o algo/m7m/cpuminer-m7m.o algo/nist5/cpuminer-nist5-gate.o algo/nist5/cpuminer-nist5-4way.o algo/nist5/cpuminer-nist5.o algo/nist5/cpuminer-zr5.o algo/panama/cpuminer-panama-hash-4way.o algo/panama/cpuminer-sph_panama.o algo/quark/cpuminer-quark-gate.o algo/quark/cpuminer-quark.o algo/quark/cpuminer-quark-4way.o algo/quark/cpuminer-anime-gate.o algo/quark/cpuminer-anime.o algo/quark/cpuminer-anime-4way.o algo/quark/cpuminer-hmq1725-gate.o algo/quark/cpuminer-hmq1725-4way.o algo/quark/cpuminer-hmq1725.o algo/qubit/cpuminer-qubit-gate.o algo/qubit/cpuminer-qubit.o algo/qubit/cpuminer-qubit-2way.o algo/qubit/cpuminer-deep-gate.o algo/qubit/cpuminer-deep-2way.o algo/qubit/cpuminer-deep.o algo/ripemd/cpuminer-sph_ripemd.o algo/ripemd/cpuminer-ripemd-hash-4way.o algo/ripemd/cpuminer-lbry-gate.o algo/ripemd/cpuminer-lbry.o algo/ripemd/cpuminer-lbry-4way.o algo/scrypt/cpuminer-scrypt.o algo/scrypt/cpuminer-scrypt-core-4way.o algo/scrypt/cpuminer-neoscrypt.o algo/sha/cpuminer-sha1.o algo/sha/cpuminer-sha1-hash.o algo/sha/cpuminer-sha256-hash.o algo/sha/cpuminer-sph_sha2.o algo/sha/cpuminer-sph_sha2big.o algo/sha/cpuminer-sha256-hash-4way.o algo/sha/cpuminer-sha512-hash-4way.o algo/sha/cpuminer-hmac-sha256-hash.o algo/sha/cpuminer-hmac-sha256-hash-4way.o algo/sha/cpuminer-sha256d.o algo/sha/cpuminer-sha256d-4way.o algo/sha/cpuminer-sha256t-gate.o algo/sha/cpuminer-sha256t-4way.o algo/sha/cpuminer-sha256q-4way.o algo/sha/cpuminer-sha256q.o algo/sha/cpuminer-sha512256d-4way.o algo/sha/cpuminer-sha256dt.o algo/shabal/cpuminer-sph_shabal.o algo/shabal/cpuminer-shabal-hash-4way.o algo/shavite/cpuminer-sph_shavite.o algo/shavite/cpuminer-sph-shavite-aesni.o algo/shavite/cpuminer-shavite-hash-2way.o algo/shavite/cpuminer-shavite-hash-4way.o algo/shavite/cpuminer-shavite.o algo/simd/cpuminer-nist.o algo/simd/cpuminer-vector.o algo/simd/cpuminer-sph_simd.o algo/simd/cpuminer-simd-hash-2way.o algo/skein/cpuminer-sph_skein.o algo/skein/cpuminer-skein-hash-4way.o algo/skein/cpuminer-skein.o algo/skein/cpuminer-skein-4way.o algo/skein/cpuminer-skein-gate.o algo/skein/cpuminer-skein2.o algo/skein/cpuminer-skein2-4way.o algo/sm3/cpuminer-sm3.o algo/sm3/cpuminer-sm3-hash-4way.o algo/swifftx/cpuminer-swifftx.o algo/tiger/cpuminer-sph_tiger.o algo/verthash/cpuminer-verthash-gate.o algo/verthash/cpuminer-Verthash.o algo/verthash/cpuminer-fopen_utf8.o algo/verthash/tiny_sha3/cpuminer-sha3.o algo/verthash/tiny_sha3/cpuminer-sha3-4way.o algo/whirlpool/cpuminer-sph_whirlpool.o algo/whirlpool/cpuminer-whirlpool-gate.o algo/whirlpool/cpuminer-whirlpool.o algo/whirlpool/cpuminer-whirlpoolx.o algo/x11/cpuminer-x11-gate.o algo/x11/cpuminer-x11.o algo/x11/cpuminer-x11-4way.o algo/x11/cpuminer-x11gost-gate.o algo/x11/cpuminer-x11gost.o algo/x11/cpuminer-x11gost-4way.o algo/x11/cpuminer-c11-gate.o algo/x11/cpuminer-c11.o algo/x11/cpuminer-c11-4way.o algo/x11/cpuminer-tribus-gate.o algo/x11/cpuminer-tribus.o algo/x11/cpuminer-tribus-4way.o algo/x11/cpuminer-timetravel-gate.o algo/x11/cpuminer-timetravel.o algo/x11/cpuminer-timetravel-4way.o algo/x11/cpuminer-timetravel10-gate.o algo/x11/cpuminer-timetravel10.o algo/x11/cpuminer-timetravel10-4way.o algo/x11/cpuminer-x11evo.o algo/x11/cpuminer-x11evo-4way.o algo/x11/cpuminer-x11evo-gate.o algo/x12/cpuminer-x12-gate.o algo/x12/cpuminer-x12.o algo/x12/cpuminer-x12-4way.o algo/x13/cpuminer-x13-gate.o algo/x13/cpuminer-x13.o algo/x13/cpuminer-x13-4way.o algo/x13/cpuminer-x13sm3-gate.o algo/x13/cpuminer-x13sm3.o algo/x13/cpuminer-x13sm3-4way.o algo/x13/cpuminer-phi1612-gate.o algo/x13/cpuminer-phi1612.o algo/x13/cpuminer-phi1612-4way.o algo/x13/cpuminer-skunk-gate.o algo/x13/cpuminer-skunk-4way.o algo/x13/cpuminer-skunk.o algo/x13/cpuminer-x13bcd-4way.o algo/x13/cpuminer-x13bcd.o algo/x14/cpuminer-x14-gate.o algo/x14/cpuminer-x14.o algo/x14/cpuminer-x14-4way.o algo/x14/cpuminer-veltor-gate.o algo/x14/cpuminer-veltor.o algo/x14/cpuminer-veltor-4way.o algo/x14/cpuminer-polytimos-gate.o algo/x14/cpuminer-polytimos.o algo/x14/cpuminer-polytimos-4way.o algo/x14/cpuminer-axiom.o algo/x15/cpuminer-x15-gate.o algo/x15/cpuminer-x15.o algo/x15/cpuminer-x15-4way.o algo/x16/cpuminer-x16r-gate.o algo/x16/cpuminer-x16r.o algo/x16/cpuminer-x16r-4way.o algo/x16/cpuminer-x16rv2.o algo/x16/cpuminer-x16rv2-4way.o algo/x16/cpuminer-x16rt.o algo/x16/cpuminer-x16rt-4way.o algo/x16/cpuminer-hex.o algo/x16/cpuminer-x20r.o algo/x16/cpuminer-x21s-4way.o algo/x16/cpuminer-x21s.o algo/x16/cpuminer-minotaur.o algo/x17/cpuminer-x17-gate.o algo/x17/cpuminer-x17.o algo/x17/cpuminer-x17-4way.o algo/x17/cpuminer-xevan-gate.o algo/x17/cpuminer-xevan.o algo/x17/cpuminer-xevan-4way.o algo/x17/cpuminer-sonoa-gate.o algo/x17/cpuminer-sonoa-4way.o algo/x17/cpuminer-sonoa.o algo/x22/cpuminer-x22i-4way.o algo/x22/cpuminer-x22i.o algo/x22/cpuminer-x22i-gate.o algo/x22/cpuminer-x25x.o algo/x22/cpuminer-x25x-4way.o algo/yespower/cpuminer-yespower-gate.o algo/yespower/cpuminer-yespower-blake2b.o algo/yespower/crypto/cpuminer-hmac-blake2b.o algo/yespower/cpuminer-yescrypt-r8g.o algo/yespower/cpuminer-yespower-opt.o algo/yespower/cpuminer-yespower-ref.o algo/yespower/cpuminer-yespower-blake2b-ref.o asm/cpuminer-neoscrypt_asm.o -lcurl -lz -ljansson -lpthread -lgmp /usr/bin/ld: algo/m7m/cpuminer-m7m.o: in functionswit2_': m7m.c:(.text+0xd2): undefined reference to pow' /usr/bin/ld: m7m.c:(.text+0xe9): undefined reference tosin' /usr/bin/ld: m7m.c:(.text+0x12c): undefined reference to exp' /usr/bin/ld: m7m.c:(.text+0x156): undefined reference toexp' /usr/bin/ld: algo/m7m/cpuminer-m7m.o: in function scanhash_m7m_hash': m7m.c:(.text+0xeaf): undefined reference tosqrt' /usr/bin/ld: m7m.c:(.text+0xf48): undefined reference to sqrt' /usr/bin/ld: algo/m7m/cpuminer-m7m.o: in functionsw2_': m7m.c:(.text+0xfba): undefined reference to sqrt' collect2: error: ld returned 1 exit status make[2]: *** [Makefile:2146: cpuminer] Error 1 make[2]: Leaving directory '/home/coin/devel/cpuminer-opt/23.16/cpuminer-opt-24.1-dev' make[1]: *** [Makefile:6192: all-recursive] Error 1 make[1]: Leaving directory '/home/coin/devel/cpuminer-opt/23.16/cpuminer-opt-24.1-dev' make: *** [Makefile:1175: all] Error 2

jwakely commented 3 months ago

If you're linking a mix of C and C++ then using g++ to link is generally correct. That's not the problem here, the problem is the change to what inline means between GCC 4 and GCC 5.

JayDDee commented 3 months ago

If you're linking a mix of C and C++ then using g++ to link is generally correct. That's not the problem here, the problem is the change to what inline means between GCC 4 and GCC 5.

I've had no problems going back to gcc-4.8 so it doesn't seem to be related to the gcc version unless the said change was backported. I know it won't compile on Centos-6 (gcc-4.4) for various reasons but this appears to be gcc-6.

This is the only case I'm aware of and it happens to be a custom build environment. Something in that environment creates the unique situation where the linker is looking for a linkable function that should alwas be inlined.

I'm somewhat curious of the root cause but I'm satisfied with adding static to the inlines

jwakely commented 3 months ago

@sumariva is using CFLAGS="-I$HOME/include"

If that overrides the default CFLAGS and replaces any optimization options like -O2 then it means the code will be compiled with no optimization, and so no inlining takes place. That means all the "inline" functions need to be defined (either as static inline or extern inline). The functions that should always be inlined won't be inlined.

Presumably compiling without optimizations makes a miner incredibly slow, and wastes even more power than normal shitcoin mining.

sumariva commented 3 months ago

Humm, I did noted that CFLAGS would override all stuff. I will try update the build process and add -O3. Thanks for advice.

UPDATE, I runned configure with the following, and code compiled without linker errors: LIBS="-lcurl -lz" LDFLAGS="-L$HOME/lib" CPPFLAGS="-I$HOME/include" ./configure --prefix=$HOME Yeahh, GCC looks like it needs optimizations on, so that linker can find the things. CPPFLAGS is the right flag to add additional include dirs.

Should I add -O3, max optimizations?

JayDDee commented 3 months ago

Unoptimized is not supported, -O3 is recommended but -O2 also works but with a noticble loss in performance.

I'll make the code changes anyway for consistency with other inline definitions.

Maybe you should add CFLAGS to CPPFLAGS instead of overwriting it.

sumariva commented 3 months ago

How the right way to augment CFLAGS? I just followed tips from configure

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CCAS        assembler compiler command (defaults to CC)
  CCASFLAGS   assembler compiler flags (defaults to CFLAGS)
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags

Use these variables to override the choices made by 'configure' or to help
it to find libraries and programs with nonstandard names/locations.

I am trying to help configure find libraries, to to force C flags.

jwakely commented 3 months ago

The -I option is a preprocessor option, so use CPPFLAGS for that, not CFLAGS, and not CPP_FLAGS.

sumariva commented 3 months ago

I got how to get rid off magimath.cpp. I removed it from Makefile.am, delete file at folder. Now configure will run only gcc as all source are .c file, which are the C source files. But now, since it is C only source compiled, they say that there is no math functions include by default: https://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c So Just added -lm to configure, and it linked the missing symbols: LIBS="-lcurl -lz -lm" LDFLAGS="-L$HOME/lib" CPPFLAGS="-I$HOME/include" CFLAGS="-O3 -march=native -Wall" ./configure --prefix=$HOME

Hope get code better!

JayDDee commented 3 months ago

Awesome! So linking with g++ instead of gcc is not about c++ but linking math. Thanks.

JayDDee commented 3 months ago

The -I option is a preprocessor option, so use CPPFLAGS for that, not CFLAGS, and not CPP_FLAGS.

Brain fart, I meant CXXFLAGS but that was wrong too because the problem wasn't due to using g++ for linking. I had previously done that to add a gnu++ standard when cpuminer actually had some c++ code.

CXXFLAGS="$CFLAGS -std=gnu++11"

JayDDee commented 2 months ago

Removing the magimath hack worked on Linux but on Windows it segfaulted in sha256 code that was unchanged from the previous version. Something weird there that requires a deep dive. As a result I'm pulling this change from the next release. The static inline changes will still be included.

sumariva commented 2 months ago

Where this sha256 is located, I may try look at it. Used the mingw64 gnu? I do not have this tool chain installed, but may try.

JayDDee commented 2 months ago

It's located in algo/sha/sha256-hash.h which uses some trickery to call the correct targets. The crash I observerd was when calling sha256_ctx_init from scanhash_yespower. The CPU did not have SHA so the target was sph_sha256_init. I haven't found any other instances of crashes, x11 ran without crashing, but also without sha256. I tested only using Msys2/mingw to build from a Windows host, I did not test using the package build process which is done on Ubuntu-20.04/mingw host.

I haven't done any further digging. Coincidentally sha256 is also used to generate the merkl root hash for all algos but that didn't seem to crash, it was only when called by yespower. The failed test used gcc-13.2 in case it's a compiler version issue.

Edit: I apppreciate your interest in this, I hope to learn something from it. My coding background is not GNU/Linux/x86/C based.

Edit: Power2b also crashes, it's the same as yespower but replaces sha256 with blake2b. M7m does not crash and it uses sha256. Scrypt crashes, it uses sha256. Scrypt and yespower use seperate but almost identical implementations of the scrypt hash function and seems to be only thing in common.

JayDDee commented 2 months ago

v24.1 is released with a fix to the title issue.

Regarding the gcc vs g++ linker issue, I don't have any leads. Perhaps it was the way I did the linkage, adding it to the same Makefile.am command that adds gmp linking, but it's just a wild guess. If you're still interested then this issue can remain open. I'm curious but stumped.