LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   gcc creating a huge executable image (RedHat 2.6.18-8.el5, x86_64, Linux) (https://www.linuxquestions.org/questions/linux-general-1/gcc-creating-a-huge-executable-image-redhat-2-6-18-8-el5-x86_64-linux-759302/)

dbulka 10-02-2009 06:56 PM

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?

Matir 10-02-2009 10:06 PM

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


All times are GMT -5. The time now is 12:27 PM.