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.

4
  • org directives really do not make a lot of sense with ELF. What are you trying to achieve? Can you show us your code? Commented Mar 19, 2018 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. Commented Mar 19, 2018 at 11:48
  • Is this for a kernel / OSDev? Commented Mar 19, 2018 at 11:50
  • yes. It is from a piece of code from OSDev. Thank you @MichaelPetch, it is exactly what I am looking for Commented Mar 23, 2018 at 17:47

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.