473,750 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c program binary/image in memory

Hi folks,

I want to understand how exactly is an image(compiled
c code and loaded into memory) stored in memory.

What exactly is a linker script?

I work with a lot of c code on a daily basis but I really
don't understand :

How exactly the sections
like "text,bss,d ata etc."
work?

What exactly are they?

I believe the linker script describes this layout.

What exactly is a 'bundled image'?

What exactly is 'microcode'?
What exactly is 'firmware'?

I admit I use these terms myself pretty often,but
without much clarity.

Anyways any information or pointers(intern et urls) in
this regard would be very helpful.

If it helps,my work involves a lot of driver code
in C on systems using MIPS processors.

Thanks a bunch..

Jan 19 '06 #1
29 3958
tele-commuter wrote:
Hi folks,

I want to understand how exactly is an image(compiled
c code and loaded into memory) stored in memory.


None of your questions are topical to this newsgroup, which deals only
with ISO standard C.

A good starting link:

http://www.iecc.com/linker/

Jan 19 '06 #2
tele-commuter a écrit :
Hi folks,

I want to understand how exactly is an image(compiled
c code and loaded into memory) stored in memory.

What exactly is a linker script?

This is an extension of the GNU linkers that allows
GNU people to configure their linker. Normal users
are not supposed to use that, at least I didn't understand
anything about it. This is GNU specific, so off topic
here.
I work with a lot of c code on a daily basis but I really
don't understand :

How exactly the sections
like "text,bss,d ata etc."
This sections map following parts of the language:

1) The "text" section is the translated output of
the compiler, the program text. For instance

int fn(void) { /* ... */

the sequence of instructions in this function will be stored
in the "text" section. This section is normally not
writable.

2) The bss section implements the zero initialized data. For instance
when you write

int b[23];

This array will be mapped into the bss section. This section will
be zeroed by the operating system when the program is loaded.
The standard specifies that this must be zeroed before the program
starts. Note that the bss sections and the data sections are
writable, i.e. can be modified.

3) The data section corresponds to the initialized data of your program.

For instance when you write:

int c[] = { 1,2,3};

The sequence of integers 1,2,3 will be stored in the data section.

In short, a C program consists of program instructions, uninitialized
data and initialized data. This logical sections of the program
are mapped into text,bss,and data, respectively.

Other sections may exist, for instance sections containing debug
information, but they are optional.

It is legal to write a program with only the text section, without any
bss/data sections. For instance this program:

int main(int argc,char *argv[])
{
return (argc*argc);
}

has only a text section, and no data/bss section.

Obviously this program could end up having a data/bss section
anyway, since the code that runs before main (the startup code
in a hosted implementation) could need those sections.
jacob
What exactly is a 'bundled image'?

No idea
What exactly is 'microcode'?
Microcode is the software that runs in the CPU itself. Modern
CPUs present a user interface with registers, ALU, etc. Internally
the high level instructions are decomposed into smaller and more
basic instructions. A sequence of them implements the user visible
instructions. This is more hardware related and it is off topic here.
What exactly is 'firmware'?


It is the software supplied by the hardware manufacturer. Again,
this is hardware related and off topic here.
Jan 19 '06 #3
Thanks a lot for the information.

Now let me provide the context.

I work with a network device (a distributed system).

Its a multiple CPU system.The main CPU runs a single monolithic image
(i referred to this as a "bundled image" in my post).

Portions of it get downloaded to other cards in the chassis during
system initialization/bootup.

What I wanted to understand in some detail was how the main CPU gets
this work done
of downloading portions of code onto other cards.I presume this is
related to way the code
is written,how makefiles are written,and how the binary is laid out in
memory to achieve this
functionality etc.

I do understand portions of my queries are off topic but I am trying to
get some clarity on
how much of all this really language/and hence compiler/linker/loader
dependant and also
how these tools come together to achieve some complicated ability like
the context I have
described.

Thanks anyways for all the help.

All the questions I have asked were keeping this situation in mind.

Jan 19 '06 #4
jacob navia wrote:
tele-commuter a écrit :
Hi folks,

I want to understand how exactly is an image(compiled
c code and loaded into memory) stored in memory.

What exactly is a linker script?


This is an extension of the GNU linkers that allows
GNU people to configure their linker. Normal users
are not supposed to use that, at least I didn't understand
anything about it. This is GNU specific, so off topic
here.


<OT>
I've used plenty of systems that had absolutely nothing to do with GNU
that used things called linker scripts where the user was *meant* to
write a linker script.

So you are correct that it is off topic, and may well be correct with
reference to GNU (or maybe not, I'm not going to verify either way) but
you are definitely *not* correct in general.
</OT>
I work with a lot of c code on a daily basis but I really
don't understand :

How exactly the sections
like "text,bss,d ata etc."


This sections map following parts of the language:


<snip>

This is also all highly system specific. I've worked on plenty of
systems that did not have this combination of sections.

You should also have flagged this as off topic.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Jan 19 '06 #5
tele-commuter wrote:
Thanks a lot for the information.
What information? Please provide context so people can see what you are
replying to. For information on how to do this read
http://cfaj.freeshell.org/google/
Now let me provide the context.

I work with a network device (a distributed system).

Its a multiple CPU system.The main CPU runs a single monolithic image
(i referred to this as a "bundled image" in my post).
<snip>
All the questions I have asked were keeping this situation in mind.


Add all the questions you asked were, and still are, OFF TOPIC.

Now, since Google which you are using shows a post before Jacob's
telling you that it is off topic but you are asking again, I'll explain
what that means.

It means you should ask somewhere else. So please find a group dedicated
to your system and ask there, because it is not what is discussed here.
I'm giving you this advice for your own good, because posting here is
unlikely to get you good answers to your questions.

FYI Jacob only usex x86 systems, and mainly Windows at that, so I doubt
that he knows a lot about how MIPS based systems work. Which is not to
say what he said was wrong for MIPS, it might be entirely correct for
all I know, but the MIPS experts won't be correcting any errors he might
have made.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Jan 19 '06 #6
Flash Gordon a écrit :
I work with a lot of c code on a daily basis but I really
don't understand :

How exactly the sections
like "text,bss,d ata etc."

This sections map following parts of the language:

<snip>

This is also all highly system specific. I've worked on plenty of
systems that did not have this combination of sections.

You should also have flagged this as off topic.


No, I do not agree.

C is a low level systems language, and as such, it is important to
be clear of the usage and the works of this mysterious tool called
THE LINKER.

This part of the system is as important as the compiler actually,
but will never explained and never mentioned anywhere. This is not
correct. C programs DO have the distinction between uninitialized
data areas and initialized ones, and that is even specified in the
standard. (The uninitialized ones should be set to zero).

There *is* always a section of the program that is reserved for
the machine instructions the circuit understands. There is almost always
a section for the initialized data, and the uninitialized data.

I think explaining this pertains to the C language, actually I think it
is an essential part that will often be neglected, treating the
compilation system as a magic black box that must be used
without any further understanding.

But of course we could agree on our disagreement ... :-)

jacob
Jan 19 '06 #7
jacob navia <ja***@jacob.re mcomp.fr> wrote:
Flash Gordon a écrit :
How exactly the sections
like "text,bss,d ata etc."

This sections map following parts of the language:


This is also all highly system specific. I've worked on plenty of
systems that did not have this combination of sections.

You should also have flagged this as off topic.


No, I do not agree.

C is a low level systems language, and as such, it is important to
be clear of the usage and the works of this mysterious tool called
THE LINKER.


IOW, you do not understend the difference between "how a toy compiler
works on a toy OS" and "how a compiler _could_ work anywhere".

A vague understanding of some irrelevant details of a Windows
implementation are of no help when you're trying to compile for, say,
the Mac. On a real system, the linker and the compiler can[1] be
different systems; one could use a variety of compilers with a single
linker, or a single compiler with a variety of linkers. And be none the
wiser about BSS, and no worse off for all that.

Richard

[1] Note: _can_, not _need_ - the opposite may also be true
Jan 19 '06 #8

jacob navia schrieb:
THE LINKER.

This part of the system is as important as the compiler actually,
but will never explained and never mentioned anywhere.

Not true.
On my system
man 1 ld
tells me a lot about the linker. Likewise,
man 4 a.out
tells me about the executable format and how the OS's loader treats it.

