473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C and ELF segment

Hi,
I hope this question belongs to this group.

I am studying book <<Expert C Programming>and in the chapter of
run time data structure, it mentions that BSS segment only stores the
size of the un-initialized data, it does not have the data images, so
it does not take up any actual space in the object file.

I tried out a simple code, but it is not as said.

Here is my first code:

#include <stdio.h>

int main(void){
printf("hello");
}

and I run size command:

size a.out
text data bss dec hex filename
874 256 4 1134 46e a.out

You see bss is of size 4.

Now the 2nd code:

#include <stdio.h>

int arr[1000];

int main(void){
printf("hello");
}

and size command output:
size a.out
text data bss dec hex filename
874 256 4032 5162 142a a.out

so bss size increases roughly the array size!

Is this because my GCC on Intel machine has different format than
before?

Aug 1 '07 #1
5 2608
linq936 <li*****@hotmail.comwrites:
>Hi,
I hope this question belongs to this group.
You will probably receive many replies stating that it does not belong
here; comp.unix.programmer is a better choice.

I am studying book <<Expert C Programming>and in the chapter of
run time data structure, it mentions that BSS segment only stores the
size of the un-initialized data, it does not have the data images, so
it does not take up any actual space in the object file.
I tried out a simple code, but it is not as said.

From your logic, you appear to be confusing the values reported by
the 'size' command with the file's size (as reported by 'ls' on UNIX system).

--
Chris.
Aug 1 '07 #2
On Jul 31, 6:15 pm, linq936 <linq...@hotmail.comwrote:
Hi,
I hope this question belongs to this group.

I am studying book <<Expert C Programming>and in the chapter of
run time data structure, it mentions that BSS segment only stores the
size of the un-initialized data, it does not have the data images, so
it does not take up any actual space in the object file.
What is a data image?
I tried out a simple code, but it is not as said.

Here is my first code:

#include <stdio.h>

int main(void){
printf("hello");
If I remember correctly, not having the '\n' causes undefined
behavior. Also, were is the 'return'?!
}

and I run size command:
My Operating system doesn't have the size command.
size a.out
text data bss dec hex filename
874 256 4 1134 46e a.out

You see bss is of size 4.

Now the 2nd code:

#include <stdio.h>

int arr[1000];

int main(void){
printf("hello");

}

and size command output:
size a.out
text data bss dec hex filename
874 256 4032 5162 142a a.out

so bss size increases roughly the array size!

Is this because my GCC on Intel machine has different format than
before?
And when I think of ELF, I think of men running around in green tights
at Christmas time.

Aug 1 '07 #3
linq936 wrote:
Hi,
I hope this question belongs to this group.

I am studying book <<Expert C Programming>and in the chapter of
run time data structure, it mentions that BSS segment only stores the
size of the un-initialized data, it does not have the data images, so
it does not take up any actual space in the object file.

I tried out a simple code, but it is not as said.

Here is my first code:

#include <stdio.h>

int main(void){
printf("hello");
}

and I run size command:

size a.out
text data bss dec hex filename
874 256 4 1134 46e a.out

You see bss is of size 4.

Now the 2nd code:

#include <stdio.h>

int arr[1000];

int main(void){
printf("hello");
}

and size command output:
size a.out
text data bss dec hex filename
874 256 4032 5162 142a a.out

so bss size increases roughly the array size!

Is this because my GCC on Intel machine has different format than
before?
Supposing sizeof(int) == 4, an array of 1000 ints is 4000 bytes,
the size of the bss segment has increased accordingly.

The other 32 are probably alignment, but I do not know
exactly.

Aug 1 '07 #4
On Wed, 01 Aug 2007 01:15:45 -0000, linq936 <li*****@hotmail.com>
wrote in comp.lang.c:
Hi,
I hope this question belongs to this group.
Actually, it really does not.
I am studying book <<Expert C Programming>and in the chapter of
run time data structure, it mentions that BSS segment only stores the
size of the un-initialized data, it does not have the data images, so
it does not take up any actual space in the object file.
Assuming that you are talking about the book "Expert C Programming:
Deep C Secrets" by Peter van der Linden, it is indeed an excellent
book for intermediate to advanced C programmers.

