7

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?
Gabriel Staples
  • 22,024
  • 5
  • 133
  • 166
woodstok
  • 2,534
  • 3
  • 31
  • 46

2 Answers2

6

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
  • 182,696
  • 29
  • 267
  • 329
  • 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 Путлер Капут 六四事 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
  • 216,767
  • 17
  • 275
  • 509