8

I need to compile glibc from source with debug symbols.

  1. Where do I specify the -g option for this?
  2. How do I later make a sample code link to this particular glibc rather than the one installed on my system?
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
woodstok
  • 2,704
  • 3
  • 34
  • 50
  • If you are not familiar with compilation of *Glibc* I would avoid doing that. If you only need the debug information of *glibc*, install the appropriate packages providing it, e.g. `libc6-dbg` on Debian or Ubuntu... – Basile Starynkevitch Apr 13 '12 at 10:26
  • That wouldnt help because i need to modify some of the files and check how they are working. – woodstok Apr 13 '12 at 10:36
  • The hard part is how to actually use it afterwards: https://stackoverflow.com/questions/56810/how-do-i-start-threads-in-plain-c Good luck with that! :-) – Ciro Santilli OurBigBook.com Sep 22 '18 at 03:59

2 Answers2

7

I need to compile glibc from source with debug symbols

You will have hard time compiling glibc without debug symbols. A default ./configure && make will have -g on compile line.

How do i later make a sample code link to this particular glibc rather than the one installed on my system?

This is somewhat tricky, and answered here.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • 1
    `-g` apparently comes from: https://sourceware.org/git/?p=glibc.git;a=blob;f=Makeconfig;h=751e9ffa32149ba8854cc6fb7404a5902305dc37;hb=HEAD#l341 in 2.21 – Ciro Santilli OurBigBook.com Jun 06 '15 at 21:35
  • 1
    No. At least not for compilation of files comprising the dynamic linker-loader (`ld.so[.new]`). Here's the captured invocation I got for one of them: `gcc dl-reloc.c -c -std=gnu11 -fgnu89-inline -O2 -Wall -Wundef -Wwrite-strings -fmerge-all-constants -frounding-math -fstack-protector-strong -march=x86-64 -pipe -Wstrict-prototypes -Wold-style-definition -fno-stack-protector -DSTACK_PROTECTOR_LEVEL=0 -ftls-model=initial-exec -I…`. There are _symbols_ in the resulting executable, but not full-fledged debug info one gets with `-g` (as can easily be seen with `dwarfdump` or by the mere size of it). – Vladislav Ivanishin Apr 22 '19 at 20:33
3

It is probably a matter of configure tricks. First, try configure --help and then, either configure --enable-debug or perhaps configure CC='gcc -g' or even configure CFLAGS='-g'

For your sample code, perhaps consider playing LD_LIBRARY_PATH or LD_PRELOAD tricks (assuming linking to dynamic library).

But be very careful, since the Glibc is the cornerstone of Gnu/Linux like systems.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547