One thing that you need to understand is that this book was written in
1994, 13 years ago, and things can change in that time. The C
language does not actually specify things like segments, a BSS
segment, Or ELF, COFF, a.out, OMF86, or any other file format. Peter
was talking about the behavior typical UNIX implementations that he
was familiar with at the time, not anything specified by C or UNIX or
guaranteed to remain unchanged forever.
I tried out a simple code, but it is not as said.

Here is my first code:

#include <stdio.h>

int main(void){
printf("hello");
}

and I run size command:

size a.out
text data bss dec hex filename
874 256 4 1134 46e a.out

You see bss is of size 4.

Now the 2nd code:

#include <stdio.h>

int arr[1000];

int main(void){
printf("hello");
}

and size command output:
size a.out
text data bss dec hex filename
874 256 4032 5162 142a a.out

so bss size increases roughly the array size!

Is this because my GCC on Intel machine has different format than
before?
Also, it is quite possible that what Peter said applies to your
compiler, but you are misunderstanding what he wrote. Since the
executable file must store the size, if not the contents, of the BSS
segment, what would you expect the "size" command to report?

What you really want to know is the difference in the file size of the
two a.out files themselves. If the second file is about 4,000 octets
larger than the first, the compiler and linker are storing 1,000 int
values of 0 in the file. If the second file is about the same size as
the first, perhaps just slightly larger, then it is obviously not
storing all those 0 valued ints in the file.

If you have further questions about object files, executable files,
segments, or other such thing are specific to your tool set, and not
defined by the language, you should ask in places like a gcc support
group (gnu.gcc.*), or perhaps news:comp.os.linux-development.apps or
news:comp.unix.programmer, if you develop on one of those platforms.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Aug 1 '07 #5
Jack Klein wrote:
On Wed, 01 Aug 2007 01:15:45 -0000, linq936 <li*****@hotmail.com>
wrote in comp.lang.c:
>Hi,
I hope this question belongs to this group.

Actually, it really does not.
<snip>
If you have further questions about object files, executable files,
segments, or other such thing are specific to your tool set, and not
defined by the language, you should ask in places like a gcc support
group (gnu.gcc.*), or perhaps news:comp.os.linux-development.apps or
news:comp.unix.programmer, if you develop on one of those platforms.
I'll also add <news:alt.lang.asmand <news:comp.lang.asm.x86to the list
of places where the OP can post his question. Executable file formats and
linkers are occasionally discussed there. A Google search of those groups
might turn up good threads.

Aug 1 '07 #6

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

Similar topics

1
by: Attila.Rajmund.Nohl | last post by:
Hello! I'm using KAI C++ Compiler (KCC) Version 4.0d on Sparc Solaris 8 with Sun WorkShop 6 update 2 backend (KCC compiles C++ code to C than uses the Sun compiler to produce machine...
5
by: tkestell | last post by:
Is their anyway to perform mass deletes (several million records) without "maxing out" rollback segments? I'm working on archiving data from an Oracle 8.1.7 database The system is about 4 years...
3
by: Stephen S M WONG | last post by:
As C++ program supports objects with constructors/destructors/methods and data items, I'll assume C++ implementation on segment model computer, like a 80286 with different access restrictions on...
4
by: cppsks | last post by:
I have been working on making a constant array available for the clients. However, it is placing it in the text segment, and external references result in unresolved references to the array. Taking...
2
by: James FitzGerald | last post by:
I am building a small memory model DOS exe (does not actually run in dos but in a custom 16bit environment). For complex reasons I am not allowed to have any relocatable items. I have run into...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
8
by: raghu | last post by:
Can anyone please tell me what are the different segments in a C program? Where can I find more details regarding this? Please help. Merry Christmas and Happy New Year Regards, Raghu
4
by: jesjak | last post by:
hi all, can any one give me some explanation of "wat is .bss segment in object file" and what it will contain and difference between data segment and .bss segment.... help me.... thanks, jes
3
by: madshov | last post by:
Hi, I have the following: <start> <segment Id="AAA"> <element Id="id">1</element> <element Id="seq">122</element> <element Id="seq2" Composite="yes">
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.