Use clang-tindy on VoidLinux

To use clang-tidy on VoidLinux, you should install clang-tools-extra first:

# xbps-install -Suv clang-tools-extra

Take following code as an example:

# cat main.cpp
struct Base
{
        virtual void do_thing() = 0;
        int data;
};

struct Derived : Base
{
        virtual void do_thing(int i) {}
};

int main()
{
}

Use clang-tidy to check it:

# clang-tidy -checks=* *.cpp --
387 warnings generated.
/root/main.cpp:1:8: warning: constructor does not initialize these fields: data [cppcoreguidelines-pro-type-member-init]
struct Base
       ^
/root/main.cpp:4:6: warning: member variable 'data' has public visibility [misc-non-private-member-variables-in-classes]
        int data;
            ^
Suppressed 384 warnings (384 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

 

Pcap develop package is needed in compiling tcpdump

On a fresh VoidLinux, I compiled tcpdump source code and met following errors during configuration:

# ../configure CFLAGS='-g -O0'
......
checking for local pcap library... not found
checking for pkg-config... no
checking for pcap-config... no
checking for main in -lpcap... no
configure: error: see the INSTALL doc for more info

I was sure libpcap was already installed. After some investigating, I found the root cause was libpcap-devel was needed:

# xbps-install -Suv libpcap-devel
......

Then the issue was fixed.

Build legacy test files in HElib

In HElib src directory, there are some files which begin with Test_ prefix. Since HElib uses CMake to build it, these Test_* files won’t be compiled by default. To build and use them, ENABLE_LEGACY_TEST option should be turned ON:

$ cmake -DENABLE_LEGACY_TEST=ON ..
$ make

The executable files will be generated in bin folder:

$ cd bin/
$ ls
Test_approxNums     Test_bootstrapping  Test_General    Test_PAlgebra      Test_PtrVector          Test_ThinEvalMap
Test_binaryArith    Test_EaCx           Test_intraSlot  Test_Permutations  Test_Replicate          Test_Timing
Test_binaryCompare  Test_EvalMap        Test_IO         Test_PolyEval      Test_tableLookup
Test_Bin_IO         Test_extractDigits  Test_matmul     Test_Powerful      Test_ThinBootstrapping

 

Fix “Permission denied, please try again.” issue when using git protocol

If you want to use git instead of https protocol, you need to leverage SSH keys. otherwise you will encounter following errors:

$ git clone git@xxxxx/xxx.git
Cloning into 'xxx'...
git@xxx's password:
Permission denied, please try again.

If you don’t have SSH keys, you need to use ssh-keygen to generate a pair of keys, then copy public key into your account. The following picture shows how to add key in gitlab(github is similar):

Reference:
Which remote URL should I use?

The takeaways of GCC optimization

GCC optimization is a good document but a little verbose. I summarize the takeaways of it in this post:

(1) Use -march to generate the optimized code for specified CPU. E.g., -march=native. But beware that the code will not have backwards compatibility for older/different CPUs.

(2) -O2 is recommended. But if play with cmake, “cmake -DCMAKE_BUILD_TYPE=Release ..” will use -O3 to compile code. At least from my own experience,-O3 should be OK.

(3) -pipe has no effect on the generated code but makes compilation fast. If the system has enough memory, use it.

So the best method of compiling code using gcc should be:

# gcc -march=native -O2 -pipe test.c -o test

Or use -O3 instead of -O2? I dunno, choose -O2 or -O3 at your own risk.