0

I'm linking a program with 2 assembly files.

How can I force the program to put some code of the first file before some code of the second file (in this pseudocode snippet, I want the instructions to be called from 0 to 5)?

#file a
do_this:
   inst 1
   inst 2

do_that:
   inst 3
   inst 4

#file b
no_no_do_this_first:
   inst 0

and_do_this_finally:
   inst 5

using sections?

Is there another way?

Ok, after reading some more I found that as I'm compiling with C, this answer might apply: https://stackoverflow.com/a/54584294/10734452

But currently my files are: crt0_generic , crt0_customerA

or crt0_generic , crt0_customerB

and I need some function of the crt0_generic to be called first

Guillaume D
  • 2,202
  • 2
  • 10
  • 37
  • 1
    What environment? For non-flat binaries you typically have an entry point specified via label so it does not matter what comes first. – Jester Jan 19 '23 at 16:08
  • how to define this label? (i'm cross compiling for riscv) – Guillaume D Jan 19 '23 at 16:09
  • It's normally called `_start` on unix-like systems. Your linker should have complained if it was missing. – Jester Jan 19 '23 at 16:11
  • i edited my question because It cannot be as generic as I wanted, as I'm compiling assembly with C – Guillaume D Jan 19 '23 at 16:14
  • If I want the 'reset' label to be called before the '_start' label, how could I do? – Guillaume D Jan 19 '23 at 16:16
  • 1
    You can tell the linker to use your `reset` as entry point but then make sure you transfer control to `_start` after you are done (with the proper register and stack state). – Jester Jan 19 '23 at 16:18
  • The above only applies if you are creating normal user mode program running under an OS with a standard loader of course. If you are trying to do bare metal, with stuff having to be put in specific places you likely need linker scripts. – Jester Jan 19 '23 at 16:39

0 Answers0