Page 1 of 1

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

Posted: Thu Jul 03, 2014 9:11 am
by Roman
...when I use flat binaries?

PS. Topic title length is limited :(

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

Posted: Thu Jul 03, 2014 12:14 pm
by DVicthor
Not really, unless you're using ld and want to know the exact position of each segment/section.

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

Posted: Thu Jul 03, 2014 12:52 pm
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).