Anonymous

Libc: Difference between revisions

From dankwiki
1,154 bytes added ,  12:22, 5 July 2020
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 40: Line 40:
* <tt>backtrace_symbols</tt>, given the output of <tt>backtrace</tt>, will populate its argv-style return value with any symbols it can look up
* <tt>backtrace_symbols</tt>, given the output of <tt>backtrace</tt>, will populate its argv-style return value with any symbols it can look up
In order to extract symbols, appropriate binaries must:
In order to extract symbols, appropriate binaries must:
* not be stripped (or linked with -s), and
* not be stripped (or linked with -s),
* be linked with -rdynamic/--export-dynamic
* be linked with -rdynamic/--export-dynamic, and
* provide frame pointers (none for inlined code, omitted with most [[gcc]] optimization levels)
==Using an alternate Glibc==
Acquire the glibc sources, create a build directory, and run <tt>configure</tt> from that build directory. You are advised to run with <tt>--prefix=/usr</tt>, and then install to an alternative directory using e.g. <tt>make install DESTDIR=$HOME/glibc</tt>. Use <tt>--with-headers</tt> to specify kernel headers:
 
<pre>
[schwarzgerat](0) $ pwd
/home/dank/src/glibc/build
[schwarzgerat](0) $ ../configure --prefix=/usr --with-headers=/usr/src/linux-headers-5.7.7nlb/include/generated/uapi/
</pre>
 
So you've installed a local build of Glibc to, say, $HOME/glibc, eh?
 
Trying to run with <tt>LD_LIBRARY_PATH=$HOME/glibc/lib</tt> will result in all dynamically-linked executables segfaulting immediately. That's because they're using a mismatched loader. Try running the correct loader directly to sanity-check your library install, e.g.:
<pre>
[schwarzgerat](0) $ /bin/echo
Segmentation fault (core dumped)
[schwarzgerat](139) $ ~/glibc/lib/ld-linux-x86-64.so.2 /bin/echo this will work
this will work
[schwarzgerat](0) $
</pre>