Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling with -march=armv8-a+crc+nocrypto results in linking error #7042

Closed
Fugoes opened this issue Jun 29, 2020 · 12 comments
Closed

Compiling with -march=armv8-a+crc+nocrypto results in linking error #7042

Fugoes opened this issue Jun 29, 2020 · 12 comments
Assignees
Labels

Comments

@Fugoes
Copy link

Fugoes commented Jun 29, 2020

Expected behavior

The shared library should link without error.

Actual behavior

For the following program named err.cpp:

#include "rocksdb/db.h"

int main() {
        rocksdb::DB* db;
        rocksdb::Options options;
        options.create_if_missing = true;
        rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);
        return 0;
}

Compile and link it with:

g++ -lrocksdb err.cpp

There are linking errors:

/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: /usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../lib64/librocksdb.so: undefined reference to `crc32c_arm64(unsigned int, unsigned char const*, unsigned int)'
/usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../aarch64-unknown-linux-gnu/bin/ld: /usr/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/../../../../lib64/librocksdb.so: undefined reference to `crc32c_runtime_check()'
collect2: error: ld returned 1 exit status

Steps to reproduce the behavior

Compile rocksdb's shared library (version 5.18.4, though I think many versions have this issue) with -march=armv8-a+crc+nocrypto compile option and follow the steps in the 'Actual behavior' section.


What's more, the default make shared_lib seems to detect CPU flags wrongly, for a +crc+nocrypto CPU, it produces +crc+crypto options, and lead to SIGILL.

@adamretter
Copy link
Collaborator

To decipher armv8-a+crc+nocrypto

  1. armv8-a = ARMv8 application architecture profile.
  2. crc = With CRC extension.
  3. nocrypto Without Cryptographic extension.

@Fugoes
Copy link
Author

Fugoes commented Jun 29, 2020

To decipher armv8-a+crc+nocrypto

1. `armv8-a` = ARMv8 application architecture profile.

2. `crc` = With CRC extension.

3. `nocrypto` Without Cryptographic extension.

I understand the meaning of these flags. I could workaround this issue by using armv8-a+nocrypto+nocrc, though my CPU do have crc capacity. But I think this might be a bug in the build system or the util/crc32c_arm64.h file?

@adamretter
Copy link
Collaborator

@Fugoes Sure. I didn't understand the flags though - which is why I added them for my own reference ;-)

@Fugoes
Copy link
Author

Fugoes commented Jun 29, 2020

What's more, most aarch64 server or high ends Android phone should have both crc and crypto I think. I encounter this issue on a raspberry pi 4 b XD.

@siying
Copy link
Contributor

siying commented Jun 29, 2020

For those who created the file, @HouBingjian , @Zhiwei-Dai and @guyuqi any thought how we should resolve this?

@grooverdan
Copy link
Contributor

grooverdan commented Jul 30, 2020

