Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 12 Oct 2012 08:28:59 -0500
From: Alex Caudill <alex.caudill@...il.com>
To: musl@...ts.openwall.com
Subject: Re: PATCH: dl_iterate_phdr()

Thanks for the review! To clarify, I meant that the patch is public
domain. This version implements most of your changes and attempts
support for dlopen()'d libraries and vdso.

Some questions:

1.) I guarded link.h with _GNU_SOURCE or _BSD_SOURCE; I'm unclear on
whether this is necessary since it isn't a standard header, so please
let me know your preference.

2.) I'm unsure of how to replace ElfW(Phdr) in dl_phdr_info - or did
you mean that musl should internally use some opaque type for
dl_phdr_info? Also, should ElfW() go in elf.h?

3.) The attached dltest.c reveals a problem with dlopen()'d libraries
which seems to be related to the locking strategy (see output below).
If I don't take the lock and check for current == saved_tail, it
"fixes" the example. At the least, I think this reveals a flaw with
dlopen("foo", RTLD_NOW) - shouldn't it hold the lock until the dso
list has been updated?

This function is used by libunwind and (I think) libgcc_eh for C++
exception support, and it's possible that additional fields in
dl_phdr_info will be necessary in order for those to work unmodified
with musl. I'll look into this today and come up with more tests.
Solaris and FreeBSD, at least, have these appended to struct
dl_phdr_info:

unsigned long long int dlpi_adds;       /* total # of loads */
unsigned long long int dlpi_subs;       /* total # of unloads */

The dl_iterate_phdr() callback is passed a size arg, and the callback
is responsible for checking the size to ensure that the additional
fields are present. Don't shoot the messenger! :)

TEST OUTPUT:
musl:
name=./dltest (6 segments)
                 header  0: address= 0x8048034
                 header  1: address= 0x80480f4
                 header  2: address= 0x8048000
                 header  3: address= 0x8049538
                 header  4: address= 0x804954c
                 header  5: address=         0
name=/lib/ld-musl-i386.so.1 (4 segments)
                 header  0: address=0x28049000
                 header  1: address=0x280c7714
                 header  2: address=0x280c77d8
                 header  3: address=0x28049000

FreeBSD libc:
name=/usr/home/alex/dltest (8 segments)
                 header  0: address= 0x8048034
                 header  1: address= 0x8048134
                 header  2: address= 0x8048000
                 header  3: address= 0x80497d0
                 header  4: address= 0x80497e4
                 header  5: address= 0x804814c
                 header  6: address= 0x8048784
                 header  7: address=       0x0
name=libc.so.7 (6 segments)
                 header  0: address=0x2806b000
                 header  1: address=0x28195000
                 header  2: address=0x281976b4
                 header  3: address=0x28195000
                 header  4: address=0x28194b38
                 header  5: address=0x2806b000
name=/compat/linux/lib/libavl.so (4 segments)
                 header  0: address=0x281c3000
                 header  1: address=0x281c5738
                 header  2: address=0x281c5738
                 header  3: address=0x281c3000

Download attachment "dynlink.patch" of type "application/octet-stream" (3447 bytes)

View attachment "link.h" of type "text/x-chdr" (474 bytes)

View attachment "dltest.c" of type "text/x-csrc" (623 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.