cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker Archives

[ curl-Bugs-3404225 ] crash on linux 64 when dynamically linking at runtime

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Wed, 21 Sep 2011 09:57:58 +0100

Bugs item #3404225, was opened at 2011-09-05 10:50
Message generated for change (Comment added) made by geneos
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3404225&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: libcurl
Group: crash
Status: Pending
Resolution: Invalid
Priority: 5
Private: No
Submitted By: geneos (geneos)
Assigned to: Daniel Stenberg (bagder)
Summary: crash on linux 64 when dynamically linking at runtime

Initial Comment:
Hello,

ENV:
--------
Libcurl library seg faults when linked dynamically at runtime on linux 64. I am using libcurl.so with openssl, curl-7.20.0 (tried with curl-7.21.1, no luck). I am on a linux 64 bit machine.
uname -a:
Linux localhost.localdomain 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

curl -V:
curl 7.20.0 (x86_64-unknown-linux-gnu) libcurl/7.20.0 OpenSSL/0.9.8m zlib/1.2.3
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: Largefile NTLM SSL libz

openssl-0.9.8 version

PROBLEM:
-------------------
I want to dynamically load the curl library at runtime , For this, I use dlopen() and dlsym() calls. It loads the library fine, gets all the curl function handles properly, but crashes with "Segmentation fault" or "Illegal Instruction", as soon as I try to execute curl_easy_setopt using the handle. No matter what options I pass to this method. This problem does not occur if I try to link the library dynamically at compile time or if I run it on other platforms.

I have attached my code snippet.

I cannot link the library dynamically at compile time in my program. Your help will be highly appreciated.

----------------------------------------------------------------------

Comment By: geneos (geneos)
Date: 2011-09-21 09:57

Message:
It is perfectly valid to try to load a library dynamically at runtime
rather than at compile time. And dlopen(), dlysym() and dlclose() are
standard unix functions to achieve this.

However, I found the fix for this problem. In my code, I was specifying
the function prototype for curl_easy_setopt() for defining the function
pointer to be used to load this method using dlsym() method as:

CURLcode curl_easy_setopt(CURL *handle, CURLoption option, void *);

(and I was typecasting the 3rd parameter in the call to (void *) )

When I changed the third parameter in function prototype to :

CURLcode curl_easy_setopt(CURL *handle, CURLoption option, ... );

it did not crash! So, I suspect that the problem is internal to libcurl
library. Anyways, I am happy that my problem is resolved.

For the libcurl library provider, I have a humble request. If you could
include examples on how to load the library at dynamically at runtime
(which people use sometimes), that would be great help!).

Thanks for your support.

it did not crash.

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2011-09-05 18:54

Message:
I don't understand how this is a bug of ours. We provide the code to a
library and it works great to link with and use on a bazillion platforms.
If you somehow cannot dlopen() it and use it, why is that a bug of ours? I
don't even understand how we even could work any differently depending on
how the function ends up in your program.

----------------------------------------------------------------------

Comment By: geneos (geneos)
Date: 2011-09-05 10:53

Message:
The compilation instructions for the test program is:

/usr/bin/g++ -DLINUX_64 -Wl,--hash-style=both -O2 -g
"-Wl,--wrap,__ctype_b,--wrap,__ctype_tolower" -Wno-system-headers
-I/home/user/Libs/curl/curl-7.20.0/include Libcurl_Test_Program.cpp
-L/home/user/openssl/lib -L. -lrt -lz -lssl -lcrypto

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3404225&group_id=976
Received on 2011-09-21

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET