Thanks to visit codestin.com
Credit goes to github.com

Skip to content

libcurl can't work fine on Qemu Vexpress  #2065

@zhouweiguo2017

Description

@zhouweiguo2017

I did this:

testcurl.c:

#include <stdio.h>
#include <stdlib.h>
#include "curl/curl.h"

void preinit(int argc, char **argv, char **envp)
{
  printf("%s\n", __FUNCTION__);
}

void init(int argc, char **argv, char **envp)
{
  printf("%s\n", __FUNCTION__);
}

void fini()
{
    printf("%s\n", __FUNCTION__);
}

__attribute__((section(".init_array"))) typeof(init) *__init = init;
__attribute__((section(".preinit_array"))) typeof(preinit) *__preinit = preinit;
__attribute__((section(".fini_array"))) typeof(fini) *__fini = fini;

void __attribute__ ((constructor)) constructor()
{
    printf("%s\n", __FUNCTION__);
}

void __attribute__ ((destructor)) destructor()
{
    printf("%s\n", __FUNCTION__);
}


int main(int argc, char *argv[])
{
    printf("test curl on qemu\n");
    curl_global_init(CURL_GLOBAL_DEFAULT);

    return 0;
}

Makefile:

CROSS_COMPILE=/linuxdev/toolchains/aarch32/bin/arm-linux-gnueabihf-
CC      = $(CROSS_COMPILE)gcc
LD      = $(CROSS_COMPILE)ld
AR      = $(CROSS_COMPILE)ar
NM      = $(CROSS_COMPILE)nm
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
READELF = $(CROSS_COMPILE)readelf

OBJS = testcurl.o

CFLAGS =  -g  -I./external/curl-7.56.1/include/
LDADD +=  ./external/curl-7.56.1/lib/.libs/libcurl.a 

BINARY = testcurl

.PHONY: all
all: $(BINARY)

$(BINARY): $(OBJS)
        $(CC)  -o $@ $(OBJS) $(LDADD)

%.o:%.c
        $(CC) -o $@ -c $< $(CFLAGS) 

.PHONY: clean
clean:
        rm -f $(OBJS) $(BINARY)

I expected the following

copy the testcurl to Qemu Vexpress VM, running the testcurl from terminal,

the program exit directly(shoudn't happen here, it seems that unexpected behaviour happened during loading the testcurl into memory and executing the testcurl from memory, and I tried use arm-linux-gnueabihf-objdump (on build host) and gdb (on running board) to analysis but couldn't find any valueable clues ). the expected result as following:

root@Vexpress:/host/linuxdev/curl  ./testcurl 
preinit
init
constructor
test curl on qemu
destructor
fini
root@Vexpress:/host/linuxdev/curl/

after comment curl_global_init(CURL_GLOBAL_DEFAULT) in testcurl.c and rebuilt with Makefile and copy the new testcurl to target board and running testcurl again, could got the expected result.

operating system

root@Vexpress:/ cat /proc/cpuinfo 
processor	: 0
model name	: ARMv7 Processor rev 1 (v7l)
BogoMIPS	: 125.00
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x2
CPU part	: 0xc0f
CPU revision	: 1

Hardware	: Generic DT based system
Revision	: 0000
Serial		: 0000000000000000
root@Vexpress:/ 

build env

linuxdev:$ uname  -a
Linux 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

build script:

linuxdev:$ cat build_curl.sh 
#curl-7.56.1.tar.gz

export CROSS_COMPILE=arm-linux-gnueabihf
export PATH=/linuxdev/toolchains/aarch32/bin/:$PATH
export SYSROOT=/linuxdev/toolchains/aarch32/arm-linux-gnueabihf/libc/
export CPPFLAGS=" -I${SYSROOT}/usr/include "
#export LDFLAGS="-L${SYSROOT}/usr/lib -lc -lm -ldl -lgcc"
export AR=arm-linux-gnueabihf-ar
export AS=arm-linux-gnueabihf-as
export LD=arm-linux-gnueabihf-ld
export RANLIB=arm-linux-gnueabihf-ranlib
export CC=arm-linux-gnueabihf-gcc
export NM=arm-linux-gnueabihf-nm
export CXX=arm-linux-gnueabihf-g++

./configure --host=${CROSS_COMPILE} --build=x86_64-pc-linux-gnu  --without-ca-bundle --without-ca-path --enable-static=yes --enable-shared=no  --prefix=/tmp/curl --without-nghttp2 --without-librtmp --without-libidn --without-libssh2 --without-libpsl --disable-ldap --disable-ldaps --disable-ftp --disable-rtsp --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-manual --disable-smb --disable-sspi --disable-manual --enable-unix-sockets --disable-versioned-symbols --enable-hidden-symbols --disable-libcurl-option --disable-verbose --disable-file --disable-option-checking --disable-silent-rules --disable-debug --disable-optimize --disable-warnings --disable-werror --disable-curldebug  --disable-symbol-hiding --disable-ares --disable-rt --disable-dependency-tracking --disable-libtool-lock --disable-versioned-symbols --disable-threaded-resolver --disable-pthreads --disable-verbose --disable-sspi --disable-crypto-auth --disable-ntlm-wb --disable-tls-srp   

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions