sysml / mini-os

Minimalistic Operating System for Xen
Other
65 stars 23 forks source link

Integrating relic library into mini-os #10

Closed hassanjameel1 closed 9 years ago

hassanjameel1 commented 9 years ago

Hi,

I am trying to include the relic library:

https://code.google.com/p/relic-toolkit/

into mini-os so that I can add some crypto functions into Click elements. What would be the standard way to compile mini-os to include an external library?

Best wishes, Hassan

fmanco commented 9 years ago

Hi,

The standard way would be to add it to the toolchain project. The process should be straightforward, but let me know if you need help.

Filipe

hassanjameel1 commented 9 years ago

Thanks Filipe,

I will try that. If I get into trouble I will ask for help. Thanks a lot.

Hassan

fmanco commented 9 years ago

No problem. I'll close this, fell free to reopen as needed.

Filipe

hassanjameel1 commented 9 years ago

Hi Filipe,

I tried to add the library to the toolchain project but I couldn't do it. I have relic's header files under /usr/local/include/relic/ and the shared library librelic.so under /usr/local/lib. How would I go about adding this info up in toolchain?

Best wishes, Hassan

jpemartins commented 9 years ago

Hi,

You need to compile the relic library within the toolchain. Using the .so and include files directly won't work unfortunately. Check out the Makefile targets suffixed with -src -build and -install for newlib target (lwip is an exception). You can see that they download the sources configure (optionally patched for mini-os) and install for some folders within the folder x86_64-root/. After that when using it in mini-os you need to add this folder as shown here. Hope that helps getting you started.

hassanjameel1 commented 9 years ago

Hi,

Thanks for the help. I managed to compile successfully using toolchain. But when trying to make minios, it does not find the library librelic.so. I edited the stub.mk file to include:

MINIOS_LDLIBS += -L$(RELIC_ROOT)/relic/lib -lrelic

RELIC_ROOT points to x86_64-root/x86_64-xen-elf. The librelic.so is under relic/lib under RELIC_ROOT.

The error I get is:

ld: cannot find -lrelic

Thanks, Hassan

fmanco commented 9 years ago

Hi

You need to build it as a static library. If it doesn't work please build we verbose=y and post the output.

Filipe

hassanjameel1 commented 9 years ago

Hi,

I tried to built it with the static library. It seems to have found the library. But it is now giving undefined reference errors. Here is the output with verbose=y:

