Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Do you mean getting the source code? If so, then you can't. The library contains compiled versions of the functions. Compilation is a lossy process meaning that you can't get back the exact source code from the machine code. You'll have to download the source code for you library if you want to examine the functions it uses.
If you mean pulling the functions into your own program so your program does not require the library anymore, that's called "static linking". You'll need to things:
1. You need to have a ".a" version of the library you want to statically link against. A ".so" won't work.
2. When you compile your program, you need to pass a special command line argument to specify static linking. For gcc it's "-static". If you use a different compiler, you'll have to check its documentation.
When statically linked, the program is self-contained, meaning the program can be run on any system that supports the executable format it's in.
I was actually very interested in extracting the underlying source code of the C Programming Language. I was hoping that by "extracting" the functions from the C Libraries, I could actually see the Assembly Language Code that made up those functions. If the libraries are in Machine Code, then I suppose there is no way to "see" the source code.
On the other hand, Assembly Language and Machine Code are the same, the only difference is that Assembly Language is a Symbolic Representation of Machine Code (so instead of working in actual Binaries, we use English ). If there was some sort of program out there that could "rebuild" the Assembly Source code from this Machine Code... then I might have a hope
Regardless, what I was REALLY looking for was the underlying source code for the C Programming Language- does anyone know if it is available to the public?
Thanks, I would REALLY REALLY REALLLLLLLLLY APPRECIATE IT
Btw: Thanks Anyways Dark_Helmet, you reply was really informative in itself and I really appreciate your help
Well, there are "decompilers" out there, but I have no experience with them. You have to understand that if you find one, and if you can get it to work on a library, then any code it spits out will be almost unintelligible. Specifically, variable names will be seemingly random.. Granted, in assembly there aren't really variables; just registers and memory locations. I wish I could point you to one, but I don't know of any.
Now, you say you want to look at the underlying code for C. That's still open to interpretation. Do you want to see the code for a C compiler? Since we were talking about libraries, I assume that you'd be interested in the standard C library. The compiler and the standard C library are two entirely different beasts. The compiler is responsible for parsing your code, optimizing it, and eventually turning it into machine code. The standard C library is created by the compiler, and provides the tools for other programs to use. Either way, you can look at the C code for both.
Both of those pages provide links to download tarballs of source code.
One thing I need to mention: you have to understand that there is no golden standard of "underlying source code for the C Programming Language". The C programming language is a specification only. It says what a compiler must support, or defines what functions must be present in a standard library. The specification does not say how that stuff is implemented. The code for gcc is one way of doing it. A borland C compiler is another. Both adhere to the C specification, but how the compilers work under the hood can vary significantly. Similarly, the GNU C library is one implementation of the standard C library. There are other syandard C libraries that provide the same functions, but those functions can (and probably are) written very differently. There is no single implementation that everyone follows.
EDIT: One other thing to mention. The gcc compiler offers a command line to produce assembly code. In other words, the compiler stops short of actually spitting out machine code. I know the option exists, but I've only seen it referenced by other people; I don't know what it is off the top of my head. You'll have to consult the documentation of gcc to find out.
Last edited by Dark_Helmet; 06-24-2005 at 08:45 PM.
Such a Coincidence, I thought of just that last night- making the compiler stop short of producing Assembly Code
Well... since the glibc library is only an implementation of the Standard C Specification, I guess that means two things for me:
1) There is no actual "Standard C Library" issued by ISO- people must produce it themselves based on the specification
and
2) Since people make it themselves... and since GNU has been working on it... then the code has to exist
This is great! Except, being a noob and all (and at my grandma's house, without any of my notes or references... not to mention Linux too) I have absolutely no idea how to get my hands on it. I briefly skimmed at the sites you gave me and found a download for the library. Problem is I have a feeling that is the same machine-code library I have on my computer...
Like I said, I'm looking for the source. I will keep on searching for it, keeping my focus on the GNU site.
And thanks again for the help! You've been a VERY helpful person
And again, if anyone knows the link for the underlying source code of the GNU Implementation of the C Library, then please let me know
Originally posted by TGWDNGHN 1) There is no actual "Standard C Library" issued by ISO- people must produce it themselves based on the specification
I don't have a copy of the C library standard, but I do have a copy of the C++ standard (BS ISO/IEC 14882:2003). I would assume that the C standard is very similar, but for C.
It literally defines the C++ language, right down to what each keyword does, what the variable scoping rules are, and so on (although some things, like the size of an int, or attempting to read past the end of an array, is left to the implementation to decide). It also defines the standard libraries in the form of “this include file contains these macros and these functions” and describes the effect of each function, including its order of complexity.
Quote:
2) Since people make it themselves... and since GNU has been working on it... then the code has to exist
It would be hard to use C if the library code didn't exist.
Quote:
And again, if anyone knows the link for the underlying source code of the GNU Implementation of the C Library, then please let me know
The GNU implementation of the C compiler is available as part of the GNU Compiler Collection (GCC), which supports many different languages on many different architectures. The source code for GCC version 3.4.4 (latest stable version as I write this, excluding 4.0.0 because this has some issues) is available in a file called /pub/gcc/releases/gcc-3.4.4/gcc-3.4.4.tar.bz2 which you can find on any GCC mirror (http://gcc.gnu.org/mirrors.html). You can also just download the core and C modules if you like. Alternatively, take a look at 4.0.0 because it works slightly differently, especially with optimisation.
The GNU implementation of the C library is in a package called libc, which you can also find on GNU mirrors. Try searching for it on www.freshmeat.net.
I don't advise you to start by reading the source code. It's huge and without some background knowledge you won't understand how it all fits together. Take a look at the documentation on http://gcc.gnu.org/ first!
The links I gave do give you access to the source code. On both pages there are links to "Tar/Gz" or "Tar/Bz2". Those are the source code tarballs. Specifically, the link on the page for glibc takes you here: ftp://ftp.gnu.org/gnu/glibc/
That page is a list of files. All of the *.tar.gz or *.tar.bz2 files are source code tarballs. I downloaded and extracted one just now to make sure.
If you're not familiar with tar, you extract a file like so:
For *.tar.gz: tar xvzf <filename>
For *.tar.bz2 tar xvjf <filename>
After that, you'll have lots of subdirectories that organize the code into logical groups. For instance, there's a "strings" subdirectory that will contain the source code for string handling functions.
I would agree with rjlee though. If you want to look directly at the source code, be prepared for a steep learning curve.
Last edited by Dark_Helmet; 06-25-2005 at 10:27 AM.
Thank you so much! Since I'm not using my own computer (once again, granny's house) I didn't really have much time to even look at the site in any detail, but I did see the files for download. When I get home I'll make good note of this
And I am sure it can be a steep learning curve, but I'm a fast learner and I'm actually very eager to start learning assembly. Now I am by no means trying to be a Braggart, but as a 15 year old taking Calculus next year I think I am more than qualified to deal with the math and logic Assembly requires. I know this is stupid (and emberessing) but I work in binary everyday just trying to solve everyday applications. I'm familiar with the fact that I'll have to deal with the data in the registers, having to jump back and forth between them and having to check their status, as well as saving and restoring their states, but I'm not concerned.
I was planning to write generic, bullet-proof functions in Assembly and Use them C for the "Think Low, Write High" approach of programming. As for the C Library (and much of the language itself) I need to see a few things... things I've always wondered and questioned
Well anyways, thank you two so much! Sorry for being such a , but I had no choice . This will help encourage me to pursue my studies in the Linux and Programming Field. I usually lose my mind when I have to sense of direction, so this will help orient me to reach me goal.
I will take note of your assistance, and maybe I can repay both of you back some day
Thanks Again!
(PS: I think that answers my questions for now... but I may return !)
There are quite a few disassemblers out there, but be aware that they can only translate object code into assembler or into some semblance of source code; what you get out is usually very different to the original source (although it will compile to a functionally equivalent version, probably with different timing specifics).
Do you mean getting the source code? If so, then you can't. The library contains compiled versions of the functions. Compilation is a lossy process meaning that you can't get back the exact source code from the machine code. You'll have to download the source code for you library if you want to examine the functions it uses.
If you mean pulling the functions into your own program so your program does not require the library anymore, that's called "static linking". You'll need to things:
1. You need to have a ".a" version of the library you want to statically link against. A ".so" won't work.
2. When you compile your program, you need to pass a special command line argument to specify static linking. For gcc it's "-static". If you use a different compiler, you'll have to check its documentation.
When statically linked, the program is self-contained, meaning the program can be run on any system that supports the executable format it's in.
I wonder whether there is a way to "delink" a shared library, and get its "*.o" object files.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.