473,840 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text,data and bss

i just got to know there are three different sections in which we can
divide our program
*Text section
*Data section
*Bss

i think text section contain our code,data section include heap,stack
(?) etc.

Can any body throw light on Bss section...
Nov 16 '08
27 13622
In article <9c************ *************** @TEKSAVVY.COM-Free>,
Lew Pitcher <le*********@di gitalfreehold.c awrote:
>The entire purposes of .bss was to get zero-initialized variables out of
.data. In a sense, it's a compression scheme.
>IIRC, the entire purpose of .bss was to get /uninitialized/ variables out
of .data. To quote "A tour through the Unix C compiler" (D. M. Ritchie,
Bell Laboratories, circa 1979)
"BSS means that subsequent information is to be compiled as uninitialized
static data"
But "unitialise d" static variables are implicitly initialised to zero.
There are no really-uninitialised static variables in C.

Here is a more detailed quote from Ritchie, in the UNIX Assembler
Reference Manual (which I found a copy of at
http://www.tom-yam.or.jp/2238/ref/as.pdf):

The bss segment may not contain any explicitly initialized code or
data. The length of the bss segment (like that of text or data) is
determined by the high-water mark of the location counter within
it. The bss segment is actually an extension of the data segment and
begins immediately after it. At the start of execution of a program,
the bss segment is set to 0. Typically the bss segment is set up by
statements exemplified by

lab:.=.+10

The advantage in using the bss segment for storage that starts
off empty is that the initialization information need not be stored in
the output file.

I think it's clear that references to the bss containing unitialised
variables are meant to imply un-(initialised to non-zero).

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 16 '08 #11
On Sun, 16 Nov 2008 18:47:55 +0000, Richard Tobin wrote:
But "unitialise d" static variables are implicitly initialised to zero.
There are no really-uninitialised static variables in C.
What about the bytes of a union that are not part of the initialised sub-
object?
Nov 16 '08 #12
In article <gf**********@n ews.motzarella. org>,
Harald van Dijk <tr*****@gmail. comwrote:
>But "unitialise d" static variables are implicitly initialised to zero.
There are no really-uninitialised static variables in C.
>What about the bytes of a union that are not part of the initialised sub-
object?
I suppose so. But you could hardly put them in a different section
from the initialised bytes of the union, so there's still no use for
a really-uninitialised section.

-- Richard

--
Please remember to mention me / in tapes you leave behind.
Nov 16 '08 #13
On Sun, 16 Nov 2008 19:02:54 +0000, Richard Tobin wrote:
In article <gf**********@n ews.motzarella. org>, Harald van Dijk
<tr*****@gmail. comwrote:
>>But "unitialise d" static variables are implicitly initialised to zero.
There are no really-uninitialised static variables in C.
>>What about the bytes of a union that are not part of the initialised
sub- object?

I suppose so. But you could hardly put them in a different section from
the initialised bytes of the union, so there's still no use for a
really-uninitialised section.
On systems where pointer types or floating-point types are not initialised
to all-bits zero (which are admittedly uncommon, but real), and the
initialised member of the union is of pointer or floating-point type, it
doesn't make sense to put the union in a zero-initialised section.
Nov 16 '08 #14
In article <gf**********@n ews.motzarella. org>,
Harald van Dijk <tr*****@gmail. comwrote:
>>>But "unitialise d" static variables are implicitly initialised to zero.
There are no really-uninitialised static variables in C.
>>>What about the bytes of a union that are not part of the initialised
sub- object?
>I suppose so. But you could hardly put them in a different section from
the initialised bytes of the union, so there's still no use for a
really-uninitialised section.
>On systems where pointer types or floating-point types are not initialised
to all-bits zero (which are admittedly uncommon, but real), and the
initialised member of the union is of pointer or floating-point type, it
doesn't make sense to put the union in a zero-initialised section.
Quite so. Is there some reason you think I'm disputing that?

If 0.0 is all zeros, then a zero-initialised section can be used
for it. If it's not, then you need something like .data that can
be initialised to any value. Neither case suggests a .bss that is
not initialised at all.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 16 '08 #15
On Sun, 16 Nov 2008 22:27:37 +0000, Richard Tobin wrote:
In article <gf**********@n ews.motzarella. org>, Harald van Dijk
<tr*****@gmail. comwrote:
>>>>But "unitialise d" static variables are implicitly initialised to
zero. There are no really-uninitialised static variables in C.
>>>>What about the bytes of a union that are not part of the initialised
sub- object?
>>I suppose so. But you could hardly put them in a different section
from the initialised bytes of the union, so there's still no use for a
really-uninitialised section.
>>On systems where pointer types or floating-point types are not
initialised to all-bits zero (which are admittedly uncommon, but real),
and the initialised member of the union is of pointer or floating-point
type, it doesn't make sense to put the union in a zero-initialised
section.

Quite so. Is there some reason you think I'm disputing that?

If 0.0 is all zeros, then a zero-initialised section can be used for it.
If it's not, then you need something like .data that can be initialised
to any value. Neither case suggests a .bss that is not initialised at
all.
Oh, sure, initialised to whatever random bytes the compiler happened to
have in memory when laying out the .data section or equivalent is
effectively uninitialised to me.

But depending on the number of bytes, it may be a waste of space to store
them all when there's no need to do so. To use an extreme example:

union {
double d;
char a[1000000];
} u;

Is there a benefit in filling a[sizeof(double)] through a[999999] in the
generated object or at startup? The drawback seems obvious to me.
Especially if u.d needs to be filled in the startup code anyway (let's say
because the system doesn't have a .data section or equivalent), I can
imagine the rest of a being semi-random.
Nov 16 '08 #16
Harald van Dijk wrote:
On Sun, 16 Nov 2008 22:27:37 +0000, Richard Tobin wrote:
>In article <gf**********@n ews.motzarella. org>, Harald van Dijk
<tr*****@gmail .comwrote:
>>On systems where pointer types or floating-point types are not
initialised to all-bits zero (which are admittedly uncommon, but real),
and the initialised member of the union is of pointer or floating-point
type, it doesn't make sense to put the union in a zero-initialised
section.

Quite so. Is there some reason you think I'm disputing that?

If 0.0 is all zeros, then a zero-initialised section can be used for it.
If it's not, then you need something like .data that can be initialised
to any value. Neither case suggests a .bss that is not initialised at
all.

Oh, sure, initialised to whatever random bytes the compiler happened to
have in memory when laying out the .data section or equivalent is
effectively uninitialised to me.
Uh, what? If all-bits-zero (which is what you'd get in .bss) does not
mean 0.0, then the compiler would instead create an entry in .data that
_does_ mean 0.0. There is no initialization to "whatever random bytes
the compiler happened to have in memory"; either way, the variable will
end up being 0.0.

If the OS does not zero-fill the .bss section on creation, then the
compiler must insert code to correct that before execution began,
eliminating any random bytes that might happened to be in memory. If it
didn't, the C implementation would be non-conforming. However, the need
to do this should be rare since giving a program leftover data from
another program can be a serious security hole.

S
Nov 17 '08 #17
On Mon, 17 Nov 2008 00:25:58 -0600, Stephen Sprunk wrote:
Harald van Dijk wrote:
>On Sun, 16 Nov 2008 22:27:37 +0000, Richard Tobin wrote:
>>In article <gf**********@n ews.motzarella. org>, Harald van Dijk
<tr*****@gmai l.comwrote:
On systems where pointer types or floating-point types are not
initialise d to all-bits zero (which are admittedly uncommon, but
real), and the initialised member of the union is of pointer or
floating-point type, it doesn't make sense to put the union in a
zero-initialised section.

Quite so. Is there some reason you think I'm disputing that?

If 0.0 is all zeros, then a zero-initialised section can be used for
it.
If it's not, then you need something like .data that can be
initialised
to any value. Neither case suggests a .bss that is not initialised at
all.

Oh, sure, initialised to whatever random bytes the compiler happened to
have in memory when laying out the .data section or equivalent is
effectively uninitialised to me.

Uh, what? If all-bits-zero (which is what you'd get in .bss) does not
mean 0.0, then the compiler would instead create an entry in .data that
_does_ mean 0.0. There is no initialization to "whatever random bytes
the compiler happened to have in memory"; either way, the variable will
end up being 0.0.
Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.
Nov 17 '08 #18
Harald van Dijk wrote:
On Mon, 17 Nov 2008 00:25:58 -0600, Stephen Sprunk wrote:
>Harald van Dijk wrote:
>>On Sun, 16 Nov 2008 22:27:37 +0000, Richard Tobin wrote:
If 0.0 is all zeros, then a zero-initialised section can be used for
it.
If it's not, then you need something like .data that can be
initialised
to any value. Neither case suggests a .bss that is not initialised at
all.

Oh, sure, initialised to whatever random bytes the compiler happened to
have in memory when laying out the .data section or equivalent is
effectively uninitialised to me.

Uh, what? If all-bits-zero (which is what you'd get in .bss) does not
mean 0.0, then the compiler would instead create an entry in .data that
_does_ mean 0.0. There is no initialization to "whatever random bytes
the compiler happened to have in memory"; either way, the variable will
end up being 0.0.

Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.
In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?

This example could be inefficient if all-bits-zero wasn't 0.0, forcing
the entire union into .data instead of .bss, but I don't think you'd get
"random bytes" in the non-overlapping part of u.x.

S
Nov 17 '08 #19
Stephen Sprunk wrote:
Harald van Dk wrote:
....
Given

union {
double d;
char x[1000];
} u = { 0 };

u.d will be initialised to zero, but I was talking about the bytes that
follow u.d.

In that example, isn't the part of u.x not overlapping with u.d supposed
to be zero-filled as well?
No.
Nov 17 '08 #20

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

Similar topics

9
6841
by: Stephen Saunders | last post by:
Hey Folks, This one currently has me stumped. I have to check for the existence of a carriage return (Enter key, hex 0D) in text data. First I tried: 'Check comment to not contain the CR (13) character For i = 1 To Len(txtComment.Text) On Error GoTo BogusComment2 If Mid(txtComment.Text, i, 1) = CStr(13) Then MsgBox "Comment cannot contain the enter character"
2
1788
by: leegold2 | last post by:
General DB questions, Why do we use null values? Why is it better than an empty field? What would be a real life situation were nulls are important to have? If I have a paragraph of text in a field of data type: TEXT. Can I search in this field? Maybe i mean, could i use SELECT on a table and get rows on the basis of a string or substring in the TEXT field? Thanks,
5
8597
by: adrian | last post by:
hi all this is my first post to this group, so pls bear with me while i try to make some sense. i am trying to create a sproc which uses dynamic sql to target a particuar table eg. '.' and perform some actions. i am using @tableID as a passes parameter for the sproc.
1
1793
by: Ola Theander | last post by:
Dear subscribers I'm currently creating a small application that will run at the end of a web installation to configure a SQL Server. For this task I have a SQL batch file in the same format as SQL Query Analyzer uses. I would prefer not to merge the content of this file into the source code of configuration application but instead keep the SQL commands in a text file included in the executable, pretty much like resource data, for...
9
2362
by: Susan Bricker | last post by:
Greetings. I am having trouble populating text data that represents data in my table. Here's the setup: There is a People Table (name, address, phone, ...) peopleID = autonumber key There is a Judge Table (information about judges) judgeID = autonumber key
6
4784
by: smilly | last post by:
This field is bound to a image data type in SQL server that is used to house big amounts of text how can I output the text data because right now I am getting System.Byte
5
1756
by: sirimanna | last post by:
hello, i'm new to VB...i like to know how to open some text data save in c: in to text box.. i know to save cord's to save data in text box in to c:..but i don't know how to get back that save text data in c: in to vbtext box thank u.
0
1317
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this tyext data into a string. I've got it working just fine, but I have to put the text data into into a fixed-size buffer BEFORE I put it into a string (ConstBufferByteSize=1000000). This fixed size buffer wastes space. Is it possible to somehow assign it straight to a string, or somehow do this 'dynamically' ?
6
5254
by: aagarwal8 | last post by:
Hi, I am trying to write the contents of a textbox to a file in binary format. My code looks like this... private void btnWriteToFile_Click(object sender, EventArgs e) { FileStream fs = File.Open(@"D:\test.dat", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs);
9
5386
by: sillyr | last post by:
Hi - I use Access 2007. I have a two data fields that I would like to add together in a query and then have the query sum the data for the entire table. The problem is that one of the data fields has a data type of number and the other data field has a data type of text. The data filed with the text data type is a combo box with two fields on of which is a number and t he other is text. I tried to use the functions Val and Cint, but am not...
0
10922
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
10603
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10301
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
9440
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 projectplanning, coding, testing, and deploymentwithout 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
7023
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
5685
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4498
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
2
4076
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3138
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.