...when I use flat binaries?
PS. Topic title length is limited
Is it necessary to use "section .text"...
Is it necessary to use "section .text"...
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Is it necessary to use "section .text"...
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)
My OS: http://hcos.hardcoder.nazuka.net (Now online, unstable release)
Re: Is it necessary to use "section .text"...
It may be desirable or needed. For example, my C compiler generates assembly output alternating between 2 sections, like this:
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).
Code: Select all
section .text
; some code
section .data
; some data
section .text
; some more code
section .data
; some more data
;...
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).