Article Memory : Text, Data, and BSS

Thread Starter

Kittu20

Joined Oct 12, 2022
482
I am reading the content provided in the link below, https://mcuoneclipse.com/2013/04/14/text-data-and-bss-code-and-data-size-explained/

but I'm having trouble understanding the author's aim. All I understand is that memory has been divided into different sections: text, data, and BSS. However, I'm unable to grasp what the author is explaining and the significance behind it.

Can anyone make an guess about what's happening and why it's important?"
 

Papabravo

Joined Feb 24, 2006
21,258
I am reading the content provided in the link below, https://mcuoneclipse.com/2013/04/14/text-data-and-bss-code-and-data-size-explained/

but I'm having trouble understanding the author's aim. All I understand is that memory has been divided into different sections: text, data, and BSS. However, I'm unable to grasp what the author is explaining and the significance behind it.

Can anyone make an guess about what's happening and why it's important?"
Sure. The different sections of memory are for different things:
  1. text is for instructions which will not be subject to change after the program is loaded. If required this section could be place in a ROM (Read Only Memory)
  2. data is for all data with an initial value. The initial values are computed at compile time and when the section is loaded into memory all the locations have their initialized value. This means that code to do this does not have to be part of the program in the "text" space. Just because this data has an initial value, does not mean that the value cannot change at a later time.
  3. BSS is an old assembly language pseudo-operation that stands for Block Starting Symbol. It contains all of the uninitialized data such as the space for a stack or the heap. All the other date in this section can be referenced as an offset from the symbol defined to be at the start of the block.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
482
Sure. The different sections of memory are for different things:
  1. text is for instructions which will not be subject to change after the program is loaded. If required this section could be place in a ROM (Read Only Memory)
  2. data is for all data with an initial value. The initial values are computed at compile time and when the section is loaded into memory all the locations have their initialized value. This means that code to do this does not have to be part of the program in the "text" space. Just because this data has an initial value, does not mean that the value cannot change at a later time.
  3. BSS is an old assembly language pseudo-operation that stands for Block Starting Symbol. It contains all of the uninitialized data such as the space for a stack or the heap. All the other date in this section can be referenced as an offset from the symbol defined to be at the start of the block.
You've explained the sections of C memory layout such as text, data, and BSS.

However, my main question was whether the author is explaining how developers can analyze code size information to reduce memory usage and improve performance.
 

Papabravo

Joined Feb 24, 2006
21,258
You've explained the sections of C memory layout such as text, data, and BSS.

However, my main question was whether the author is explaining how developers can analyze code size information to reduce memory usage and improve performance.
I don't think the division of memory into sections has anything to do with performance or minimal memory usage.
 

ApacheKid

Joined Jan 12, 2015
1,658
I developed a compiler that ran on Windows NT, in the early 90s. That entailed having to intimately understand the structure of OBJ and DLL files in Windows NT, this was my reference, I printed it out and read over and over, scribbling notes on many of the pages, its a very well written reference document.

https://courses.cs.washington.edu/courses/cse378/03wi/lectures/LinkerFiles/coff.pdf

COFF, ELF and PE are very closely related and all originate from the Unix original COFF structure. My advice is to study that document and return here if you have specific question, you wont encounter many people wrote a COFF generator API and I'm happy to help if you have a genuine interest.

Here's some source for you too, part of that compiler I referred to:

https://github.com/Steadsoft/PLI-2000/blob/main/Compiler Source/COFF.H

https://github.com/Steadsoft/PLI-2000/blob/main/Compiler Source/Cofflib.c
 
Last edited:

Thread Starter

Kittu20

Joined Oct 12, 2022
482
I don't think the division of memory into sections has anything to do with performance or minimal memory usage.
As far as I understand, the writer has shown the size of different sections of memory layout, such as text, data, and bss, using the size command. If there are modifications in the program, then different sizes will be shown in the output
 

Papabravo

Joined Feb 24, 2006
21,258
As far as I understand, the writer has shown the size of different sections of memory layout, such as text, data, and bss, using the size command. If there are modifications in the program, then different sizes will be shown in the output
What does that have to do with performance? Generally speaking, designs are no longer memory limited as they were 50 years ago.
 
Top