LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 10-02-2009, 06:56 PM   #1
dbulka
LQ Newbie
 
Registered: Dec 2006
Posts: 8

Rep: Reputation: 0
Red face 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?
 
Old 10-02-2009, 10:06 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
-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.
 
  


Reply

Tags
gcc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to configure samba in redhat linux el5 jai_nagarajan Linux - Server 2 07-06-2009 08:32 PM
Unable to get ip-address on RHEL5 with GNU/Linux x86_64 with 2.6.18-8.el5 kernel. RHEL5_1979 Linux - Wireless Networking 5 08-21-2008 05:14 PM
media player for Redhat EL5 and how to see windows xp from linux buva7687 Linux - Software 1 06-25-2008 06:23 AM
download "gcc 3.4" for redhat linux AS4 x86_64 naveenkarkra Linux - Newbie 5 09-06-2007 04:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration