Why does my C program lookup libraries on runtime?
I decided to create a neat little program out of boredom a few days ago. It works perfectly but whenever I run it, it produces weird output along with my own output. Every time a function call appears in my code, a line is sent to stdout that says that it is looking for the function in a file called libc.so.6 located in the directory /lib/tls. Here are two examples of what happens when I try to run my program:
Example 1: (my normal output is highlighted in dark red) jarobman@linux:~/Documents> ./imessage samurai.jpg Hello World! 10603: symbol=strlen; lookup in file=./imessage 10603: symbol=strlen; lookup in file=/lib/tls/libc.so.6 10603: symbol=fgetc; lookup in file=./imessage 10603: symbol=fgetc; lookup in file=/lib/tls/libc.so.6 10603: symbol=printf; lookup in file=./imessage 10603: symbol=printf; lookup in file=/lib/tls/libc.so.6 ffd8 10603: symbol=fputc; lookup in file=./imessage 10603: symbol=fputc; lookup in file=/lib/tls/libc.so.6 10603: symbol=fclose; lookup in file=./imessage 10603: symbol=fclose; lookup in file=/lib/tls/libc.so.6 10603: symbol=free; lookup in file=./imessage 10603: symbol=free; lookup in file=/lib/tls/libc.so.6 10603: symbol=strlen; lookup in file=./imessage 10603: symbol=strlen; lookup in file=/lib/tls/libc.so.6 Filename: samurai.jpg Message: Hello World! @ Example 2: jarobman@linux:~/Documents> ./imessage samurai.jpg This is a message, fool! 11060: binding file ./imessage to /lib/tls/libc.so.6: normal symbol `strlen' [GLIBC_2.0] 11060: binding file ./imessage to /lib/tls/libc.so.6: normal symbol `fgetc' [GLIBC_2.0] 11060: binding file ./imessage to /lib/tls/libc.so.6: normal symbol `printf' [GLIBC_2.0] ffd8 11060: binding file ./imessage to /lib/tls/libc.so.6: normal symbol `fputc' [GLIBC_2.0] 11060: binding file ./imessage to /lib/tls/libc.so.6: normal symbol `fclose' [GLIBC_2.1] 11060: binding file /lib/tls/libc.so.6 to /lib/tls/libc.so.6: normal symbol `free' [GLIBC_2.0] 11060: binding file /lib/tls/libc.so.6 to /lib/tls/libc.so.6: normal symbol `strlen' [GLIBC_2.0] Filename: samurai.jpg Message: This is a message, fool! @ Here is my code just in case: (This is a console program that accepts a JPEG file and either writes a message in in it [parameters after the file name] or retrieves an already placed message [no parameters after the file name]) Code:
#include <stdlib.h> Although my program works, I still could do without the ugly output. I have compiled my program with gcc version 3.3.3-41. I have no idea what the libc.so.6 file is and I don't know why it has to be searched through every time I call a C function. The main problem I have with this issue other that aesthetics is that this can cause a problem if I want to script my output to a file. Any solutions would be greatly appreciated. If I somehow, by a fluke, solve the problem myself, I will post the solution here for anyone having a similar problem. |
"Every time a function call appears in my code, a line is sent to stdout that says that it is looking for the function in a file called libc.so.6 located in the directory /lib/tls."
"I have no idea what the libc.so.6 file is and I don't know why it has to be searched through every time I call a C function." Every time you call a C function your program will go through libc.so.6. What is peculiar is that your program is logging calls to libc.so.6. Check the gcc command you used to compile this program to see if you have specified any debug options. http://gcc.gnu.org/onlinedocs/gcc/De...ugging-Options ---------------------------- Steve Stites |
I have only used the following commands to compile my program:
gcc imessage.c -Wall -o imessage -and- gcc imessage.c -o imessage It is a mystery to me why my program is logging calls to libc.so.6 because when it comes to compiling C programs, the above is as simple as it gets. |
Does the file /lib/tls/libc.so.6 exist?
libc.so contains the all the basic c libraries that you compile into your code. Your program is using fgetc, strlen, printf and others. You can see the libraries that you program depends on by running: Code:
ldd imessages Type the command: Code:
locate libc.so.6 |
I just ran my program without typing in any parameters. The result is a call to printf with a string describing the usage of the program as a parameter. This call to printf does not cause a call to libc.so.6 to be logged! I noticed that this is the only case where my FILE struct is not assigned to a stream, so I'm tempted to think that that might be related to my overall problem. I will look into this issue some more for now...
|
Quote:
|
I don't think my FILE stream has anything to do with my problem. I created the following program and it doesn't log calls to libc.so.6 at all:
Code:
#include <stdio.h> Code:
if (argc >= 3) |
You're somehow invoking LD_DEBUG.
Look here: http://www.wlug.org.nz/LD_DEBUG Try this: set|grep LD <= IF YOU'VE SOMEHOW SET "LD_DEBUG" IN YOUR ENVIRONMENT, PLEASE TRY *UNSETTING* IT AND RE-RUN YOUR PROGRAM 'Hope that helps .. PSM |
I ran set|grep LD but that didn't change my situation. I am not sure how to change anything in my environment variables. The link you provided didn't tell me much about how to solve my problem. However, I now have a focus point towards the grand solution of my problem. Thanks.
|
set | grep LD
wouldn't change the situation .... it would show you whether LD_DEBUG is set or not ... that aside, do you compile the program from a Makefile, and if so, did you "borrow" from some other source, by any chance? Maybe the directive is being invoked somewhere you haven't looked yet... Cheers, Tink |
I didn't compile from a makefile and I didn't borrow from another source. I made this program completely from scratch and as you can see from my code, I have only included three C standard libraries. I did similar operations in the test program that I wrote and the output was normal. I don't see anything unusual about my code that would cause this whole issue :confused: . It just doesn't make sense. If anyone can tell me how to change the LD_DEBUG_OUTPUT environment variable, please do. Thanks!
|
Not sure if this is the cause of your problem, but it is definitely a problem:
Code:
char *msg; |
I don't think mallocs are required in this situation. What the string functions do is put data in some place in memory and I'm just assigning the pointer msg to that address. I haven't seen a single segmentation fault during the creation of my program so far.
|
Quote:
Quote:
|
Quote:
As already stated, strcat just appends to the end of the pointer you give it, then returns that same pointer as a convenience. It does no memory allocation of its own. |
All times are GMT -5. The time now is 08:22 PM. |