ld -r -nostdlib -m elf_x86_64 /home/nfv1/clickos/clickos/minios/build/mini-os/arch/libx86_64.a /home/nfv1/clickos/clickos/minios/build/mini-os/arch/x86_64.o /home/nfv1/clickos/clickos/minios/build/clickos.o /home/nfv1/clickos/clickos/minios/build/mini-os/console.o /home/nfv1/clickos/clickos/minios/build/mini-os/ctype.o /home/nfv1/clickos/clickos/minios/build/mini-os/events.o /home/nfv1/clickos/clickos/minios/build/mini-os/gntmap.o /home/nfv1/clickos/clickos/minios/build/mini-os/gnttab.o /home/nfv1/clickos/clickos/minios/build/mini-os/hypervisor.o /home/nfv1/clickos/clickos/minios/build/mini-os/kernel.o /home/nfv1/clickos/clickos/minios/build/mini-os/lock.o /home/nfv1/clickos/clickos/minios/build/mini-os/lwip-arch.o /home/nfv1/clickos/clickos/minios/build/mini-os/lwip-net.o /home/nfv1/clickos/clickos/minios/build/mini-os/main.o /home/nfv1/clickos/clickos/minios/build/mini-os/math.o /home/nfv1/clickos/clickos/minios/build/mini-os/mm.o /home/nfv1/clickos/clickos/minios/build/mini-os/printf.o /home/nfv1/clickos/clickos/minios/build/mini-os/sched.o /home/nfv1/clickos/clickos/minios/build/mini-os/shutdown.o /home/nfv1/clickos/clickos/minios/build/mini-os/stack_chk_fail.o /home/nfv1/clickos/clickos/minios/build/mini-os/string.o /home/nfv1/clickos/clickos/minios/build/mini-os/sys.o /home/nfv1/clickos/clickos/minios/build/mini-os/xencons_ring.o /home/nfv1/clickos/clickos/minios/build/mini-os/xmalloc.o /home/nfv1/clickos/clickos/minios/build/mini-os/xenbus.o /home/nfv1/clickos/clickos/minios/build/mini-os/xs.o /home/nfv1/clickos/clickos/minios/build/mini-os/blkfront.o /home/nfv1/clickos/clickos/minios/build/mini-os/netfront.o /home/nfv1/clickos/clickos/minios/build/mini-os/lwip/liblwip.a -L/home/nfv1/clickos/clickos/minios/build/mini-os/arch -lx86_64 -L/home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib -lc -lm -o /home/nfv1/clickos/clickos/minios/build/clickos_x8664.o objcopy -w -G xenos_* -G _start /home/nfv1/clickos/clickos/minios/build/clickos_x8664.o /home/nfv1/clickos/clickos/minios/build/clickos_x86_64.o ld -nostdlib -m elf_x86_64 -T /home/nfv1/clickos/mini-os/arch/x86/minios-x86_64.lds /home/nfv1/clickos/clickos/minios/build/clickos_x86_64.o -o /home/nfv1/clickos/clickos/minios/build/clickos_x86_64 /home/nfv1/clickos/clickos/minios/build/clickos_x86_64.o: In function IPChanger::simple_action(Packet*)': :(.text+0x81e49): undefined reference tocore_init()' :(.text+0x81e51): undefined reference to ep_param_set_any_pairf()' :(.text+0x81e56): undefined reference toep_param_print()' :(.text+0x81e5b): undefined reference to core_get()' :(.text+0x81ebb): undefined reference tocp_bgn_gen(_bgnt, _bgnt)' :(.text+0x81ec4): undefined reference to test_fail()' :(.text+0x81ed0): undefined reference toutilprintf(char const, ...)' :(.text+0x81edc): undefined reference to util_printf(char const_, ...)' :(.text+0x81eed): undefined reference toutil_printf(char const, ...)' :(.text+0x81f0d): undefined reference torand_bytes(unsigned char_, int)' :(.text+0x81f56): undefined reference tocp_bgn_enc1(epst () [1], unsigned long, _bgnt)' :(.text+0x81f5f): undefined reference to test_fail()' :(.text+0x81f6b): undefined reference toutilprintf(char const, ...)' :(.text+0x81f77): undefined reference to `util_printf(char const, ...)' :(.text+0x81f88): undefined reference toutil_printf(char const_, ...)' :(.text+0x81ffe): undefined reference toutilprintf(char const, ...)' :(.text+0x82020): undefined reference to cp_bgn_dec1(unsigned long*, ep_st (*) [1], _bgn_t*)' :(.text+0x82029): undefined reference totest_fail()' :(.text+0x82035): undefined reference to util_printf(char const*, ...)' :(.text+0x82041): undefined reference toutilprintf(char const, ...)' :(.text+0x82052): undefined reference to util_printf(char const_, ...)' :(.text+0x820c1): undefined reference toutil_printf(char const, ...)' :(.text+0x820d6): undefined reference totest_fail()' :(.text+0x820e2): undefined reference toutil_printf(char const, ...)' :(.text+0x820ee): undefined reference toutil_printf(char const_, ...)' :(.text+0x820ff): undefined reference toutilprintf(char const, ...)' :(.text+0x82126): undefined reference to cp_bgn_enc2(ep2_st (*) [1], unsigned long, _bgn_t*)' :(.text+0x8212f): undefined reference totest_fail()' :(.text+0x8213b): undefined reference to util_printf(char const*, ...)' :(.text+0x82147): undefined reference toutilprintf(char const, ...)' :(.text+0x82158): undefined reference to util_printf(char const_, ...)' :(.text+0x821c7): undefined reference toutil_printf(char const, ...)' :(.text+0x821e9): undefined reference tocp_bgn_dec2(unsigned long_, ep2_st (_) [1], _bgn_t_)' :(.text+0x821f2): undefined reference totest_fail()' :(.text+0x821fe): undefined reference toutil_printf(char const_, ...)' :(.text+0x8220a): undefined reference toutil_printf(char const, ...)' :(.text+0x8221b): undefined reference toutil_printf(char const_, ...)' :(.text+0x8228e): undefined reference toutilprintf(char const, ...)' :(.text+0x822a3): undefined reference to test_fail()' :(.text+0x822af): undefined reference toutilprintf(char const, ...)' :(.text+0x822bb): undefined reference to util_printf(char const_, ...)' :(.text+0x822cc): undefined reference toutil_printf(char const, ...)' :(.text+0x822f6): undefined reference torand_bytes(unsigned char_, int)' :(.text+0x82369): undefined reference tocp_bgn_enc1(epst () [1], unsigned long, _bgnt)' :(.text+0x82372): undefined reference to test_fail()' :(.text+0x8237e): undefined reference toutilprintf(char const, ...)' :(.text+0x8238a): undefined reference to `util_printf(char const, ...)' :(.text+0x8239b): undefined reference toutil_printf(char const_, ...)' :(.text+0x823ba): undefined reference tocp_bgn_enc1(epst () [1], unsigned long, _bgnt)' :(.text+0x823c3): undefined reference to test_fail()' :(.text+0x823cf): undefined reference toutilprintf(char const, ...)' :(.text+0x823db): undefined reference to util_printf(char const*, ...)' :(.text+0x823ec): undefined reference toutilprintf(char const, ...)' :(.text+0x82407): undefined reference to ep_add_projc(ep_st_, ep_st const_, ep_st const_)' :(.text+0x82428): undefined reference toep_add_projc(ep_st, ep_st const, ep_st const)' :(.text+0x82437): undefined reference toep_norm(ep_st_, ep_st const_)' :(.text+0x82442): undefined reference toep_norm(ep_st, ep_st const)' :(.text+0x8245c): undefined reference tocp_bgn_dec1(unsigned long_, ep_st (_) [1], _bgn_t_)' :(.text+0x82465): undefined reference totest_fail()' :(.text+0x82471): undefined reference toutil_printf(char const_, ...)' :(.text+0x8247d): undefined reference toutil_printf(char const, ...)' :(.text+0x8248e): undefined reference toutil_printf(char const_, ...)' :(.text+0x824b2): undefined reference totest_fail()' :(.text+0x824be): undefined reference toutil_printf(char const_, ...)' :(.text+0x824ca): undefined reference toutil_printf(char const, ...)' :(.text+0x824db): undefined reference toutil_printf(char const_, ...)' :(.text+0x824f3): undefined reference tocp_bgn_enc2(ep2st () [1], unsigned long, _bgnt)' :(.text+0x824fc): undefined reference to test_fail()' :(.text+0x82508): undefined reference toutilprintf(char const, ...)' :(.text+0x82514): undefined reference to `util_printf(char const, ...)' :(.text+0x82525): undefined reference toutil_printf(char const_, ...)' :(.text+0x82544): undefined reference tocp_bgn_enc2(ep2st () [1], unsigned long, _bgnt)' :(.text+0x8254d): undefined reference to test_fail()' :(.text+0x82559): undefined reference toutilprintf(char const, ...)' :(.text+0x82565): undefined reference to util_printf(char const*, ...)' :(.text+0x82576): undefined reference toutilprintf(char const, ...)' :(.text+0x82591): undefined reference to ep2_add_projc(ep2_st_, ep2_st_, ep2_st_)' :(.text+0x825b8): undefined reference toep2_add_projc(ep2_st, ep2_st, ep2_st)' :(.text+0x825c7): undefined reference toep2_norm(ep2_st_, ep2_st_)' :(.text+0x825d2): undefined reference toep2_norm(ep2_st, ep2_st)' :(.text+0x825ec): undefined reference tocp_bgn_dec2(unsigned long_, ep2_st (_) [1], _bgn_t_)' :(.text+0x825f5): undefined reference totest_fail()' :(.text+0x82601): undefined reference toutil_printf(char const_, ...)' :(.text+0x8260d): undefined reference toutil_printf(char const, ...)' :(.text+0x8261e): undefined reference toutil_printf(char const_, ...)' :(.text+0x8263f): undefined reference totest_fail()' :(.text+0x8264b): undefined reference toutil_printf(char const_, ...)' :(.text+0x82657): undefined reference toutil_printf(char const, ...)' :(.text+0x82668): undefined reference toutil_printf(char const_, ...)' :(.text+0x82692): undefined reference torandbytes(unsigned char, int)' :(.text+0x826f8): undefined reference to `cp_bgn_enc1(ep_st () [1], unsigned long, _bgn_t)' :(.text+0x82701): undefined reference totest_fail()' :(.text+0x8270d): undefined reference toutil_printf(char const, ...)' :(.text+0x82719): undefined reference toutil_printf(char const_, ...)' :(.text+0x8272a): undefined reference toutilprintf(char const, ...)' :(.text+0x82749): undefined reference to cp_bgn_enc2(ep2_st (*) [1], unsigned long, _bgn_t*)' :(.text+0x82752): undefined reference totest_fail()' :(.text+0x8275e): undefined reference to util_printf(char const*, ...)' :(.text+0x8276a): undefined reference toutilprintf(char const, ...)' :(.text+0x8277b): undefined reference to util_printf(char const_, ...)' :(.text+0x827de): undefined reference tocp_bgn_mul(unsigned long () [2][3][2][4], ep_st () [1], ep2_st () [1])' :(.text+0x827ef): undefined reference totest_fail()' :(.text+0x827fb): undefined reference toutil_printf(char const, ...)' :(.text+0x82807): undefined reference toutil_printf(char const_, ...)' :(.text+0x82818): undefined reference toutilprintf(char const, ...)' :(.text+0x82876): undefined reference to util_printf(char const*, ...)' :(.text+0x828be): undefined reference tocp_bgndec(unsigned long, unsigned long (_) [2][3][2][4], _bgnt)' :(.text+0x828cf): undefined reference to test_fail()' :(.text+0x828db): undefined reference toutilprintf(char const, ...)' :(.text+0x828e7): undefined reference to util_printf(char const*, ...)' :(.text+0x828f8): undefined reference toutilprintf(char const, ...)' :(.text+0x82956): undefined reference to util_printf(char const_, ...)' :(.text+0x8296b): undefined reference totest_fail()' :(.text+0x82977): undefined reference toutil_printf(char const_, ...)' :(.text+0x82983): undefined reference toutilprintf(char const, ...)' :(.text+0x82994): undefined reference to util_printf(char const*, ...)' :(.text+0x829d9): undefined reference tocp_bgnadd(unsigned long () [2][3][2][4], unsigned long () [2][3][2][4], unsigned long () [2][3][2][4])' :(.text+0x829ea): undefined reference to test_fail()' :(.text+0x829f6): undefined reference toutilprintf(char const, ...)' :(.text+0x82a02): undefined reference to util_printf(char const*, ...)' :(.text+0x82a13): undefined reference toutilprintf(char const, ...)' :(.text+0x82a71): undefined reference to util_printf(char const_, ...)' :(.text+0x82a8b): undefined reference tocp_bgn_dec(unsigned long, unsigned long () [2][3][2][4], _bgn_t)' :(.text+0x82a94): undefined reference totest_fail()' :(.text+0x82aa0): undefined reference toutil_printf(char const, ...)' :(.text+0x82aac): undefined reference toutil_printf(char const_, ...)' :(.text+0x82abd): undefined reference toutilprintf(char const, ...)' :(.text+0x82ada): undefined reference to test_fail()' :(.text+0x82ae6): undefined reference toutilprintf(char const, ...)' :(.text+0x82af2): undefined reference to util_printf(char const_, ...)' :(.text+0x82b03): undefined reference toutil_printf(char const*, ...)' :(.text+0x82b3d): undefined reference tocore_get()' :(.text+0x82bd1): undefined reference tocore_clean()' /home/nfv1/clickos/clickos/minios/build/clickos_x86_64.o: In function_times_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/timesr.c:60: undefined reference totimes' make[2]: * [/home/nfv1/clickos/clickos/minios/build/clickos_x86_64] Error 1 make[2]: Leaving directory/home/nfv1/clickos/clickos/minios' make[1]: **\* [stub] Error 2 make[1]: Leaving directory/home/nfv1/clickos/clickos/minios' make: * [minios] Error 2

Note that ipchanger.cc is the file where I import "relic/relic.h" and "relic/relic_test.h", the two files containing the above mentioned functions.

fmanco commented 9 years ago

Hi

May be an error on the Makefile. Please remove the flags -L$(RELIC_ROOT)/relic/lib -lrelic from MINIOS_LDLIBS and add them to LDLIBS directly.

hassanjameel1 commented 9 years ago

Hi,

I have removed the flag from MINIOS_LDLIBS and added it to LDLIBS, but the error persists. By looking at the following lines in stub.mk:

Linking the image

$(STUB_APPIMG).o: $(MINIOS_ARCH_LIB) $(MINIOS_ARCH_HEAD_OBJ) $(STUB_APP).o $(MINIOS_OBJS) $(MINIOS_LWIP_LIB) $(call verbose_cmd,$(LD) -r $(LDFLAGS) $^ $(MINIOS_ARCH_LDLIBS) $(LDLIBS) -o,'LD ',$@)

$(STUB_APP_IMG).o: $(STUB_APPIMG).o $(call verbose_cmd,$(OBJCOPY) -w -G $(STUB_GLOBAL_PREFIX)* -G _start $^,'OCP',$@) $(STUB_APP_IMG): $(STUB_APP_IMG).o $(call verbose_cmd,$(LD) $(LDFLAGS) -T $(MINIOS_ARCH_LDS) $(LDLIBS) $@.o -o,'LD ',$@)

the error occurs executing the last of the ld command.

Best wishes, Hassan

fmanco commented 9 years ago

Hi,

You need to check if the missing symbols are available in the lib, you can use objdump -t to check for it. In case they are there then I need to be able to reproduce the setup, so you need to provide your changes.

Filipe

hassanjameel1 commented 9 years ago

Hi Filipe,

The symbols are there. So I guess I just let you know how I am running my setup. I am assuming toolchain is under /home/hassan/nfv-proj/toolchain. Assume $HOME=/home/hassan/nfv-proj

  1. I go to $HOME/toolchain directory and download the relic library:

git clone https://github.com/relic-toolkit/relic.git

This downloads the relic project in $HOME/toolchain/relic

  1. I go to $HOME/toolchian/relic/CMakeCache.txt and change the CMAKE_INSTALL_PREFIX variable by specifying:

    CMAKE_INSTALL_PREFIX:PATH=/home/hassan/nfv-proj/toolchain/x86_64-root/x86_64-xen-elf/relic

  2. I add the following in the Makefile from toolchain:

################################################################################

relic

################################################################################ RELIC_SRC = relic CMAKE_SUFFIXES = -DARITH=gmp -DCORES=1 -DMULTI=OPENMP _relic-cmake: cd $(RELIC_SRC);\ pwd;\ cmake . $(CMAKE_SUFFIXES);\ touch $@

_relic-build: _relic-cmake mkdir -p $(PREFIX)/$(TARGET)/relic cd $(RELIC_SRC);\ make

_relic-test: _relic-build

cd $(RELIC_SRC);\

make test

_relic-install: _relic-build cd $(RELIC_SRC);\ make install

.PHONY: cross-relic clean-relic cross-relic: _relic-install

clean-relic: rm -rf $(PREFIX)/$(TARGET)/relic cd $(RELIC_SRC);\ make clean

  1. Then I run the make command by going to $HOME/toolchain
  2. I copy the libgmp.a library installed in /usr/lib/x86_64-linux-gnu/ to $HOME/toolchain/x86_64-root/x86_64-xen-elf/relic/lib

The above lib folder also contains relic's static library librelic_s.a

  1. I define the environment variable RELIC_HOME to point to:

$HOME/toolchain/x86_64-root/x86_64-xen-elf

  1. I then go to $HOME/mini-os and change the stub.mk file to add the LDLIBS:

LDLIBS += -L/RELIC_HOME/relic/lib -lrelic_s -lgmp

  1. I then go to $HOME/clickos and run the make command, resulting in the above mentioned error.

If you need more info please feel free to ask.

Thanks a lot, Hassan

fmanco commented 9 years ago

Hi

I'll also need a minimal working example of an element that fails to link with relic (it doesn't need to be your element, just an example).

Filipe

hassanjameel1 commented 9 years ago

Hi Filipe,

Here is an element saved as ipchanger.cc:

include <click/config.h>

include "ipchanger.hh"

include <click/args.hh>

include <clicknet/ip.h>

include <clicknet/udp.h>

include <clicknet/tcp.h>

include <click/straccum.hh>

include

include

CLICK_DECLS

IPChanger::IPChanger() { }

IPChanger::~IPChanger() { }

int IPChanger::configure(Vector &conf, ErrorHandler *errh) { _dst_anno = true; return Args(conf, this, errh).read_p("DST_ANNO", _dst_anno).complete(); }

Packet IPChanger::simple_action(Packet p_in) { WritablePacket p = p_in->uniqueify(); unsigned char idat = p->data(); int bytes = p->length(); // new checksum is same as old checksum click_ip iph = p->ip_header(); click_chatter("IP header has already been assigned"); click_udp udph = p->udp_header(); click_chatter("Length of the packet %d", int(p->length()));

if(iph!=NULL){ click_chatter("IP Address of sender is: %s", IPAddress(iph->ip_src).unparse().c_str()); click_chatter("IP TTL is: %d", int(IPAddress(iph->ip_ttl))); click_chatter("Protocol type is: %d", int(iph->ip_p)); click_chatter("IP header length: %d", int(iph->ip_hl)4); click_chatter("IP total length: %" PRIu16 "", htons(iph->ip_len)); iph->ip_src = IPAddress(4294967296); click_chatter("IP Address of sender after changing is: %s", IPAddress(iph->ip_src).unparse().c_str()); } if(udph!=NULL){ click_chatter("Source port: %" PRIu16 "", htons(udph->uh_sport)); click_chatter("Destination port: %" PRIu16 "", htons(udph->uh_dport)); click_chatter("Original packet contents: \n"); unsigned char pack_data [bytes]; for (int i = 0; i < bytes; i++, idat++) { pack_data[i] = idat & 0xff; click_chatter("%02x", *idat & 0xff); click_chatter("pack data %02x", pack_data[i]); } }

/**** RELIC *****/ int code = STS_OK ;

//library init
core_init(); pc_param_set_any(); pc_param_print();

/****/ return p; }

CLICK_ENDDECLS EXPORT_ELEMENT(IPChanger) ELEMENT_MT_SAFE(IPChanger)

This works without the clearly marked relic part. The associated header file ipchanger.hh is simple:

ifndef CLICK_IPCHANGER_HH

define CLICK_IPCHANGER_HH

include <click/element.hh>

CLICK_DECLS

class IPChanger : public Element { public:

IPChanger() CLICK_COLD;
~IPChanger() CLICK_COLD;

const char *class_name() const      { return "IPChanger"; }
const char *port_count() const      { return PORTS_1_1; }

int configure(Vector<String> &conf, ErrorHandler *errh) CLICK_COLD;
Packet *simple_action(Packet *);

private:

bool _dst_anno;

};

CLICK_ENDDECLS

endif // CLICK_IPCHANGER_HH

Best wishes, Hassan

hassanjameel1 commented 9 years ago

Hi,

I have been able to fix the above. The problem was with the g++ compiler compiling Relic's C code. I was able to do that by enclosing relic headers within 'extern "C", and adding the gmpxx.h header (C++ equivalent of the gmp library.

However, now I am running into conflict issues with newlib's implementation of classes versus the system implementation. For instance, the header file pthread.h. Newlib's version does not name the type 'pthread_t' as an example. I guess this is a dead-end then?

Thanks, Hassan

fmanco commented 9 years ago

Hi Hassan

Unfortunately I haven't had time to look into this in detail. I managed to build Relic (without GMP), and a simple example element. I didn't manage to link the final object though, because of conflicts between relic's and newlib's symbols (for instance arch_init). I didn't had any issues with pthread but if the library uses pthread, for the time being this won't work. MiniOS does support threads, but has only a cooperative scheduler and AFAIK doesn't support pthread. Are you sure this is a relic dependency, or is it GMP's. Can't you use Relic without GMP?

If you can run the library single threaded maybe it can work, but it requires more exploitation. I'm afraid I can't help you more, but let me know if I do.

Thanks Filipe

hassanjameel1 commented 9 years ago

Hi Filipe,

Thanks. I will give it a final try without GMP, and see if I can fix any linking problems.

Thanks for your help.I will take it from here.

Best wishes, Hassan

hassanjameel1 commented 9 years ago

Hi,

I was successfully able to compile and link relic with minios (after resolving conflicts with symbols). Now, when I run an click element using relic functions, it gives page fault errors whenever a relic function is using a copying function such as "strncpy" and "memcpy". Is there any reason why this should be the case?

Best wishes, Hassan

fmanco commented 9 years ago

Hi

That's great news. First thing I would try to increase the amount of memory you give the domain. Another issue that comes to my head is the libc. Did you build relic with the systems libs or with newlib?

Best regards Filipe

hassanjameel1 commented 9 years ago

Hi,

The clickos instance had 1024MB memory. So, I think the problem was that I had not built relic with newlib. But after trying to build it with newlib, I get the following error:

Linking C executable ../bin/test_bn cd /home/nfv1/clickos/toolchain/relic/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/test_bn.dir/link.txt --verbose=1 /usr/bin/cc -pipe -std=c99 -Wall -nostdinc -fno-stack-protector -Wno-format -Wno-redundant-decls -Wno-undef -fno-builtin -fgnu89-inline -isystem /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/include -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed -L/home/nfv1/clickos/toolchain/relic/src/low/easy/ -nostdlib -L/home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib -lc -lm -lgcc -lnosys -static CMakeFiles/test_bn.dir/test_bn.c.o -o ../bin/test_bn -rdynamic ../lib/librelic_s.a -nostdlib -L/home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib -lc -lm -lnosys -Wl,-Bstatic /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-closer.o): In function _close_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/closer.c:53: warning: _close is not implemented and will always fail /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-signalr.o): In function_getpid_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/signalr.c:96: warning: _getpid is not implemented and will always fail /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-makebuf.o): In function __smakebuf_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/makebuf.c:110: warning: isatty is not implemented and will always fail /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-signalr.o): In function_kill_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/signalr.c:61: warning: _kill is not implemented and will always fail /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-readr.o): In function _read_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/readr.c:58: warning: _read is not implemented and will always fail /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-writer.o): In function_write_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/writer.c:58: warning: _write is not implemented and will always fail /usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400150 ../lib/librelic_s.a(relic_bn_div_low.c.o): In function bn_divn_low': relic_bn_div_low.c:(.text+0x33f): undefined reference toudivti3' ../lib/librelic_s.a(relic_bn_div_low.c.o): In function bn_div1_low': relic_bn_div_low.c:(.text+0x85d): undefined reference toudivti3' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-vfiprintf.o): In function _vfiprintf_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/vfprintf.c:521: undefined reference to_lock_acquire_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/vfprintf.c:532: undefined reference to `lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-vfiprintf.o): In function__sbprintf': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/vfprintf.c:210: undefined reference to_lock_init_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-vfiprintf.o): In function_vfiprintf_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/vfprintf.c:1333: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/vfprintf.c:525: undefined reference to`lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-fflush.o): In function _fflush_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fflush.c:175: undefined reference to_lock_release_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fflush.c:94: undefined reference to `lock_acquire_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fflush.c:171: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fflush.c:140: undefined reference to_lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In function`fp_lock': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:260: undefined reference to ___lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionfp_unlock': /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:270: undefined reference to `lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In function__sinit_lock_acquire': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:246: undefined reference to_lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionstd': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:65: undefined reference to___lock_init_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:65: undefined reference to`lock_init_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:65: undefined reference to ___lock_init_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsfp_lock_acquire': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:234: undefined reference to ___lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsfp': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:130: undefined reference to ___lock_init_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsfp_lock_release': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:240: undefined reference to ___lock_release_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:240: undefined reference to_lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In function __sfp_lock_acquire': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:234: undefined reference to_lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In function `sinit_lock_release': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:252: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsfp_lock_acquire': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:234: undefined reference to___lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsfp_lock_release': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:240: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsinit_lock_acquire': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:246: undefined reference to___lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsinit_lock_release': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:252: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-findfp.o): In functionsfp_lock_release': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/findfp.c:240: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-fwalk.o): In functionfwalk': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fwalk.c:43: undefined reference to___lock_acquire_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fwalk.c:46: undefined reference to_lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-fwalk.o): In function`fwalk_reent': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fwalk.c:67: undefined reference to ___lock_acquire_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fwalk.c:70: undefined reference to_lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-mlock.o): In function `malloc_lock': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/mlock.c:51: undefined reference to___lock_acquire_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-mlock.o): In functionmalloc_unlock': /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdlib/../../../../../newlib-1.16.0/newlib/libc/stdlib/mlock.c:60: undefined reference to`lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-fclose.o): In function _fclose_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fclose.c:102: undefined reference to_lock_release_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x8664-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fclose.c:81: undefined reference to `lock_acquire_recursive' /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/stdio/../../../../../newlib-1.16.0/newlib/libc/stdio/fclose.c:85: undefined reference to___lock_release_recursive' /home/nfv1/clickos/toolchain/x86_64-root/x86_64-xen-elf/lib/libc.a(lib_a-lseekr.o): In function_lseek_r': /home/nfv1/clickos/toolchain/newlib-x86_64/x86_64-xen-elf/newlib/libc/reent/../../../../../newlib-1.16.0/newlib/libc/reent/lseekr.c:58: undefined reference tolseek64' collect2: error: ld returned 1 exit status make[3]: **\* [bin/test_bn] Error 1 make[3]: Leaving directory/home/nfv1/clickos/toolchain/relic' make[2]: * [test/CMakeFiles/test_bn.dir/all] Error 2 make[2]: Leaving directory/home/nfv1/clickos/toolchain/relic' make[1]: **\* [all] Error 2 make[1]: Leaving directory/home/nfv1/clickos/toolchain/relic' make: * [_relic-build] Error 2

