Menu

#1040 crash on linux 64 when dynamically linking at runtime

closed-invalid
libcurl (356)
5
2013-06-21
2011-09-05
geneos
No

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.

Discussion

  • geneos

    geneos - 2011-09-05

    Test program

     
  • geneos

    geneos - 2011-09-05

    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

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-09-05

    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.

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-09-08
    • status: open --> pending-invalid
     
  • geneos

    geneos - 2011-09-21

    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.

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-09-21
    • status: pending-invalid --> closed-invalid
     
  • Daniel Stenberg

    Daniel Stenberg - 2011-09-21

    This is not a libcurl bug.

     
MongoDB Logo MongoDB