Discussion:
[Libunwind-devel] Build glibc linking libunwind
Fabio
2011-09-24 21:46:05 UTC
Permalink
Hi all,
I am trying to build glibc and link libunwind to get a backtrace at
the beginning of some glibc function like strcpy for example but I
can't get them to build.
I include -lunwind in the CFLAGS and I export
LD_LIBRARY_PATH=/usr/local/lib, but when it comes to build ld.so it
fails:

usr/bin/gcc-4.3 -nostdlib -nostartfiles -shared -I/usr/local/lib \
-Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
-Wl,--verbose 2>&1 | \
LC_ALL=C \
sed -e '/^=========/,/^=========/!d;/^=========/d' \
-e 's/\. = .* + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/ld.so.lds
/usr/bin/gcc-4.3 -nostdlib -nostartfiles -shared -I/usr/local/lib -o
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/ld.so \
-Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs \
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/librtld.os
-Wl,--version-script=/home/wintermute/tesi/glibc/2.14/custom/glibc-build/ld.map \
-Wl,-soname=ld-linux.so.2 -T
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/ld.so.lds
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/librtld.os: In
function `strcpy':
/home/wintermute/tesi/glibc/2.14/custom/glibc-2.14/string/strcpy.c:43:
undefined reference to `_Ux86_getcontext'
/home/wintermute/tesi/glibc/2.14/custom/glibc-2.14/string/strcpy.c:44:
undefined reference to `_ULx86_init_local'
collect2: ld returned 1 exit status

Am I missing something? Sorry for asking a dumb question and thanks in advance.
--
Kind regards,
Fabio Pozzi
Joe Damato
2011-09-24 22:16:25 UTC
Permalink
yo

i modified ltrace to include support for libunwind. not sure exactly
what you are trying to do, but if you want to get a backtrace from
arbitrary library functions (glibc included) you might try just build
ltrace from source (http://ltrace.alioth.debian.org/) and using that
instead.

joe
Post by Fabio
Hi all,
I am trying to build glibc and link libunwind to get a backtrace at
the beginning of some glibc function like strcpy for example but I
can't get them to build.
I include -lunwind in the CFLAGS and I export
LD_LIBRARY_PATH=/usr/local/lib, but when it comes to build ld.so it
usr/bin/gcc-4.3   -nostdlib -nostartfiles -shared -I/usr/local/lib      \
         -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
-Wl,--verbose 2>&1 |    \
         LC_ALL=C \
         sed -e '/^=========/,/^=========/!d;/^=========/d'    \
             -e 's/\. = .* + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \
         > /home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/ld.so.lds
/usr/bin/gcc-4.3   -nostdlib -nostartfiles -shared -I/usr/local/lib -o
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/ld.so                   \
         -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs       \
         /home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/librtld.os
-Wl,--version-script=/home/wintermute/tesi/glibc/2.14/custom/glibc-build/ld.map \
         -Wl,-soname=ld-linux.so.2 -T
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/ld.so.lds
/home/wintermute/tesi/glibc/2.14/custom/glibc-build/elf/librtld.os: In
undefined reference to `_Ux86_getcontext'
undefined reference to `_ULx86_init_local'
collect2: ld returned 1 exit status
Am I missing something? Sorry for asking a dumb question and thanks in advance.
--
Kind regards,
Fabio Pozzi
_______________________________________________
Libunwind-devel mailing list
https://lists.nongnu.org/mailman/listinfo/libunwind-devel
Ken Werner
2011-10-12 11:14:45 UTC
Permalink
Post by Fabio
Hi all,
I am trying to build glibc and link libunwind to get a backtrace at
the beginning of some glibc function like strcpy for example but I
can't get them to build.
I include -lunwind in the CFLAGS and I export
LD_LIBRARY_PATH=/usr/local/lib, but when it comes to build ld.so it
undefined reference to `_Ux86_getcontext'
undefined reference to `_ULx86_init_local'
collect2: ld returned 1 exit status
Am I missing something? Sorry for asking a dumb question and thanks in advance.
I suspect you're on a system where the linker does not pull in indirect
shared libs (the default behavior of recent Debian or Fedora based
distros). I had a similar issue - see:
http://lists.gnu.org/archive/html/libunwind-devel/2011-03/msg00002.html.
You're probably just missing to link against libunwind-x86_64.so. Adding
-lunwind-x86 to your CLFAGS/LDFLAGS should be sufficient.

Regards
Ken
Paul Pluzhnikov
2011-10-12 14:40:29 UTC
Permalink
Post by Ken Werner
Post by Fabio
Hi all,
I am trying to build glibc and link libunwind to get a backtrace at
the beginning of some glibc function like strcpy for example but I
can't get them to build.
I include -lunwind in the CFLAGS and I export
LD_LIBRARY_PATH=/usr/local/lib, but when it comes to build ld.so it
undefined reference to `_Ux86_getcontext'
undefined reference to `_ULx86_init_local'
collect2: ld returned 1 exit status
Am I missing something? Sorry for asking a dumb question and thanks in advance.
I suspect you're on a system where the linker does not pull in indirect
shared libs (the default behavior of recent Debian or Fedora based distros).
http://lists.gnu.org/archive/html/libunwind-devel/2011-03/msg00002.html.
You're probably just missing to link against libunwind-x86_64.so. Adding
-lunwind-x86 to your CLFAGS/LDFLAGS should be sufficient.
The link failure is while linking ld.so itself. It better not use
libunwind-x86_64.so (or any other shared library) for obvious reasons.
--
Paul Pluzhnikov
Ken Werner
2011-10-13 14:22:04 UTC
Permalink
Post by Paul Pluzhnikov
Post by Ken Werner
Post by Fabio
Hi all,
I am trying to build glibc and link libunwind to get a backtrace at
the beginning of some glibc function like strcpy for example but I
can't get them to build.
I include -lunwind in the CFLAGS and I export
LD_LIBRARY_PATH=/usr/local/lib, but when it comes to build ld.so it
undefined reference to `_Ux86_getcontext'
undefined reference to `_ULx86_init_local'
collect2: ld returned 1 exit status
Am I missing something? Sorry for asking a dumb question and thanks in advance.
I suspect you're on a system where the linker does not pull in indirect
shared libs (the default behavior of recent Debian or Fedora based distros).
http://lists.gnu.org/archive/html/libunwind-devel/2011-03/msg00002.html.
You're probably just missing to link against libunwind-x86_64.so. Adding
-lunwind-x86 to your CLFAGS/LDFLAGS should be sufficient.
The link failure is while linking ld.so itself. It better not use
libunwind-x86_64.so (or any other shared library) for obvious reasons.
Oh, ok. So, you modified strcpy.c of glibc to make use of
functionalities provided by libunwind. And it looks like strcpy.c gets
also pulled in when the ld.so is being built. Maybe you can ifdef the
code that uses libunwind functionalities. I had a quick look into glibc
and found that eglibc/libc/include/libc-symbols.h defines _LIBC:

/* This is defined for the compilation of all C library code. features.h
tests this to avoid inclusion of stubs.h while compiling the library,
before stubs.h has been generated. Some library code that is shared
with other packages also tests this symbol to see if it is being
compiled as part of the C library. We must define this before including
config.h, because it makes some definitions conditional on whether libc
itself is being compiled, or just some generator program. */
#define _LIBC 1

Regards
Ken
Ken Werner
2011-10-13 14:33:16 UTC
Permalink
Post by Ken Werner
Post by Paul Pluzhnikov
Post by Ken Werner
Post by Fabio
Hi all,
I am trying to build glibc and link libunwind to get a backtrace at
the beginning of some glibc function like strcpy for example but I
can't get them to build.
I include -lunwind in the CFLAGS and I export
LD_LIBRARY_PATH=/usr/local/lib, but when it comes to build ld.so it
undefined reference to `_Ux86_getcontext'
undefined reference to `_ULx86_init_local'
collect2: ld returned 1 exit status
Am I missing something? Sorry for asking a dumb question and thanks in advance.
I suspect you're on a system where the linker does not pull in indirect
shared libs (the default behavior of recent Debian or Fedora based distros).
http://lists.gnu.org/archive/html/libunwind-devel/2011-03/msg00002.html.
You're probably just missing to link against libunwind-x86_64.so. Adding
-lunwind-x86 to your CLFAGS/LDFLAGS should be sufficient.
The link failure is while linking ld.so itself. It better not use
libunwind-x86_64.so (or any other shared library) for obvious reasons.
Oh, ok. So, you modified strcpy.c of glibc to make use of
functionalities provided by libunwind. And it looks like strcpy.c gets
also pulled in when the ld.so is being built. Maybe you can ifdef the
code that uses libunwind functionalities.
A colleague just suggested to test for the NOT_IN_libc define which is
set by the build system.

Regards
Ken
Fabio
2011-10-13 15:09:14 UTC
Permalink
I will try your suggestions, for now I am trying to see if I can
manage to solve the problem by wrapping glibc with a dynamic library
file written using libunwind.
Thanks a lot for your help!
--
Regards,
Fabio Pozzi
Loading...