Fwd: static link segmentation fault

JD H hanjideng at gmail.com
Tue Sep 24 07:54:17 UTC 2019


* Hi:*
*I static compile opensslv1.1.1 on Ubuntu18.04 as follow :*
  $./config no-shared
*and then:*
  $make
  $make install
*after that, I write a test.c like this:*

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/crypto.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>

int generate_key(int bits, int count)
{
    int             ret = 0;
    RSA             *r = NULL;
    BIGNUM          *bne = NULL;
    unsigned long   e = RSA_F4;


    fprintf(stdout, "id;n;e;p;q;d;t\n");

    for (int i = 0; i < count; i++) {
        bne = BN_new();
        ret = BN_set_word(bne,e);


        r = RSA_new();
        ret = RSA_generate_key_ex(r, bits, bne, NULL);
    }

    return (ret == 1);
}

// added main function
int main (){
    printf("Hello\n");
    return 0;
}

*and static compile it as follow:*
  $gcc -static -o test test.c -lssl -lcrypto -ldl -pthread
   x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function
`dlfcn_globallookup':
   dso_dlfcn.c:(.text+0x11): warning: Using 'dlopen' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
   libcrypto.a(b_addr.o): In function `BIO_lookup_ex':
b_addr.c:(.text+0xcea): warning: Using 'getaddrinfo' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
   x86_64-linux-gnu/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
   b_sock.c:(.text+0x71): warning: Using 'gethostbyname' in statically
linked applications requires at runtime the shared libraries from the glibc
version used for linking
*when i exec the test:*
  $./test
  [1]    36025 segmentation fault (core dumped)  ./test

*Use gdb for debug:*
 gdb-peda$ bt
 #0  0x0000000000000000 in ?? ()
 #1  0x00000000005a14e5 in __register_frame_info_bases.part.6 ()
 #2  0x000000000040168d in frame_dummy ()
 #3  0x0000000000000001 in ?? ()
 #4  0x00000000005a275c in __libc_csu_init ()
 #5  0x00000000005a1f27 in __libc_start_main ()
 #6  0x00000000004015aa in _start ()

*So, how did i use openssl for static link?*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-users/attachments/20190924/2f82bf96/attachment-0001.html>


More information about the openssl-users mailing list