Code segment

Portion of an object file containing executable instructions


title: "Code segment" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["executable-file-formats", "memory-management"] description: "Portion of an object file containing executable instructions" topic_path: "technology/operating-systems" source: "https://en.wikipedia.org/wiki/Code_segment" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Portion of an object file containing executable instructions ::

::figure[src="https://upload.wikimedia.org/wikipedia/commons/9/96/Program_memory_layout.svg" caption="heap]] sections."] ::

In computing, a code segment, also known as a text segment or simply as text, is a portion of an object file or the corresponding section of the program's virtual address space that contains executable instructions.{{Cite web | url = http://www.cs.uwm.edu/classes/cs315/Bacon/Lecture/HTML/ch10s04.html | title = Chapter 10. Subprogram Calls and the Stack | at = Section 10.4. Memory Segments | date = 2012-03-13 | accessdate = 2014-05-02 | author = Jason W. Bacon | website = cs.uwm.edu | archive-date = 2014-05-02 | archive-url = https://web.archive.org/web/20140502115622/http://www.cs.uwm.edu/classes/cs315/Bacon/Lecture/HTML/ch10s04.html | url-status = dead

Segment

The term "segment" comes from the memory segment, which is a historical approach to memory management that has been succeeded by paging. When a program is stored in an object file, the code segment is a part of this file; when the loader places a program into memory so that it may be executed, various memory regions are allocated (in particular, as pages), corresponding to both the segments in the object files and to segments only needed at run time. For example, the code segment of an object file is loaded into a corresponding code segment in memory.

The code segment in memory is typically read-only and has a fixed size, so on embedded systems it can usually be placed in read-only memory (ROM), without the need for loading. If the code segment is not read-only, then the particular architecture allows self-modifying code. Fixed-position or position-independent code may be shared in memory by several processes in segmented or paged memory systems.{{Cite web | url = http://www.beingdeveloper.com/memory-layout-of-a-program/ | title = Code Segment and Data Segment: Memory Layout of a Program | date = 2012-09-20 | accessdate = 2014-05-02 | author = Kai Wang | website = beingdeveloper.com | archive-date = 2014-05-02 | archive-url = https://web.archive.org/web/20140502121214/http://www.beingdeveloper.com/memory-layout-of-a-program/ | url-status = dead | doi = 10.1109/ISCIT.2005.1567023 | title = Buffer overflow protection based on adjusting code segment limit | conference = IEEE International Symposium on Communications and Information Technology | date = October 2005 | author1 = Yu-An Tan | author2 = Ji-yan Zheng | author3 = Yuan-Da Cao | author4 = Xue-lan Zhang | publisher = IEEE

References

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

executable-file-formatsmemory-management