[adding the list back in, with permission] On 07/14/2015 07:47 PM, Vinh Nguyen wrote: > Dear Eric, > Thank you for your useful information about dirname function. But the main thing I wanted to report is not the way to use dirname, but the weird behavior of dirname loading library named "." into the running process and cause error "Error while mapping shared library sections. '.' is not in executable format: Is a directory" and segmentation fault subsequently. The document says nothing about this behavior so it is a bug. Also, Dl_info's dli_fname is a char array, not const char* so the cast in "dirname((char*)info.dli_fname)" just do nothing. > I'm looking forward to hearing from you soon. Your problem stems from the fact that calling dirname() modifies its argument. >> Dl_info info; >> if ( dladdr( ( const void* )function_to_get_address, &info ) == 0 ) >> return false; >> if ( info.dli_fname == NULL ) >> return false; >> dirname((char*)info.dli_fname); (1) Whatever info.dli_fname was prior to dirname, it was modified in place to now be "." after the invalid call. So now that it has a changed value, it is messing with all the assumptions of the rest of dl*() that assume the name will not be changed. I stand by my assertion that the bug is in your invalid use of dirname(). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org