But it is absolutely CERTAIN, that on other systems, the manuals will
tell different things. On some platforms, there is even more than one
executable format.

So, this is absolutely off topic.

Jan 19 '06 #9
Richard Bos a écrit :
jacob navia <ja***@jacob.re mcomp.fr> wrote:

Flash Gordon a écrit :
> How exactly the sections
> like "text,bss,d ata etc."

This sections map following parts of the language:

This is also all highly system specific. I've worked on plenty of
systems that did not have this combination of sections.

You should also have flagged this as off topic.
No, I do not agree.

C is a low level systems language, and as such, it is important to
be clear of the usage and the works of this mysterious tool called
THE LINKER.

IOW, you do not understend the difference between "how a toy compiler
works on a toy OS" and "how a compiler _could_ work anywhere".

A vague understanding of some irrelevant details of a Windows
implementation are of no help when you're trying to compile for, say,
the Mac.
The gcc compiler is the compiler under MAC,and I would be surprised
that it wouldn't use the bss/data/and text sections. Really surprised.
On a real system, the linker and the compiler can[1] be different systems; one could use a variety of compilers with a single
linker, or a single compiler with a variety of linkers. And be none the
wiser about BSS, and no worse off for all that.

Richard

[1] Note: _can_, not _need_ - the opposite may also be true


I am speaking about logical sections, that are implicit in
the semantic of the C language.

int a = 488776;

This implies that somewhere in the executable, the data
488776 is stored in the binary representation specific
to the system where the translaion being done

This is the data section.

I will ignore your remarks about "toy compiler" or "toy system".
The system you are working in is obviously THE ONLY TRUE
OPERATING SYSTEM, and surely THE BEST ONE.
Jan 19 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5590
by: David Stockwell | last post by:
Hi, I'd like to read the contents of a file into memory. The problem is that this file is binary. I then want to store the whole thing in memory to a database as a blob. I have no problem reading from a file: I did this: import os f = open('/bin/ls' , 'r+b') data = f.read()
3
2098
by: Josema | last post by:
Hi to all, I have stored in a database some binary files (pdfs, and gif images), i would like to know how could i show it, in internet explorer when a person enters for instance in a textbox the id of the file that want to view.... This is my Sql table... ID int File binary
4
5178
by: Sharon | last post by:
Hi Everyone, I have a TIF file 62992 x 113386 Pixels, Huffman RLE compression, 3200 x 3200 DPI resolution, binary colored (1 Bit Per Pixel), file on disk size 43.08 MB (45,169,042 Bytes). This kind of image should consume 851.66 MB (893,028,184 Bytes) of memory when loaded, and this is exactly what I want it to consume. Otherwise; the representation per pixel will be 1 byte (8 Bits), which means that this kind of image require 6.652 GB...
2
2044
by: S.Creek | last post by:
Hi, I need to take few files (images in my case) and create one file out of them, this file should be accessed so i can grab a single image from it if necessary, i thought of taking all the images and put them in one binary file, but couldn't figure out a way to do that, anyone has an idea? thanks
4
2397
by: Beginner | last post by:
How do I convert JPEG images to binary files in ASP.NET? Please advice. Thanks.
8
4390
by: gsmith | last post by:
Hello, I am developing a video recording (mjpeg) system which records large binary files. I need to read the JPEG data from the binary file and create a bitmap object to be displayed. Unfortunately I cannot find an efficient way to do this in C#. I need to do this at 10fps+ with 1hour+ data files. My current approach is read a byte from the filestream, then create a MemoryStream to the created byte and then a bitmap from the memory
3
3693
by: Howler | last post by:
Hello all, I am having a hard time seeing what I am doing wrong with a program I am having to write that converts pbm monochrome images into a similar pgm file. The problem I am having is understanding how to properly convert the bit/pixel in pbm to byte/pixel in pgm. My program is very straight forward conceptually open files, read header, read binary data, convert to p5 in loop and then write file out. My for loop is where I am...
8
13060
by: brainflakes.org | last post by:
Hi guys, I need to manipulate binary data (8 bit) stored in a 2 dimensional array. I've tried various methods (arrays, using a string filled with chr(0), using gd lib) and so far the fastest way I've found is to actually create an 8-bit image in GD and use imagecolorat and imagesetpixel to read and write the data.
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.