The "___lock_acquire_recursive" is undefined in libc.a from newlib. If I am correct, it is defined in sys/lock.h but does not appear in the include files in newlib. Any ideas?

Thanks a lot, Hassan

hassanjameel1 commented 9 years ago

Hi,

I have been able to build relic successfully with newlib. Thanks for your help.

I have two questions not related to relic.

  1. When I increase the memory of DomU, say beyond 1024MB, the clickos startup hangs at "main". That is, at:

Xen Minimal OS! start_info: 0xa04000(VA) nr_pages: 0x100000 shared_inf: 0x885fc000(MA) pt_base: 0xa07000(VA) nr_pt_frames: 0x9 mfn_list: 0x204000(VA) mod_start: 0x0(VA) mod_len: 0 flags: 0x0 cmd_line: stack: 0x1c0ac0-0x1e0ac0 MM: Init _text: 0x0(VA) _etext: 0x1159ec(VA) _erodata: 0x199000(VA) _edata: 0x19ac3c(VA) stack start: 0x1c0ac0(VA) _end: 0x203010(VA) start_pfn: a13 max_pfn: 100000 Mapping memory range 0xc00000 - 0x100000000 setting 0x0-0x199000 readonly skipped 0x1000 MM: Initialise page allocator for 1210000(1210000)-100000000(100000000) MM: done Demand map pfns at 100001000-2100001000. Heap resides at 2100002000-4100002000. Initialising timer interface Initialising console ... done. gnttab_table mapped at 0x100001000. Initialising scheduler Thread "Idle": pointer: 0x2100002050, stack: 0x1240000 Thread "xenstore": pointer: 0x2100002800, stack: 0x1250000 xenbus initialised on irq 1 mfn 0x23103a Thread "shutdown": pointer: 0x2100002fb0, stack: 0x1260000 Dummy main: start_info=0x1e0bc0 Thread "main": pointer: 0x2100003760, stack: 0x1270000 sparsing 0MB at 1b2000 "main"

After trying to restart it a few times it starts up. Is there any reason behind that?

  1. In case of page fault errors, is there any way to debug and see what might be causing the error?

Thanks, Hassan

fmanco commented 9 years ago

Hey Hassan

Great that you got it working. I just tested it with 2048 MB and it works, so I would need more information to understand what's going on. You can use gdbsx to debug a running domain.

You can use something like gdbsx -a <DOMAIN_ID> 64 60000 to run the server and gdb -ex "target remote localhost:60000" -d <CLICKOS_PATH> -d <MINIOS_PATH> <IMAGE_PATH>, to attach the debugger. You can then debug like a traditional application.

Best regards Filipe

jpemartins commented 9 years ago

Hey Hassan,

I think it's not hangup on "main" but rather waiting for a Click configuration. Actually it would be good to add something that hints the user that it's waiting for a config.

Could try starting up a simple configuration like FromDevice(0) -> Discard() just for you to see the router initializing?

Cheers!