gcc creating a huge executable image (RedHat 2.6.18-8.el5, x86_64, Linux)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
gcc creating a huge executable image (RedHat 2.6.18-8.el5, x86_64, Linux)
I'm trying to figure out the mystery of the 64-bit ELF image. I wrote a hello.c little program, compiled with
% gcc hello.c -o hello
No problem. Got a "hello" executable image of size 6668 bytes. So far so good.
I really want to understand the "-Ttext" linker parameter so I repeated the compilation, this time with a linker parameter:
% gcc -Xlinker -Ttext=0x2000 hello.c -o hello
Again, a "hello" executable gets created and even runs ok, but the size of the file is roughly 2MB (2102706 to be exact.) So I go looking inside the image for some clues:
% dd bs=4092 count=256 if=hello | od -Ax -tx1z -v
The image starts with the expected ELF header. Then I found out that the ".text" segment itself was placed in offset 0x2000 in the "hello" file. The ".text" segment was followed by almost 2MB of zeroes.
Main questions:
What is the meaning of the -Ttext= directive? (I thought it was supposed to tell the loader that I want the ".text" segment in that specific location in physical memory, not in the file itself. I really don't care where they place it in the file.)
Did I get this wrong? Does "-Ttext=" really indicate a file offset as opposed to a physical memory address?
-Ttext is an alias for "--section-start=text", which reads as:
Quote:
--section-start=sectionname=org
Locate a section in the output file at the absolute address given
by org. You may use this option as many times as necessary to
locate multiple sections in the command line. org must be a single
hexadecimal integer; for compatibility with other linkers, you may
omit the leading 0x usually associated with hexadecimal values.
Note: there should be no white space between sectionname, the
equals sign ("="), and org.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.