0

As far as I understand using the ORG directive in assembly (NASM assembly in particular) and setting the location counter in a linker script to some value perform the same function. However I am wondering that if I use both the org directive and the location counter which will have precedence. For e.g if I have an assembly code beginning with ORG 0x10000 and a linker script beginning with

SECTIONS {
 . = 0xC0000000

which address will the code be linked to ?

Seki
  • 11,135
  • 7
  • 46
  • 70
vjain27
  • 3,514
  • 9
  • 41
  • 60
  • As far as I know, if NASM is told to generate an object file (rather than a flat binary or something), the ORG directive isn't allowed and will cause an error. You can only use ORG for things that don't need linking (where no linker or linker script is involved). – Brendan May 15 '12 at 10:23
  • Try and see. Also check the documentation for your tools (NASM and whatever else you're using). Btw, is there any useful case for doing this? – Alexey Frunze May 15 '12 at 14:49
  • I was looking at the linux kernel source code which uses both a linker script vmlinux.lds and org directive in some of the assembly files. I don't know how the full build takes place but I was just wondering if both could be used somehow. – vjain27 May 15 '12 at 17:04
  • 1
    Unless I'm missing something, it makes no sense to use both, and is probably impossible. However, it does make sense to use one of them for building different binaries and you can (and sometimes it's useful) build one binary and then include it in another binary (as data), in which case you can build both using a different "org", but that by itself doesn't change anything. – Alexey Frunze May 16 '12 at 01:15

0 Answers0