In addition to the flags discussion here (that I'm following closely) note that @guyuqi who submitted the same code to mariadb (MariaDB/server#772) missed a getauxval runtime check on HWCAP_PMULL (1 << 4) (wip fix - for maria- mysqlonarm/server@1bd43b6) which will cause Cortex-A72 to SIGILL (ref MariaDB/mariadb-docker#318 and https://jira.mariadb.org/browse/MDEV-23030).

@guyuqi
Copy link
Contributor

guyuqi commented Jul 30, 2020

Yep, HWCAP_PMULL should be also checked in runtime routine like HWCAP_CRC32 does. Sorry for missing it.
@grooverdan Thanks for your comments, it's informative.
@siying I would like to submit a PR to fix it.

@dr-m
Copy link

dr-m commented Jul 30, 2020

MariaDB/server#1645 introduces a revised runtime check for the CRC-32C acceleration:

int crc32c_aarch64_available(void)
{
  return !(~getauxval(AT_HWCAP) & (HWCAP_CRC32 | HWCAP_PMULL));
}

I expect to merge it as soon as it has been validated on a (pmull capable) CI system.

facebook-github-bot pushed a commit that referenced this issue Sep 22, 2020
Summary:
Issue:#7042

No PMULL runtime check will lead to SIGILL on a Raspberry pi 4.

Leverage 'getauxval' to get Hardware-Cap to detect whether target
platform does support PMULL or not in runtime.

Consider the condition that the target platform does support crc32 but not support PMULL.
In this condition, the code should leverage the crc32 instruction
rather than skip all hardware crc32 instruction.

Pull Request resolved: #7233

Reviewed By: jay-zhuang

Differential Revision: D23790116

fbshipit-source-id: a3ebd821fbd4a38dd2f59064adbb7c3013ee8140
codingrhythm pushed a commit to SafetyCulture/rocksdb that referenced this issue Mar 5, 2021
Summary:
Issue:facebook#7042

No PMULL runtime check will lead to SIGILL on a Raspberry pi 4.

Leverage 'getauxval' to get Hardware-Cap to detect whether target
platform does support PMULL or not in runtime.

Consider the condition that the target platform does support crc32 but not support PMULL.
In this condition, the code should leverage the crc32 instruction
rather than skip all hardware crc32 instruction.

Pull Request resolved: facebook#7233

Reviewed By: jay-zhuang

Differential Revision: D23790116

fbshipit-source-id: a3ebd821fbd4a38dd2f59064adbb7c3013ee8140
@adamretter adamretter added the arm label Apr 26, 2021
tchaikov pushed a commit to ceph/rocksdb that referenced this issue May 1, 2021
Summary:
Issue:facebook#7042

No PMULL runtime check will lead to SIGILL on a Raspberry pi 4.

Leverage 'getauxval' to get Hardware-Cap to detect whether target
platform does support PMULL or not in runtime.

Consider the condition that the target platform does support crc32 but not support PMULL.
In this condition, the code should leverage the crc32 instruction
rather than skip all hardware crc32 instruction.

Pull Request resolved: facebook#7233

Reviewed By: jay-zhuang

Differential Revision: D23790116

fbshipit-source-id: a3ebd821fbd4a38dd2f59064adbb7c3013ee8140
(cherry picked from commit 29f7bbe)
@sike-evolve
Copy link
Contributor

@Fugoes I'd like to know how you did compile RocksDB shared library. I'm trying to reproduce the same problem but I couldn't.

@riversand963
Copy link
Contributor

Since #7233 is merged, should we close this one?

@alanpaxton
Copy link
Contributor

@siying Could you clarify for me if @guyuqi fix #7233 resolves this entire issue ? I want to know if I (as the inheritor of sike's work) should pick it up again and try to repro ?

@alanpaxton
Copy link
Contributor

I have acquired a Pi 4 B and explicitly built the shared lib at HEAD with nocrypto (-march=armv8-a+crc+nocrypto) instead of the current default of (-march=armv8-a+crc+crypto). In both cases, the symbols reported missing above are found, and the snippet compiles and runs successfully as err.cpp in ./examples (use nm to check the symbols in a library)

I am using 64bit PiOS.

(cd examples; g++ -fno-rtti err.cpp -oerr -L.. -lrocksdb -I../include -O2 -std=c++17 -lpthread -lrt -ldl -lz -std=c++17)

NOTE ALSO that the 4B DOES support armv8-a crypto instructions, it has a cortex-a72 as described in https://developer.arm.com/documentation/100097/0003/introduction/about-the-cortex-a72-processor-cryptography-engine?lang=en

It does not seem possible to build 5.18 with the current toolchain, so testing whether the problem is reproducible there has not been done. But crc32c_arm64.cc logic has changed significantly, and in particular is based on the definition of __ARM_FEATURE_CRYPTO which is defined when building with crypto; see the following incantations for determining the headers defined by g++

echo | gcc -march=armv8-a+crc+crypto -dM -E - | grep ARM

and undefined without

echo | gcc -march=armv8-a+crc+nocrypto -dM -E - | grep ARM

It seems then, that the reported SIGILL is the one fixed by #7233

tldr; actual behaviour should now be the expected behaviour.

@Fugoes @siying I think this can be closed now.

@ajkr ajkr closed this as completed Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants