Make a shared library which can be executable in linux

    Great day!! Finally I came to know, how to create a file which can act as both shared library and executable. You might not have observed it in your unix machines. In linux, execute /lib/libc.so as a command, it gives you all the version information. I have been trying to simulate the same feature in my shared libraries also. I have seen glibc source code and got to know that we have to use entry option of linker. With that knowledge, I have written a small program and tried for a complete working day, with the result ending up in Illegal instructions/ segmentation faults. Then I have just sent a mail to gcc mailing list and got the answers 1 ,2 ,3.

I am attaching a simple 5 line c program here. Commands that I have used are

# gcc -g -W -Wall -fPIC -o libtest.so -shared -Wl,-e,test1 test.c

    #./ libtest.so

    Hi dp! you finally made it

    # 

In our C program, we have to declare a char array for .interp section to hold the absolute path of the linker. In our entry function test1, after processing the logic, we should use exit() function instead of returning. I dont know the logic behind these 2 points.

In Solaris also, we can have this feature. But, I have not tried/tested it. If you are interested, you can look at this. Read the whole page and see the comment named “solaris 9 compile”.

Using TUI commands when debugging with GDB

    Today, when I was using GDB, by mistake I have typed refresh. Immediately my window was split into 2 and upper half was loaded with the source code I was debugging. Finally it was like Visual studio debugger [Showing source in the top frame and commands in the bottom frame]. I like this feature very much and but I did not know that it is available in GDB.
Then I did some research about that and came to know about TUI commands. TUI stands for Text User Interface. We can use TUI commands like layout, info, refresh in GDB. We can see the source code of our debugging program by executing “layout src” command in GDB. Similarly, we can see assembly instructions and regs values also. You can read more about TUI commands at this link. I have attached screenshot of my GDB. By seeing that, you can get the overview of how it looks like. In the src layout, we can see our breakpoints [Marked with B+ on left side] and at which step our program is executing [Marked with > on left side and highlighted text].

Newer entries »