Problems with linking of shared libraries in AIX

    Normally, in Solaris, Linux and other common platforms, shared libraries are represented with .so/.sl suffix. Static libraries are represented with .a suffix in filenames. But in AIX, static libraries have .a suffix and shared libraries can have either .so or .a suffix.

when we try to compile a c file which uses shared library with .so suffix, it wont succeed by default. It gives a compilation error. Additionally we have to pass “-Wl,-brtl” flag to the compiler. “-Wl” is to say that it is a flag to the linker, so “-brtl” is internally passed to the linker [ld]. “-brtl” says that it should consider files with .so suffix also as shared libraries. There is no need to pass this flag when your shared library contains .a suffix. This type of linking is loadtime linking.

When we want to access a shared library at runtime using dlopen & dlsym calls, it is called runtime linking. In this case, we wont get any compilation errors. If the shared library contains .a suffix, we wont get any errors at runtime also. But if the shared library contains .so suffix, we get segmentation fault at runtime. Confusing thing is, it succesfully executes dlopen call, but at the time of dlsym, it exits with segmentation fault. If we give “-Wl-brtl” flag to compiler at compilation time, runtime linking goes fine.

Why doesn’t firefox prompt to remember yahoo password

I have observed that firefox does not prompt to remember password for yahoo mail. Then after searching for it over net, I found that we can restrict browsers from prompting to remember passwords. In HTML <form> elelement, we can use autocomplete=”off” to restrict browsers from prompting. Yahoo mail uses form element like this <form method=“post” action=; autocomplete=“off” name=“login_form”>.

In this webpage, I have found a bookmarklet which will remove autocomplete=”off” parameter in form element. So, when we click login, browser submits the login/password to server and prompts the password remember dialog [because, now form element does not have autocomplete=”off” parameter]. Once the browser remembers password info, from next time on, it does not check for autocomplete parameter in form element.

How to execute: open firefox and enter Once the page is loaded, copy the bookmarklet and paste it in the address bar and execute. It says it has removed autocomplete parameter from the form. Then, enter your login/password info and press enter. Then, firefox “remember password dialog” appears.

You can copy the bookmarklet from the above mentioned webpage or I have copy/pasted the same bookmarklet here.

Using opaque data types in C

Suppose if we have to write a SDK and don’t want others to know the details of function parameters, we can use opaque data types in C. In most of the cases, you may not need these. But if you use them, it will be very difficult for hacker/crackers to know what is being stored in the datatype. I have made a sample library and a program which uses them. You can download them here. I have written this code just to demonstrate; it is not optimized.
test1.h and test1.c are used to generate file. test2.c is used to test the library. We give only test1.h and files to our customers. Lets assume test2.c is the program written by him. By seeing test1.h, customer does not know what is “opaque_type1“. But he uses it in his code [test2.c] and gets the result.

If we are using C structures for making opaque data types, we can’t use them directly as compiler does not know the size of it to allocate[In my code, I have implemented opaque data types using C structures. They are just declared not defined]. We always have to use them as pointers.

Version scripts & Function aliasing

    In windows, there is a problem called “DLL HELL” which has been there for many years. I heard that, Vista is going to provide a complete solution to this problem. Unix guys thought about this problem long back and provided solution through “Version scripts” [First implemented in SunOS 2.5 and later also implemented in GCC and linux]. Through version scripts, we can simply maintain versions in shared libraries. When we link an application against a shared library that has versioned symbols, the application itself knows which version of each symbol it requires, and it also knows which version nodes it needs from each shared library it is linked against. Thus at runtime, the dynamic loader can make a quick check to make sure that the libraries you have linked against do in fact supply all of the version nodes that the application will need to resolve all of the dynamic symbols.

Simple version script looks like the following

	VERS_1.1 {
	VERS_1.2 {
	} VERS_1.1;

More info on version scripts is given better in the reference links mentioned in the end.

GCC has added an extension to this and provided an excellent feature for function aliasing. We can do this by adding assember macro like the following in C code.

		__asm__(".symver old_foo,foo@VERS_1.1");
		__asm__(".symver old_foo1,foo@VERS_1.2");
		__asm__(".symver new_foo,foo@@VERS_2.0");

So, for the executables linked with VERS_1.2, a function call to foo will be redirected to  old_foo1 internally.  Similarly for executables linked with VERS_1.1,  function call to foo will be redirected internally to old_foo.

You can find more description about these at   [This original URL is too long.. so snipped it]

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/ 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 -shared -Wl,-e,test1 test.c


    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].

How to make a web page better printable

Today, I have seen a webpage full of menus, submenus and other links to their sites. But, it has a very good information. I can take printout, but I dont like to see the page with their menus/submenus. But I tried to print that page from firefox. Surprisingly, I did not get their menus/submenus. I got exactly what I wanted. Then I saw HTML source code and saw this line <link rel=“stylesheet” type=“text/css” media=“print” href=“print.css” />. Then I read about link tag in HTML and came to know that attribute named “media” can be used to specify action name. Then I saw this article “Print Different“. If you want this kind of functionality in your web application, then read the above mentioned article.

Dont use null pointers directly in solaris

        Code : char * text= NULL;  int text_len=strlen(text);

Above code, if it is used in linux, it works fine. text_len variable value will be 0. But the same code, if it is used in solaris, it gives segmentation fault. When I first encountered this problem, I struggled for 1 day debugging my code for the bug and finally I found this very good link solaris-null-pointer-bug.

It was intentionally implemented in solaris to catch the poorly written code. So, if we first check our (char *) pointer is NULL or not, there won’t be any problem. If you are too lazy to do all this, you can either use setenv LD_PRELOAD_32 /usr/lib/

Soap web services and ReST web services

    Soap webservices are webserivces which use soap protocol [no longer simple object access protocol.. it is so complicated now]. ReST stands for Representable State Transfer web services.  ReST web services use normal HTTP protocol. These are simple and represented in HTTP URLs. These do not depend any common definition language like wsdl. Definition language/output schema is given by service provider. In ReST web services, we access a web page and get XML output [mostly xml output .. we can get output in other formats also. this depends on service provider] instead of HTML. XML output schema is specified by the service provider. Now a days, many internet companies like yahoo, amazon are giving their apis based on ReST instead of traditional soap services. For accessing these from programs, we just have to have xml apis for parsing xml output from the services. If our webservices do not need any state, we can implement them using ReST which aligns well with HTTP protocol [ stateless protocol]. We can also implement stateful services also using ReST.

If we want security, transaction support in our services, it is better to implement them in soap services only.. because there are lot of specifications/apis for doing that. You might have heard JAX-* apis for web services. All of those are for soap web services [although JAX-WS 2.0 says that it supports ReST also].

For services used in AJAX, ReST services fit well. ReST service messages are shorter than soap service messages because soap services use lot of XML [soap itself is represented in XML]. Recently I read in some article that, ReST services use very less amount of memory because XML demarshalising is very little when compared to soap. So, ReST services are good for low memory devices also.

Have you tried web services in sun studio?

    In .net IDE, MS has integrated web services with their IDE very well. You ask any MS dev guy, I am sure they will say it is very simple and takes 5 minutes to develop and deploy.

    But, I have never heard the same words from a java guy [Atleast from the java people that I know]. Like many, I used to think developing web services in java is difficult and have to write lot of code manually. But, recently I had explored web services options in Sun Studio Enterprise. Totally, I had spent 2 hours in collecting/seeing tutorials and flash demos.

    Sun has considered many things from dev point of view. It has put all options necessary for webservices. Finally, when I tried to develop a web service, it was completed in 5 minutes. yes.. really 5 minutes!!

    Not only web services, that tool is very good for enterprise development. Enterprise development means, I would say web applications, EJBs, Web services and Integration with major application servers from with in the IDE. For my application development, I have used that tool. It has lot many good features likes profiler, Application verification kit, debug integrated with all supported app servers and Matisse based GUI development[Drag and drop like in VB].

    If you want to do enterprise development in java.. then consider Sun Studio Enterprise [Its free!!].

You may find these following links useful.

« Older entries