Is there a best practice on setting up glibc on docker alpine linux base image?

Yes there is, I’ve used a custom built glibc to install a JRE on it. You can find it here You can use wget or curl to get the code and apk to install them UPDATED commands see comments below apk –no-cache add ca-certificates wget wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk apk add glibc-2.28-r0.apk … Read more

Compiling without libc

If you compile your code with -nostdlib, you won’t be able to call any C library functions (of course), but you also don’t get the regular C bootstrap code. In particular, the real entry point of a program on Linux is not main(), but rather a function called _start(). The standard libraries normally provide a … Read more

difference between gcc -D_FORTIFY_SOURCE=1 and -D_FORTIFY_SOURCE=2

From the manual page for the Feature Test Macros (man 7 feature_test_macros) _FORTIFY_SOURCE (since glibc 2.3.4) Defining this macro causes some lightweight checks to be performed to detect some buffer overflow errors when employing various string and memory manipulation functions (for example, memcpy, memset, stpcpy, strcpy, strncpy, strcat, strncat, sprintf, snprintf, vsprintf, vsnprintf, gets, and … Read more

Using C++ library in C code

Yes, this is certainly possible. You will need to write an interface layer in C++ that declares functions with extern “C”: extern “C” int foo(char *bar) { return realFoo(std::string(bar)); } Then, you will call foo() from your C module, which will pass the call on to the realFoo() function which is implemented in C++. If … Read more

Multiple glibc libraries on a single host

It is very possible to have multiple versions of glibc on the same system (we do that every day). However, you need to know that glibc consists of many pieces (200+ shared libraries) which all must match. One of the pieces is ld-linux.so.2, and it must match libc.so.6, or you’ll see the errors you are … Read more

Why does glibc’s strlen need to be so complicated to run quickly?

You don’t need and you should never write code like that – especially if you’re not a C compiler / standard library vendor. It is code used to implement strlen with some very questionable speed hacks and assumptions (that are not tested with assertions or mentioned in the comments): unsigned long is either 4 or … Read more