Link order of objects / Linker script

OP #1174731
Is it "normal" to have to specify the order of .o files when linking?

I have just encountered some sample code where the ARM startup assembly
code object file must be first in the list of files to be linked.  (If
not, the code will not run.)  Other sample code doesn't seem to care
what order the files are linked.

Is is a function if the linker script to tell the linker where to put
certain object files?
Moderator
Joe Dupre wrote:
> Is it "normal" to have to specify the order of .o files when linking?
The order has an impact but it's usually not a good idea to create code
that depends on the order. Usage of libraries (.a-files) might be
excpetion in certain scenarios. Are there any weak
defintions/attributes? Are symbols used in the startup-code which are
also used in other files?

> I have just encountered some sample code where the ARM startup assembly
> code object file must be first in the list of files to be linked.  (If
> not, the code will not run.)  Other sample code doesn't seem to care
> what order the files are linked.
Please check the map-files for the both cases, you should see
differences esp. in the cross-reference. If you have difficulties to
interpret them you can pack the two map-files into a zip-file and attach
it to a message. Maybe the readers of the forum can help. Without a
little more information it's difficult to help.

> Is is a function if the linker script to tell the linker where to put
> certain object files?
This is somehow possible but it's not a "where to put object files" but
where to put the sections defined in the object file.
OP
> The order has an impact but it's usually not a good idea to create code
> that depends on the order.


The problem was that the arm boot code, including the reset handler, was
assigned to the .text section, not the .startup section.  Therefore if
bootcode.s was linked first, everything was fine.  (I thought the ENTRY
declaration would handle this, but apparently not.)

[I had converted the project from a make project to an eclipse project,
so the linker object order got re-arranged.]

Reply

A question of your own? This thread is over 17 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.