Sponsored Content
Top Forums UNIX for Dummies Questions & Answers dlsym() returns 0 for an existing function Post 302428052 by sds on Wednesday 9th of June 2010 09:59:38 AM
Old 06-09-2010
dlsym() returns 0 for an existing function

Sometimes I observe this in gdb:
Code:
(gdb) br my_function
Breakpoint .. at 0x...: file ..., line ...

i.e., "my_function" does exist in the current executable.
however, dlsym does not find it:
Code:
(gdb) p dlsym(0,"my_function")
$6 = 0

This is a C program; dlsym does find other defined functions and variables.
(this question stems from this bug report)

What could cause this? How do I avoid this?

---------- Post updated 2010-06-09 at 08:59 AM ---------- Previous update was 2010-06-08 at 03:05 PM ----------

the presence of my_function is also obvious from
Code:
(gdb) p my_function
$21 = {void (void)} 0x486f9c <my_function>

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

dlsym...error

Hi, I have ftp.so file which on nm gives the following table.... |0x0000c4f8|0x000000f0|FUNC |LOCL |0 |14 |ftp_active |0x0000c00c|0x000000f0|FUNC |LOCL |0 |14 |ftp_ascii |0x0000c0fc|0x000000f0|FUNC |LOCL |0 |14 |ftp_binary |0x0000a8e0|0x000001a8|FUNC |LOCL... (0 Replies)
Discussion started by: Vikky Panchal
0 Replies

2. Shell Programming and Scripting

function returns string

Can I create a function to return non-interger value in shell script? for example, function getcommand () { echo "read command" read command echo $command } command=$(getcommand) I tried to do something as above. The statement echo "read command" does not show up. ... (5 Replies)
Discussion started by: lalelle
5 Replies

3. Shell Programming and Scripting

folder existing and file existing

I want to look into a folder to see if there are any folders within it. If there are, I need to check inside each folder to see if it contains a .pdf file So If /myserver/myfolder/ contains a folder AND that folder conatins a .pdf file do X Else do Z I may have multiple folders and... (4 Replies)
Discussion started by: crowman
4 Replies

4. Solaris

Add existing user into an existing group

Pre: no gpasswd/adduser there is just usermod can be used, also there is no -a option for usermod. How should I add a user into a group? (4 Replies)
Discussion started by: a2156z
4 Replies

5. Shell Programming and Scripting

insert pipes for existing and non-existing records

I have a source file like this, L4058S462 34329094 F51010141TK1070000483L4058S462 34329094 0232384840 381892 182 5690 L4058S462 34329094 F51020141FIRST CLEARING, LLC A/C 3432-9094 L4058S462 34329094 F51030141JOHAN HOLMQVIST ... (1 Reply)
Discussion started by: saravanamr
1 Replies

6. Shell Programming and Scripting

Function returns wrong values - solved

Hi I have a small function which returns a wrong value. The function tries to make a connection to oracle database and tries to get the open_mode of the database in the variable status. However when a database is down the value of the status column is set to READWRITE i am not sure why. I... (0 Replies)
Discussion started by: xiamin
0 Replies

