Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's a couple of my most fun ones.

1. Mac build crashes with "illegal instruction" due to AVX512 instruction that the Mac CPU doesn't support. Problem is though that the AVX512 code is in its own file, and this particular function is only called if AVX512 is supported by the CPU. So this code should never even run, and in fact it doesn't, so what gives?

Turns out that the AVX file is compiled with -mavx512f (sensible enough), and that this file includes a header that defines:

    const float SQUARE_ROOT_OF_2 = (float)sqrt(2.0f);
Turns out that GCC compiles this to code including AVX512 instructions, which get executed completely bypassing the "if AVX512 is supported" check.

Fix: Change the constant to a numeric value.

2. Code crashes oddly on shutdown. Debugging shows destructors run twice.

Turns out the project is split into a large number of libraries one of which is 'shared', and includes very general purpose stuff like logging. 'shared' then gets linked into other libraries, which get linked into the resulting binary.

When linking statically this has the fun result that libfoo links to libshared, libbar links to libshared, and then libfoo and libbar make up the binary. Now there are two copies of libshared that end up in the binary, and this results in static variables being constructed and destructed twice.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: