Re: [PPL-devel] [Yap-users] Interfacing Yap with a C++ library

Vitor Santos Costa wrote:
- The second possibility is that C++ needs a dynamic library, which is
weird. You can try
configure --enable-dynamic-loading make clean make install
That should have a .so file.
Please tell me if you can't still make it work.
Dear Vitor,
since I have stumbled on exactly the same problem encountered by Pat, I have tried the above suggestion. This solves the problem indicated by "usr/bin/ld: /usr/local/lib/libYap.a(c_interface.o): relocation R_X86_64_32S against `Yap_REGS' can not be used when making a shared object; recompile with -fPIC". However, now there is another problem:
% Restoring file /usr/local/lib/Yap/startup YAP version Yap-5.1.1 % reconsulting /home/roberto/ppl/ppl/interfaces/Prolog/YAP/yap_pl_check.pl... % reconsulting /home/roberto/ppl/ppl/interfaces/Prolog/YAP/ppl_yap.pl... % % % YAP OOOPS: tried to access illegal address 0x8!!!!. % % 1725KB of Code Space (0x8800000--0x89af4b0) 1KB of Global Stack (0x89b4000--0x89b4598) 2KB of Local Stack (0x8b3f768--0x8b40000) 0KB of Trail (0x8b40008--0x8b40088) Performed 0 garbage collections Running code at clause 1 of prolog:load_foreign_files/3 Continuation is at clause 1 of prolog:load_foreign_files/3 clause 1 of prolog:load_foreign_files/3 clause 2 of prolog:$do_yes_no/2 clause 6 of prolog:$process_directive/3 clause 5 of prolog:$execute_command/4 indexing code of prolog:$catch/3 (*) clause 1 of prolog:$system_catch/4 clause 1 of prolog:$loop/2 clause 1 of prolog:$do_lf/9 clause 7 of prolog:$lf/13 clause 1 of prolog:$load_files/3 clause 5 of prolog:$execute_command/4 indexing code of prolog:$catch/3 (*) clause 1 of prolog:$system_catch/4 clause 1 of prolog:$loop/2 clause 1 of prolog:$do_lf/9 clause 7 of prolog:$lf/13 clause 1 of prolog:$load_files/3 indexing code of prolog:$catch/3 (*) clause 1 of prolog:$system_catch/4 clause 1 of prolog:$do_startup_reconsult/1 clause 1 of prolog:$init_system/0 clause 1 of prolog:$live/0
Exiting ....
The problem disappears if I configure with
configure --enable-dynamic-loading --enable-debug-yap
I have tried to disable all optimizations in order to better understand what is going on using gdb, but with optimizations turned off, making Yap dies at this point:
gcc -rdynamic -Wl,-R,NONE/lib -o yap yap.o libYap.so -lgmp -lreadline -lncurses -ltermcap -lm -ldl -lnsl /usr/bin/ld: yap: hidden symbol `stat' in /usr/lib64/libc_nonshared.a(stat.oS) is referenced by DSO /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status
By configuring with
CFLAGS="-g -O" ./configure --enable-dynamic-loading
I can use gdb to see where the illegal access at address 0x8 occurs:
% Restoring file /usr/local/lib/Yap/startup YAP version Yap-5.1.1 % reconsulting /home/roberto/ppl/ppl/interfaces/Prolog/YAP/yap_pl_check.pl... % reconsulting /home/roberto/ppl/ppl/interfaces/Prolog/YAP/ppl_yap.pl...
Program received signal SIGSEGV, Segmentation fault. Yap_NewPredPropByFunctor (fe=0x89af410, cur_mod=142656577) at ./C/adtdefs.c:532 532 p->KindOfPE = PEProp; (gdb) list 527 Prop p0; 528 PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p)); 529 530 INIT_RWLOCK(p->PRWLock); 531 INIT_LOCK(p->PELock); 532 p->KindOfPE = PEProp; 533 p->ArityOfPE = fe->ArityOfFE; 534 p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL; 535 p->cs.p_code.NOfClauses = 0; 536 p->PredFlags = 0L; (gdb) print p $1 = (PredEntry *) 0x0 (gdb) print &(p->KindOfPE) $2 = (PropFlags *) 0x8 (gdb)
Does this shed any light? Please let me know if I can do more to help locate the sources of the problems. All the best,
Roberto

Roberto,
the code assumes YAP successfully allocated memory, and it seems it did not. I'll try to see I can repeat it, but I suspect it's a difference between different versions of the Linux libc.

Roberto
Would it be possible for you to try
www.cos.ufrj.br/~vitor/Yap-5.1.2-small.tar.gz
and see if the problem still remains?
Thanks!
Vitor

Vitor Santos Costa wrote:
Would it be possible for you to try
www.cos.ufrj.br/~vitor/Yap-5.1.2-small.tar.gz
and see if the problem still remains?
Dear Vitor,
the version in the tarfile you provided fails in `make install' as follows:
... make[1]: Leaving directory `/usr/local/distrib/Yap-5.1.2/LGPL/clpr' (cd LGPL/chr ; make install) make[1]: Entering directory `/usr/local/distrib/Yap-5.1.2/LGPL/chr' "../../yap" -l chr_swi_bootstrap.yap \ -g "chr_compile_step1('chr_translate_bootstrap1.chr','chr_translate_bootstrap1.pl'),halt." \ -z 'halt(1).' ../../yap: error while loading shared libraries: libYap.so: cannot open shared object file: No such file or directory make[1]: *** [chr_translate_bootstrap1.pl] Error 127 make[1]: Leaving directory `/usr/local/distrib/Yap-5.1.2/LGPL/chr' make: *** [install_data] Error 2
By setting LD_LIBRARY_PATH I was able to let it find the just-generated libYap.so shared object.
After this, I could run all our regression test programs without any problem. So the problem that forced us to always configure with --enable-debug-yap seems solved. Moreover, with that version, everything works also if the --enable-dynamic-loading configure option is omitted.
The problem whereby it is not possible to switch off optimizations when compiling YAP is, however, still there: by configuring with
CFLAGS="-g" ./configure --enable-dynamic-loading
I obtain
... ld -shared -export-dynamic -o libYap.so agc.o absmi.o adtdefs.o alloc.o amasm.o analyst.o arrays.o arith0.o arith1.o arith2.o attvar.o bignum.o bb.o cdmgr.o cmppreds.o compiler.o computils.o corout.o cut_c.o dbase.o dlmalloc.o errors.o eval.o exec.o globals.o gprof.o grow.o heapgc.o index.o init.o inlines.o iopreds.o depth_bound.o mavar.o myddas_mysql.o myddas_odbc.o myddas_shared.o myddas_initialization.o myddas_util.o myddas_statistics.o myddas_top_level.o modules.o other.o parser.o readutil.o save.o scanner.o sort.o stdpreds.o sysbits.o threads.o tracer.o unify.o userpreds.o utilpreds.o write.o ypsocks.o ypstdio.o load_foreign.o load_dl.o load_dld.o load_dyld.o load_none.o load_aout.o load_aix.o load_dll.o load_shl.o c_interface.o opt.memory.o opt.misc.o opt.init.o opt.preds.o or.engine.o or.cowengine.o or.sbaengine.o or.scheduler.o or.cut.o tab.tries.o tab.suspend.o eamamasm.o eam_showcode.o eamindex.o eam_am.o -lgmp -lreadline -lncurses -ltermcap -lm -ldl -lnsl gcc -rdynamic -Wl,-R,NONE/lib -o yap yap.o libYap.so -lgmp -lreadline -lncurses -ltermcap -lm -ldl -lnsl /usr/bin/ld: yap: hidden symbol `stat' in /usr/lib64/libc_nonshared.a(stat.oS) is referenced by DSO /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status make: *** [yap] Error 1
All the best,
Roberto
participants (2)
-
Roberto Bagnara
-
Vitor Santos Costa