compilationlinkerglibc

multiple definition error from dl-addr.c with addition of printf, in glibc compilation


In glibc-2.13/nptl/sigaction.c, i just put a simple printf("test\n"); and my glibc compilation fails. Just adding a printf gives me multiple definitions of _itoa from dl-addr.c and i have no idea why.

Can any body please tell me why is this happening and possible solution. The error:

test/glibc-build/libc_pic.a(_itoa.os): In function `_itoa':
test/glibc-2.13/stdio-common/_itoa.c:215: multiple definition of 
`_itoa'
test/glibc-build/elf/dl-allobjs.os:test/glibc-2.13/elf/dl-minimal.c:300: first defined here
test/glibc-build/libc_pic.a(dl-addr.os): In function `_dl_addr_inside_object':
test/SOURCE/glibc-2.13/elf/dl-addr.c:156: multiple definition of   
`_dl_addr_inside_object'
test/glibc-build/elf/dl-allobjs.os:glibc-2.13/elf/dl-open.c:658: first defined here

Solution

  • Just adding a printf gives me multiple definitions of _itoa

    Don't do that.

    Glibc is quite complicated, and you need to know what you are doing when you modify it.

    What's happening is that the link for elf/ld.so fails (you didn't say what target is failing, but I am pretty sure it's the ld.so; in the future please show the entire error message, not just parts of it).

    The ld.so is the dynamic linker, that will eventually bind your program to printf in libc.so.6. For obvious reason, ld.so itself can't dynamically link to printf -- it must execute before libc.so.6 has even been mmaped. As such, it links in minimal parts of libc.a, just enough for it to get running. The printf is not part of that minimal runtime, so you can't "just add a call to it".