This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Building a .so in c6x

I am trying to build a .c file into a .so library.  Ideally I would like to do this as part of the c6x linux build (i.e. prj build), but for now I would be happy to get it to build from the command line.

In Ubuntu, I use this command (snippet from Makefile):

example_api.so:
    gcc -shared -o libexample_api.so -pthread -fPIC -g -Wall example_api.c

Can anyone tell me the equivalent command to get it to build for the 6678?  I can prj build, so I have the 6678 cross-compile toolchain.

Thanks,

MS

  • Hello, MS!

    Try to look at this page on chapter 3.4

    http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

    If you need I can send for you my Makefiles, but they are very simple.

    I saw strange behaviour of linux-c6x when I try to use shared libraries.
    I build my software stack, that consist from several *.so libraries, custom kernel module and user space application. (All components working under DM816x linux and on desktop linux). After running application linux-c6x will hung. I discover this situation and found that system was crashed during loading shared library before my program will be execute. Can somebody tell me how I can solve this problem? Any tips required.

    P.S. I rebuild library to *.a and link it to my application as static and they working fine. But I'm need *.so.

    Thank you.

  • Thanks for the info, Vladimir.  I am able to build the .so.  As soon as I figure out how to download the image to the board I'll find out if it worked.

    MS

  • Hi, Vladmir,

    Linux C6x is using uClinux, not Linux for embedded system. Is it possible that it linked in the wrong libraries from Liinux, not uClinux? That may explain why it works for DM816x and desktop because both are running Linux, not uClinux.

    Rex

  • Hi, Rex! 

    Thank you for your answer. Yes it is possible, but I'm not sure.

    Rex, can you give me advice how I can build my software components during prj build stage, for excluding native linux libraries from desktop system. Thank you.

    Vladimir

  • Hi, Vladimir,

    You will need to set up your desktop to use cross-compiler. I don't know if you have done that. Setenv pretty much have done it for you, and you can refer to setenv to see how it was done. I wonder if the syslink hlos could be an exmple for you to build your component as part of the build. Syslink build a .ko module for High Level OS application running on Linux, and RTOS application on DSP.

    Rex 

  • Hello, Rex!

    Thank you for your answer! I twice check my build environment - it is the same setenv file than I do prj build. And I do 

    source setenv. I can rebuild all linux-c6x components and use it. But if I try use own shared libraries I have system hung, or sometimes this messages:

    /root # ./sem_test
    ./sem_simple_test: can't load library 'libgipcy.so.0'
    /root # export LD_LIBRARY_PATH=/root:$LD_LIBRARY_PATH

    System not exucute my main() function at all. And program possible killed. dmesg give me this message:

    Exception: Oops - instruction fetch PC[0x0] signo[7] code[0x30002]

    The static version of this program:

    /root # ./sem_test
    ./sem_test is running
    Press Enter to IPC_createSemaphore()

    IPC_createSemaphore(1) - Ok
    Press Enter to IPC_lockSemaphore()

    IPC_lockSemaphore(-1) - Ok
    Press Enter to IPC_lockSemaphore(1000)


    IPC_lockSemaphore(): Error lock semaphore
    IPC_lockSemaphore(1000) - Error
    Press Enter to IPC_unlockSemaphore()
    IPC_unlockSemaphore() - Ok
    Press Enter to IPC_deleteSemaphore()

    IPC_deleteSemaphore() - Ok

    TEST COMPLETE

    Can you give me some tips or directions? How I can get dependencies of my program, as on desktop linux?

    ldd ./sem_test

    linux-gate.so.1 => (0xb771b000)
    libgipcy.so.0 => ../lib/libgipcy.so.0 (0xb770f000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb760d000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7462000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb745d000)
    librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb7454000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7439000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb741b000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb73ee000)
    /lib/ld-linux.so.2 (0xb771c000)

    May be you have some program that using shared library?

    Thank you.

    Vladimir

  • Hi, Vladimir,

    Is it possible that the *.so libraries you cross-compiled was not copied into the target root filesystem? The  libraries (libgipcy.so.0, …) should be copied into /usr/lib directory of the root filesystem and eventually run ldconfig on the target after that installation.

    Not sure if LD_LIBRARY_PATH works properly with C6x dynamic linker .

    Rex

  • Hi, Rex! Thank you for your answer. I'm working with NFS and libgipcy.so installed in target root filesystem after build automatically. But I will check your advice about LD_LIBRARY_PATH and properly library installation in /usr/lib directory and write here. Thank you again.

    Vladimir   

  • Hello, Rex!

    I try to examine issue with using of shared library on linux-c6x.

    1) I place shared library in target: /usr/lib/libgipcy.so

    2) I reboot my target, because I can't found ldconfig (about ldconfig you mention)

    3) I start my program without setting LD_LIBRARY_PATH and after that system was hung, before call main() function from my program. System behavior was the same that I mentioned early.

    4) application that linked statically with libgipcy working fine. I don't know there may be a problem and still need any suggestions and tips.

    Thank you.

    Vladimir

  • Vladimir,

    Not sure what the issue could be. Let me consult internally and get back to you.

    Rex

  • Vladimir,

    I just want to confirm that all hit libaries and the dynamic library you built exist in the file system.

    Rex

  • Hello, Rex!

    I have a some problem of using shared libraries in linux-c6x platform. I attach a simple project to examine problem in detail. It must be built under c6x-uclinux-gcc compiler. But you can test it on x86 platform by editing Makefiles (see comments in their).

    Attached example: 5050.shlibtst.tar

    After exam application exit - processor will be hung. Kernel stop working. Here the program output:

    / # cd shlibtst/
    /shlibtst # ./exam
    dlopen() - ok
    dlsym() - ok
    function1(1, 2)
    dlclose() - ok

    Press enter to exit
    Oops - undefined instruction: 8cc76fa8

    PC: 8cc76fa8 SP: 8cfffe50
    Status: 15000102 ORIG_A4: 8c87ee00
    A0: 00000000 B0: 800c07b8
    A1: 8cc76f84 B1: 80430720
    A2: 8cef9308 B2: 15000103
    A3: 00004000 B3: 800bfbd0
    A4: 8c87ee00 B4: 0000541b
    A5: 8c1b5120 B5: 15000102
    A6: 8cfdfc54 B6: 8cfdfc54
    A7: 00000000 B7: 8cd7f084
    A8: 00000002 B8: ffffffbb
    A9: 8c192808 B9: 00000002
    A10: 8cfdfc54 B10: 8cfdfc54
    A11: 8c87ee00 B11: 00000000
    A12: 8c87ee00 B12: 15000102
    A13: 8cdeafcc B13: 8cf1173c
    A14: 00000072 B14: 8cc79308
    A15: 8cffff68 B15: 8cfffe50
    A16: 00000000 B16: 800c07b8
    A17: 8cc76f84 B17: 80430720
    A18: 8cef9308 B18: 15000103
    A19: 00004000 B19: 800bfbd0
    A20: 8c87ee00 B20: 0000541b
    A21: 8c1b5120 B21: 15000102
    A22: 8cfdfc54 B22: 8cfdfc54
    A23: 00000000 B23: 8cd7f084
    A24: 00000002 B24: ffffffbb
    A25: 8c192808 B25: 00000002
    A26: 00000000 B26: 800c07b8
    A27: 8cc76f84 B27: 80430720
    A28: 8cef9308 B28: 15000103
    A29: 00004000 B29: 800bfbd0
    A30: 8c87ee00 B30: 0000541b
    A31: 8c1b5120 B31: 15000102
    Corrupted stack page
    Process isvi_server (pid: 120, stackpage=8c1b5f00)
    Stack from 8cfffbfc:
    80003444 8000345c 803d8fd7 8c1b50e8 00000078 8c1b5f00 80433dd8 80433dfc
    8cc76fa8 8c87ee00 8cdeafcc 800035a4 803d8ffe 803d9043 8cc76fa8 00000004
    00030001 00000016 8047a030 800637b0 8cfffd38 8cbeda00 00000016 1843a566
    80431170 80052868 804311a0 00000016 18519600 804311f8 18519600 80431170
    80431170 00000016 80053fbc 1843a566 00000016 7fffffff 00000001 18519600
    18148d00 804311f8 18148d00 80431170 80431170 00000016 ffffffff 00000016
    Call trace: [<80003444>] die+0x1b4/0x1d4
    [<8000345c>] die+0x1cc/0x1d4
    [<800035a4>] do_trap+0x100/0x178
    [<800637b0>] tick_dev_program_event+0x90/0x234
    [<80052868>] hrtimer_wakeup+0x38/0x50
    [<80053fbc>] hrtimer_interrupt+0x214/0x528
    [<80017cbc>] wake_up_process+0x0/0x2c
    [<803ab240>] printk+0x0/0x40
    [<80003890>] process_exception+0x274/0x390
    [<800a9330>] fget_light+0x100/0x170
    [<80017cbc>] wake_up_process+0x0/0x2c
    [<803ab240>] printk+0x0/0x40
    [<80011634>] timer_interrupt+0x28/0x54
    [<80009c9c>] ret_from_trap+0x0/0x3c
    [<800c07b8>] sys_ioctl+0x0/0xe8
    [<800bfbd0>] do_vfs_ioctl+0x10c/0xcf4
    [<8007573c>] irq_to_desc+0x0/0x34
    [<800125e0>] handle_cpintc_combined_irq+0x168/0x224
    [<80009e1c>] resume+0x0/0xa4
    [<80009ec0>] __current_thread_info+0x0/0x20
    [<80009e1c>] resume+0x0/0xa4
    [<800c0818>] sys_ioctl+0x60/0xe8
    [<80008e28>] ret_from_syscall_function+0x0/0x4

    Adding LD_DEBUG before running application don't help me. I try different RTLD_x flags with the same result.

    Please try to build example and run it on linux-c6x. Thank you.

  • Hi, Vladimir,

    I don't see the issue. It works for me. Please see attached screenshot from my linux-c6x console. I did one change in the shlib1/Makefile from $(CSTOOL_PREFIX) to $(CROSS_COMPILE). I also did "export CROSS_COMPILE=c6x-uclinux-". Is it possible that using CSTOOL_PREFIX casued shared library built using wrong compiler?

    Rex

     

  • HI, Rex!

    Thank you for your answer. This is from my environment-c6x file:

    export PATH=~/linux-c6x/opt/gcc-c6x/bin:$PATH
    export C6X_BASE_DIR=$CGT_LINUX_DIR
    export C6X_CGT_VERSION=7_2_2
    export CROSS_COMPILE=c6x-uclinux-
    export ARCH=c6x
    export CSTOOL_PREFIX=${CROSS_COMPILE}
    export KERNELDIR=${HOME}/linux-c6x/linux-c6x
    export PATH=${HOME}/embedded/common:${PATH}
    export PATH=${HOME}/ti/ccsv5/ccsv5/tools/compiler/c6000/bin:${PATH}
    export INSTALL_MOD_PATH=${HOME}/targetfs-c6x
    export INSTALL_PREFIX=${HOME}/targetfs-c6x/usr/lib

    export CC=c6x-uclinux-gcc
    export CPP="c6x-uclinux-gcc -E"
    export NM=c6x-uclinux-nm
    export RANLIB=c6x-uclinux-ranlib
    export OBJCOPY=c6x-uclinux-objcopy
    export STRIP=c6x-uclinux-strip
    export AS=c6x-uclinux-as
    export AR=c6x-uclinux-ar
    export OBJDUMP=c6x-uclinux-objdump
    export KERNELDIR=${HOME}/linux-c6x/Build/kobjs/evmc6678.el
    export INSTALL_MOD_PATH=${HOME}/targetfs-c6x
    export INSTALL_PREFIX=${HOME}/targetfs-c6x
    export TARGETFS_USER=embedded

    export PS1="\[\e[32;1m\][linux-c6x]\[\e[0m\]:\w> "

    1) Rex, please, can you provide me your setenv file and type of rootfs that you using (min rootfs, full rootfs or custom).

    2) Can you provide me your binary image of exam. I try run it on my system.

    I suppose that I have some system configuration errors. linux kernel, rootfs image, or cross tools environment, but I can't understand where exactly.

    Thank you.

  • Hi, Vladimir,

    I didn't do anything extra. I used the pre-buiild image, evmc6678-initramfs-demo.el-hf-linux-c6x.2.0.0.63.bin programmed to the NAND. I believe the file system in the prebuild is mcsdk-demo-root. The only build environment variables I set are the PATH and CROSS_COMPILE through command line, and I modified the Makefile to use CROSS_COMPILE, not CSTOOL_PREFIX. I did "make" in both shlibtst and shlib1 directories. Then tftp'ed the binaries, the exam and 3 shared libraries,  to the EVM.

    The binaries, exam and libraries, are attached.

    3858.tst.tar

    Rex

     

  • By the way, I "chmod +x" to the binarries and moved the libraries under /lib after tftp them to the EVM.

    Rex

     

  • Hi, Rex!

    Thank you for your time!

    I run your binaries with the same result as before: crash dump of process exam. See the log below.

    /tst # ls
    exam
    /tst # ./exam
    dlopen() - ok
    dlsym() - ok
    function1(1, 2)
    dlclose() - ok

    Press enter to exit. After application was exit system is broken up!
    Oops - undefined instruction: 8cd6afd0

    PC: 8cd6afd0 SP: 8ca7fd50
    Status: 15000102 ORIG_A4: 03300694
    A0: 03300694 B0: 00000000

    ************************

    [<8002eb30>] do_softirq+0x88/0x94
    [<80009c9c>] ret_from_trap+0x0/0x3c

    My rootfs was taken from mcsdk-demo-root-c6x-hf.cpio.gz and from full-root-c6x-hf.cpio.gz. I copy *.so into the /lib and do chmode +x as you say. With my binaries the same result too.

    Rex, please can you tell me that cross tools you use:

    1) $TOP_C6X_DIR/sdk/bin - this directory created after "prj build" command. Or from 

    2) $TOP_C6X_DIR/opt/gcc-c6x/bin? 

    Did you do "source setenv" in linux-c6x-project before building from external Makefile?

    Can you run my binaries on your system runnig from NAND and from NFS?

    I use NFS mounted rootfs. May be here issue?

    My binaries: 3051.bin.tar

    Update 1. You use kernel from Release linux-c6x-2.0, but I use latest kernel based on linux-c6x.org git repo.

  • Hi, Vladimir,

    Your binaries works fine on my EVM as well. I installed the compiler off my mounted hard drive at /media/disk3/opt/linux-c6x. I don't think it matters. Nor does the NFS or NAND FS. Could you try the release kernel instead?

    Rex

  • Hi, Rex!

    Thank you for your help! You are right, it was a kernel problem! Yesterday, I compared your kernel, my and latest from linux-c6x.org git repo. I found some files that was not the same as in linux-c6x.org in /arch/c6x/kernel directory. After correct them example became working.

    But there is another problem, if you add such code (and headers) in shared library

    std::string str = "Hello, World!";

    fprintf(stderr, "%s(): %s\n", __FUNCTION__, str.c_str());

    After start exam I see such message:

    ./exam: cant't resolve symbol '_ZNaIcEC1Ev' in lib '/shlibtst_cpp/bin/libshlib1.so'

    But if I using std::vector - all work ok.

    Thank you.

    Example: 1425.shlibtst_cpp.tar

    P.S. This thread may be marked as answered, but I can't to do it.

    Update: I miss commit from Nov 5 in linux-c6x.org in my source tree