Is it necessary to use "section .text"...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Is it necessary to use "section .text"...

Post by Roman »

...when I use flat binaries?

PS. Topic title length is limited :(
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
DVicthor
Posts: 11
Joined: Sat Oct 12, 2013 10:23 am

Re: Is it necessary to use "section .text"...

Post by DVicthor »

Not really, unless you're using ld and want to know the exact position of each segment/section.
Life is a test. Endure, live righteously so that you may rest in eternal peace. Oh, and while coding, don't let the code bugs byte.
My OS: http://hcos.hardcoder.nazuka.net (Now online, unstable release)
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Is it necessary to use "section .text"...

Post by alexfru »

It may be desirable or needed. For example, my C compiler generates assembly output alternating between 2 sections, like this:

Code: Select all

section .text
; some code

section .data
; some data

section .text
; some more code

section .data
; some more data

;...
Btw, sometimes it may be handy to be able to organize hand-written code like this.

This output is then fed into NASM.

And NASM can combine all pieces of .text into a single continuous .text section (ditto for .data) irrespective of the output format being object (ELF/COFF/etc) or raw/flat binary (NASM can produce flat binary output directly without a linker).

AFAIR, FASM, OTOH, cannot do this. And so, if my compiler were to be used with something like FASM, it would need to generate code differently (e.g. accumulate .text and .data internally before outputting them) or insert jump instructions to jump over pieces of .data (specifically for this case I now have an option that produces assembly output without sections but with these jumps).
Post Reply