4

I am beginning to learn to write some low-level software for micro-controllers, and I've started studying linker scripts.

I don't really get the meaning of the ENTRY command in this context. Since most micro-controllers start execution at a predetermined address, what difference does it make which entry point we choose in the linker script?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
josecm
  • 413
  • 3
  • 15

2 Answers2

8

ENTRY() is an ELF feature that basically just sets the program entry address in the ELF header of your executable. This address may differ from the start address of the first executable segment of your binary (which would be the default execution address if you didn't define ENTRY()).

Whether this information is used (i.e. whether start of execution happens at the first code segment address or at ENTRY()) is out of control of the linker as it entirely depends on the availability and features of your ELF loader.

As you usually do not have such thing on a microcontroller, ENTRY() is practically useless there and you might as well omit the statement at no consequence.

mfro
  • 3,286
  • 1
  • 19
  • 28
  • Thank you! That was pretty much the conclusion that I arrived at, but was not sure of it, since in many linker scripts for bare-metal MCU applications I still see the definition of the entry point. – josecm Nov 19 '16 at 10:50
  • Isn't it needed to get a gdb remote extended debug session to allow using "load". I found I needed it for that feature to work (which is pretty convenient for dev). – aselle Feb 26 '18 at 01:19
  • yes and no. The ELF format specifies a load address *and* an entry address. In almost all cases, this will be the same (since most µC start execution with the very first word of flash/ROM anyway). You can then just omit the `ENTRY()' statement. At least for some implementations, gdb can also load binary formats other than ELF (e.g. srec files). In that case, you need to specify the load address manually, however. – mfro Mar 20 '18 at 16:14
1

The entry point defines the starting point of your program. This is of course very good information to have. This way flash tools know where to flash your code and also debug tools know where your symbols are at.

MathiasE
  • 467
  • 3
  • 10
  • I understand it is useful information. However, isn't the whole purpose of the linker script for the tools to know where to flash the code? Specifying the entry point does not alter the starting point of the program if your are programming in a completely bare-metal fashion, or am I missing something? – josecm Nov 15 '16 at 16:16
  • That is correct, linker script cannot, and should not, affect the address where the MCU starts executing code. Linker script dictates how to link the program together and what goes where. That is its main purpose. – MathiasE Nov 15 '16 at 19:02
  • So my question still stands. In this context, is it necessary, or is there some pratical useful reason to define the entry point? – josecm Nov 15 '16 at 22:55
  • I am not sure I understand what you mean. If you do not need to flash nor debug your software, then the entry point would not be needed. Usually this is desired and considered a practical useful reason. Actually, I do not think the entry point is strictly needed, if it is left out, the linker will automatically try and figure out where the entry point is. – MathiasE Nov 16 '16 at 10:59