7. Shell Programming and Scripting

Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable. PREVIOUS_DATE_FUNCTION() { date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

8. Shell Programming and Scripting

Help in function returns value

Hi, I need to return a value from the function. the value will be the output from cat command which uses random fucntion. #!/bin/ksh hello() { var1=$(`cat /dev/urandom| tr -dc 'a-zA-Z0-9-!%&()*+,-/:;<=>?_'|fold -w 10 | head -n 1`) echo "value is" var1 return var1 } hello var=$?... (2 Replies)
Discussion started by: Nandy
2 Replies

9. Shell Programming and Scripting

Function Returns

I'm having a little trouble returning a value from a function or calling it, I'm not quite sure. I'm calling the function here function region_lookup_with_details { results = $(set_region) echo $results } This is the function I'm calling function set_region { ... (8 Replies)
Discussion started by: akechnie
8 Replies

10. Windows & DOS: Issues & Discussions

Home Questions Tags Users Unanswered Windows 2016 DNS server returns SERVFAIL for non-existing doma

I have two DNS resolvers in /etc/resolv.conf file. The top one is Windows DNS server, and the bottom one is my wi-fi router. Please see below. nameserver 192.168.1.126 nameserver 192.168.1.1 In Windows DNS server, the sole "Forward Lookup Zone" is biman.net When I query for host in the zone... (6 Replies)
Discussion started by: broy32000
6 Replies
dlsym(3C)																 dlsym(3C)

NAME
dlsym - get the address of a symbol in a shared object or executable SYNOPSIS
#include <dlfcn.h> void *dlsym(void *restrict handle, const char *restrict name); The dlsym() function allows a process to obtain the address of a symbol that is defined within a shared object or executable. The handle argument is either the value returned from a call to dlopen() or one of a family of special handles. The name argument is the symbol's name as a character string. If handle is returned from dlopen(), the associated shared object must not have been closed using dlclose(). A handle can be obtained from dlopen() using the RTLD_FIRST mode. With this mode, the dlsym() function searches for the named symbol in the initial object referenced by handle. Without this mode, the dlsym() function searches for the named symbol in the group of shared objects loaded automatically as a result of loading the object referenced by handle. See dlopen(3C) and . The following special handles are supported. RTLD_DEFAULT Instructs dlsym() to search for the named symbol starting with the first object loaded, typically the dynamic executable. The search continues through the list of initial dependencies that are loaded with the process, followed by any objects obtained with dlopen(3C). This search follows the default model that is used to relocate all objects within the process. This model also provides for transitioning into a lazy loading environment. If a symbol can not be found in the presently loaded objects, any pending lazy loaded objects are processed in an attempt to locate the symbol. This loading compensates for objects that have not fully defined their dependencies. However, this compensation can undermine the advantages of lazy loading. RTLD_PROBE Instructs dlsym() to search for the named symbol in the same manner as occurs with a handle of RTLD_DEFAULT. However, this model only searches for symbols in the presently loaded objects, together with any lazy loadable objects specifically identified by the caller to provide the named symbol. This handle does not trigger an exhaustive load of any lazy loadable symbols in an attempt to find the named symbol. This handle can provide a more optimal search than would occur using RTLD_DEFAULT. RTLD_NEXT Instructs dlsym() to search for the named symbol in the objects that were loaded following the object from which the dlsym() call is being made. RTLD_SELF Instructs dlsym() to search for the named symbol in the objects that were loaded starting with the object from which the dlsym() call is being made. When used with a special handle, dlsym() is selective in searching objects that have been loaded using dlopen(). These objects are searched for symbols if one of the following conditions are true. o The object is part of the same local dlopen() dependency hierarchy as the calling object. See the for a description of dlopen() dependency hierarchies. o The object has global search access. See dlopen(3C) for a discussion of the RTLD_GLOBAL mode. The dlsym() function returns NULL if handle does not refer to a valid object opened by dlopen() or is not one of the special handles. The function also returns NULL if the named symbol cannot be found within any of the objects associated with handle. Additional diagnostic information is available through dlerror(3C). Example 1: Use dlopen() and dlsym() to access a function or data objects. The following code fragment demonstrates how to use dlopen() and dlsym() to access either function or data objects. For simplicity, error checking has been omitted. void *handle; int *iptr, (*fptr)(int); /* open the needed object */ handle = dlopen("/usr/home/me/libfoo.so.1", RTLD_LAZY); /* find the address of function and data objects */ fptr = (int (*)(int))dlsym(handle, "my_function"); iptr = (int *)dlsym(handle, "my_object"); /* invoke function, passing value of integer as a parameter */ (*fptr)(*iptr); Example 2: Use dlsym() to verify that a particular function is defined. The following code fragment shows how to use dlsym() to verify that a function is defined. If the function exists, the function is called. int (*fptr)(); if ((fptr = (int (*)())dlsym(RTLD_DEFAULT, "my_function")) != NULL) { (*fptr)(); } The dlsym() function is one of a family of functions that give the user direct access to the dynamic linking facilities. These facilities are available to dynamically-linked processes only. See the . See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ ld(1), ld.so.1(1), dladdr(3C), dlclose(3C), dldump(3C), dlerror(3C), dlinfo(3C), dlopen(3C), attributes(5), standards(5) If an object is acting as a filter, care should be taken when interpreting the address of any symbol obtained using a handle to this object. For example, using dlsym(3C) to obtain the symbol _end for this object, results in returning the address of the symbol _end within the filtee, not the filter. For more information on filters see the . 26 Sep 2005 dlsym(3C)
All times are GMT -4. The time now is 09:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy