5

Why is it not possible recompile GLibc turning off all the optimizations (i.e., -O0)?

Particularly in doing this:

make CFLAGS='-O0 -w' CXXFLAGS='-O0 -w'

I get:

 #error "glibc cannot be compiled without optimization"
badnack
  • 737
  • 1
  • 11
  • 20

3 Answers3

7

When I Google the error, the first result tells me exactly why.

"In the early startup of the dynamic loader (_dl_start), before relocation of the PLT, you cannot make function calls. You must inline the functions you will use during early startup, or call compiler builtins (__builtin_*).

Without optimizations enabled GCC will not inline functions. The early startup of the dynamic loader will make function calls via an unrelocated PLT and crash." -- Carlos O'Donell

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
user541686
  • 205,094
  • 128
  • 528
  • 886
  • 2
    Why not just add the inline option (like -finline-functions and -finline-small-functions) and turn off the other optimizations? I tried but it doesn't work anyway. – badnack May 07 '15 at 01:13
  • @badnack: I don't know, I'm not the one who set this restriction... I'm just a messenger – user541686 May 07 '15 at 01:14
  • This stackoverflow question *is* the first result now. You might not want to be passive aggressive about googling for this and other reasons. – kcghost Mar 19 '19 at 11:54
2

Basically: "glibc is voodoo!" This one "library of all libraries" has a very special place in any system, because virtually(?) everything else in the entire system relies upon it.

Therefore, if "someone out there" took the time to prevent you from compiling this library "without optimizations," I cordially invite you to take him/her at their word. "There must be a [very good] reason."

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
0

By Slackware operating system version 15. In the folder:

/home/wsys0/glibc/glibc-2.36/build/

Create a file name cmp:

chmod 700 cmp

Put the following line into cmp:

export CFLAGS="-Wno-error -O3 -g"
../configure --prefix=/home/wsys0/glibc/out --disable-sanity-checks

Then run: ./cmp, to install it.

Reference: https://sky-bro.github.io/posts/compile-and-use-your-own-glibc/

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77