Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Failure to run monero (Illegal instruction) on core2duo cpu (AES ?) #18

Open
jeandestouches opened this issue Aug 12, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@jeandestouches
Copy link

Hi,
I'm unable to run monero on my core2 system. It says : "Illegal instruction".
I think it is related to the fact, that by default monero is configured with AES support
See : https://github.com/monero-project/monero/blob/82149bfe441e56d5f9d72a13ffa25ce1df6d8391/CMakeLists.txt (line 741)

and there is no USE flag to disable it currently (there is no AES support on my core2 duo)

with gdb, the output is the following :

0x0000555555891a6a in _GLOBAL__sub_I_crypto.cpp ()

Maybe it is something else, I'm not sure, but on an other system (with AES support in the cpu), it works fine.

@00-matt 00-matt added the bug Something isn't working label Aug 13, 2021
@jeandestouches
Copy link
Author

jeandestouches commented Aug 13, 2021

Tried to explicitely disable aes support by adding -DNO_AES=ON (in the ebuild after having copied it in my localrepo), no luck. (Still throwing illegal instruction)
I'm not sure where else look, the system is fully up-to-date, using GCC 10.3.0 and hardened profile.

@jeandestouches
Copy link
Author

jeandestouches commented Aug 13, 2021

Some news, I forgot to mention that all my packages are built in a chroot (-march=core2) on a AMD system. (-march=bdver2) If I compile monero directly on my core2 laptop (instead of pulling the binary from my AMD system chroot), then it works perfectly ! (and no need to tweak the current ebuild)
This is the first time in two years of using this chroot that I encounter such issue though.. I suspect that while building the package in the chroot, monero detects AES support even though CPU_FLAGS is correctly set in the chroot (CPU_FLAGS_X86="mmx mmxext sse sse2 sse3 sse4_1 ssse3") so AES instruction should be ignored from what I understand. Let me know what you think.

@00-matt
Copy link
Member

00-matt commented Aug 14, 2021

It seems like the Monero CMake configure scripts just assume that x86 has AES extensions unless you explicitly pass -DNO_AES=ON. Interesting that this didn't fix it for you.

I'll try to have a play around with this soon.

@jeandestouches
Copy link
Author

jeandestouches commented Aug 14, 2021

Indeed, passing "-DNO_AES=ON" should disable AES, according to the log, it says "Disabling AES blabla" but the resulting binary is still throwing "Illegal instruction", this only happen when it is built inside the chroot on my AMD system with aes enabled cpu.

https://gist.githubusercontent.com/jeandestouches/004aa8f441ca53e451fb9a389116915d/raw/7fe925db081747feddbc36e016d604414f6dd72b/monero-0.17.2.0-core2 (laptop build)

https://gist.githubusercontent.com/jeandestouches/004aa8f441ca53e451fb9a389116915d/raw/7fe925db081747feddbc36e016d604414f6dd72b/monero-0.17.2.0-core2-chroot (chroot build)

Looking at the chroot build log at the "Compiler flags" part though,

-march=core2 -O2 -pipe -pthread -maes -march=native

I suspect the redudancy of -march with -march=core2 and -march=native is causing issue when the package is built inside a chroot.

An user on gentoo forum said :
"Well, I guess it doesn't really matter what the faulting instruction is. With -march=native on a computer compiling that's not of the same architecture, it can generate bad instructions regardless if -maes is also put there.

I wouldn't be surprised if it put in aes instructions as it's probably doing encryption of sorts."

I think it is more likely an issue with monero cmake.
For now, I can make an exception for this package and compile it straight on my laptop (it works) instead of pulling the non working binary.

Hopefully, this helps a little bit to eventually find a way to solve this. I would understand if this bug is closed since it is related to my particular setup -building inside a chroot for different arch- and not strictly related to the ebuild.
Anyway, thanks for your help.

@jeandestouches
Copy link
Author

jeandestouches commented Aug 14, 2021

Fixed ! :)
user eccerr0r on gentoo forum suggested to add -DARCH=default to the ebuild. This works 100% and the resulting executable works fine. Now I don't know if this can be added to the monero ebuild in this overlay. But at least it fixes the issue for my particular case, so meanwhile I'll just copy the ebuild to my localrepo with that minor little change added.

(Build Optimization - The CMake build system will, by default, create optimized native builds for your particular system type when you build the software. Using this method, the binaries created provide a better experience and all together faster performance. However, if you wish to create portable binaries that can be shared between systems, specify -DARCH=default in your CMake arguments during the build process. Note that portable binaries will have a noticable difference in performance than native binaries. For this reason, it is always best to build for your particuar system if possible.)

--- monero-0.17.2.0.ebuild.old   2021-08-14 07:51:20.920625609 -0600
+++ monero-0.17.2.0.ebuild   2021-08-14 07:51:43.620625493 -0600
@@ -72,6 +72,7 @@
       # The user can decide for themselves if they want to use ccache.
       -DUSE_CCACHE=OFF
       -DUSE_DEVICE_TREZOR=$(usex hw-wallet)
+      -DARCH=default
    )
 
    cmake_src_configure

No more redudancy of -march as you can see :

Build type      Gentoo
Install path    /usr
Compiler flags:
C               -march=core2 -O2 -pipe -pthread -maes  -fno-strict-aliasing -std=c11 -D_GNU_SOURCE   -Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized -Wlogical-op -Wno-error=maybe-uninitialized -Wno-error=cpp -Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes  -fPIC  -Wformat -Wformat-security -fstack-protector -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -fno-strict-aliasing
C++             -march=core2 -O2 -pipe -pthread -maes  -fno-strict-aliasing -std=c++11 -D_GNU_SOURCE   -Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized -Wlogical-op -Wno-error=maybe-uninitialized -Wno-error=cpp -Wno-reorder -Wno-missing-field-initializers  -fPIC  -Wformat -Wformat-security -fstack-protector -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -fno-strict-aliasing -ftemplate-depth=900
Linker flags:
Executable      -Wl,-O1 -Wl,--as-needed  -pie -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack 
Module          -Wl,-O1 -Wl,--as-needed
Shared          -Wl,-O1 -Wl,--as-needed

-- Configuring done

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants