1

This question is partially answered here but they don't help with generating elf file with ORG directive when you are obliged to use it.

I need a way to combine nasm use and ORG directive to produce an equivalent Elf file. This is how I proceed now:

nasm -f elf64 -F dwarf -g Main.s -o Main.elf  

but nasm keeps rejecting it because of my necessary ORG.

Godo
  • 48
  • 5
  • `org` directives really do not make a lot of sense with ELF. What are you trying to achieve? Can you show us your code? – fuz Mar 19 '18 at 11:46
  • 3
    Org applies to the -f bin` option. If you want to set an origin point you'll have to use a linker script or override the linker command line with something like -Ttext=0xNNNNNNNN where NNNNNNNN is the origin point of the code. – Michael Petch Mar 19 '18 at 11:48
  • Is this for a kernel / OSDev? – Michael Petch Mar 19 '18 at 11:50
  • yes. It is from a piece of code from OSDev. Thank you @MichaelPetch, it is exactly what I am looking for – Godo Mar 23 '18 at 17:47

1 Answers1

3

This is to give a precise solution to your problem, in case others would be in the same situation:

If you want to set your binary origin to 0x7c00 (as in common kernel boot-loader)

ld -Ttext=0x7c00 --oformat binary -o Main.bin Main.elf
Mahouk
  • 902
  • 9
  • 28