.initN section in an .a file

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have written a library implementing HEAP functionality 200 bytes long.
The library consists of two functions and one initialization routine: malloc, free, and init.

I have defined init like

.section .init3, "ax", @progbits
INIT CODE HERE

How can I make it be linked to the app using this library whenever malloc, or free is used? or make it link every time?

Right now if I include the .S file containing the initialization routine, the init code gets into the right place (before main), but if I include the library, it just ignores it. (Doesn't get copied to the .text section. What Can I do?

Thanks,
axos88

axos88

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The usual thing: library modules (that is, an entire object module, i.e.
everything that's compiled from a single source file, or rather
"translation unit" in terms of the standard) will be considered by the
linker if (and only if) they resolve an undefined external symbol. So
if you want to link something that's otherwise not referenced at all,
you could force that by using the linker's -u option which produces an
undefined external symbol beforehand.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But avr-libc manages doing this (includes the crt1.S, with the stack initialization, vectors, and stuff like that. ?...

axos88

axos88

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The crtXXX.o file is always explicitly linked by the compiler driver.
It is *not* taken out of a library, btw.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh... So the only way is to use the -u option.

Thanks

EDIT:
Isn't there a way to make a function "appear to use" a symbol, just to make it link into the binary?

Some kind of assembly directive, or sthg?

axos88

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you really *have* to use it. Usually, placing the initialization
function in the same module as the actual stuff, and then calling the
init function from main() does the trick, but I see that you are trying
to *just* place the init function there. That wouldn't work that way.

You are aware that your only saving is about a CALL and a RET but not
much more, are you? Not sure whether this is worth burning several hours
to find another solution...

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah... I know that, but uh... I'm a curious guy :) My bad :D

axos88