Search code examples
clinuxlinux-kernelruntimecompile-time

Checking linux version in compile time or runtime


I use the function prctl which was introduced in Linux 2.1.57. I do the following:

// function 'prctl' is linux only and was introduced in  version
#ifdef __linux__
    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,57)
        prctl(PR_SET_PDEATHSIG, SIGKILL);
    #endif
#endif

But what happens if I run my binary in lower version of linux? Program will crash or not load?

Do I need to replace compile time checks by runtime (with utsname()->release) or use both compile and runtime checks?


Solution

  • If you compile your program on modern Linux but try to run it on older one, there are 2 possibilites:

    1. Program was compiled dynamically. In this case, most likely it won't even load - because it will be linked to modern glibc version, which would not exist on older Linux system.
    2. Program was compiled statically (meaning necessary glibc calls were bundled with your executable, making it larger). In that case, it will load, but most likely either crash, exit prematurely or simply skip offending call.

    At any rate, it will not work normally.