John The Ripper compile error (Gentoo)

So I was trying to build John The Ripper 1.8.0 but it failed here:

In file included from /usr/include/string.h:494,
from c3_fmt.c:20:
In function ‘strncpy’,
inlined from ‘binary’ at c3_fmt.c:173:2:
/usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 128 equals destination size [-Wstringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64-pc-linux-gnu-gcc DES_fmt.o DES_std.o DES_bs.o DES_bs_b.o BSDI_fmt.o MD5_fmt.o MD5_std.o BF_fmt.o BF_std.o AFS_fmt.o LM_fmt.o trip_fmt.o dummy.o batch.o
bench.o charset.o common.o compiler.o config.o cracker.o crc32.o external.o formats.o getopt.o idle.o inc.o john.o list.o loader.o logger.o math.o memory.o m
isc.o options.o params.o path.o recovery.o rpp.o rules.o signals.o single.o status.o tty.o wordlist.o unshadow.o unafs.o unique.o c3_fmt.o x86-64.o -Wl,-O1 -W
l,–as-needed -fopenmp -lcrypt -o ../run/john
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: john.o: in function `main’:
john.c:(.text.startup+0x89): undefined reference to `CPU_detect’
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: john.c:(.text.startup+0xc0): undefined reference to `CPU_detect’
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: john.c:(.text.startup+0xed): undefined reference to `CPU_detect’
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: john.c:(.text.startup+0x532): undefined reference to `CPU_detect’
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:835: ../run/john] Error 1
make[1]: Leaving directory ‘/var/tmp/portage/app-crypt/johntheripper-1.8.0/work/john-1.8.0/src’
make: *** [Makefile:184: linux-x86-64] Error 2
make: Leaving directory ‘/var/tmp/portage/app-crypt/johntheripper-1.8.0/work/john-1.8.0/src’
* ERROR: app-crypt/johntheripper-1.8.0::gentoo failed (compile phase):
* emake failed
*
* If you need support, post the output of `emerge –info ‘=app-crypt/johntheripper-1.8.0::gentoo’`,
* the complete build log and the output of `emerge -pqv ‘=app-crypt/johntheripper-1.8.0::gentoo’`.
* The complete build log is located at ‘/var/tmp/portage/app-crypt/johntheripper-1.8.0/temp/build.log’.
* The ebuild environment file is located at ‘/var/tmp/portage/app-crypt/johntheripper-1.8.0/temp/environment’.
* Working directory: ‘/var/tmp/portage/app-crypt/johntheripper-1.8.0/work/john-1.8.0’
* S: ‘/var/tmp/portage/app-crypt/johntheripper-1.8.0/work/john-1.8.0’

It turns out to be related to compiler options. Specifically I needed to NOT use -march=native and I needed to have “avx” in my CPU_FLAGS_X86. With those two changes I was able to compile (emerge) without further issues. After it finished compiling I switched my -march flag back to native.