Can I use printf in dl-load.c?

Yihan Dang qcloud1223@qq.com
Thu Jan 14 07:04:25 GMT 2021


Hello,


I'm trying to use printf to get maplength in dl-load.c:_dl_map_object_from_fd, and this is how the code looks like:


    /* add stdio at the very beginning */
    #include <stdio.h>
    ......
    /* Length of the sections to be loaded.  */
    maplength = loadcmds[nloadcmds - 1].allocend - loadcmds[0].mapstart;


    /* code added */
    printf("The maplength of shared library %s is %ld\n", name, maplength);


    /* Now process the load commands and map segments into memory.
       This is responsible for filling in:
       l_map_start, l_map_end, l_addr, l_contiguous, l_text_end, l_phdr
     */

    errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds,
				  maplength, has_holes, loader);



And this is the error message I got:
gcc   -nostdlib -nostartfiles -r -o /home/dyh/expr/glibc/build/elf/librtld.map.o -Wl,--defsym='__stack_chk_fail=0' -Wl,--defsym='__stack_chk_fail_local=0' \
	'-Wl,-(' /home/dyh/expr/glibc/build/elf/dl-allobjs.os /home/dyh/expr/glibc/build/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/home/dyh/expr/glibc/build/elf/librtld.mapT
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_signal_exception':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:91: multiple definition of `_dl_signal_exception'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:91: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_signal_error':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:109: multiple definition of `_dl_signal_error'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:109: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_catch_exception':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:175: multiple definition of `_dl_catch_exception'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:175: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_catch_error':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:213: multiple definition of `_dl_catch_error'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:213: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(init-first.os):(.data+0x0): multiple definition of `__libc_multiple_libcs'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:(.bss+0xe0): first defined here
collect2: error: ld returned 1 exit status
Makefile:437: recipe for target '/home/dyh/expr/glibc/build/elf/librtld.map' failed
make[2]: *** [/home/dyh/expr/glibc/build/elf/librtld.map] Error 1
make[2]: Leaving directory '/home/dyh/expr/glibc/elf'
Makefile:215: recipe for target 'elf/subdir_lib' failed
make[1]: *** [elf/subdir_lib] Error 2
make[1]: Leaving directory '/home/dyh/expr/glibc'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2



I had a hard time understanding the messages. Why strcmp in <string.h> can be used in this file, but printf in <stdio.h> can't?


I know that I can use readelf to calculate the virtual space a shared library takes up, but I'm really confused about this error.




Thanks in advance,
Yihan


More information about the Libc-help mailing list