How does dlsym work?

it is very easy to find how to use dlsym () and other functions from this family, but how does it work internally? Is it possible to write my own, easy implementation of dlsym ()?

I am wondering if it is possible to achieve similar behavior, but without a reference to -ldl (let's say I can't do this).

+4
source share
1 answer

how does it work inside?

, GLIBC struct link_map, , , DT_HASH DT_GNU_HASH , dlsym - .

, dlsym()?

. , . , () : , , - .dynsym .dynstr , ( , "foo")

const char *strtab = ... /* locate .dynstr */
const ElfW(Sym) *sym = ... /* locate .dynsym */

for (; sym < end_of_dynsym; ++sym) {
  if (strcmp(strtab + sym->st_name, "foo") == 0) {
    /* found it */
    return load_address + sym->st_value;
  }
}
/* symbol not found */
return NULL;

(dlsym ), .hash .gnu_hash, . .

+9

All Articles