how to get rid of c-startup file?

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

I try to compile a bootloader with avr-gcc4.2.2. With avr-gcc 3.4.6 the linker command

avr-gcc -mmcu=atmega128 -Wl,-nostdlib,-Map,bootloader.map,--section-start=text=0x7000,--cref,-e,start -o bootloader.elf start.o boot.o

worked fine. With 4.2.2 and binutils 2.18 I always get the error message

gcrt1.S:124: undefined reference to `main'

.
I also extended the linker command to

-Wl,-nostdlib,-Map,bootloader.map,--section-start=text=0x7000,--cref,-e,start,-nostartfiles

without sucess. Any idea?

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

Any function called 'main' anywhere?

I'm not sure what -nostdlib actually does, so it may be useless, I don't know (it seems to not matter, as it still pulls in stuff from libgcc.a if needed).

Using -nostartfiles should get rid of the error, as it will get rid of the startup code in .init9 that calls(or jmp's) to main. But I'm not sure it works when that option follows -Wl as you do. My automatically generated makefile (by avr studio) puts the -nostartfiles before the -Wl options (so it is a 'direct' linker option, not passed). Or something.

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

curtvm wrote:
Any function called 'main' anywhere?

No

curtvm wrote:
Using -nostartfiles should get rid of the error, as it will get rid of the startup code in .init9 that calls(or jmp's) to main. But I'm not sure it works when that option follows -Wl as you do. My automatically generated makefile (by avr studio) puts the -nostartfiles before the -Wl options (so it is a 'direct' linker option, not passed). Or something.
That's the point! It is a gcc parameter and not a ld parameter.
With a good trigger like your's RTFM makes sense :D
Thank's for help
Knut

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

knut wrote:
curtvm wrote:
Any function called 'main' anywhere?

No
This is the problem with separately compiling the boot -- the main routine of the boot must be called main(). After all, you're trying to compile the boot as a separate app. That means there must be a main() somewhere. That's all that is going on here.

Try changing the name of your main boot routine to main() and see what happens.

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

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

stu_san wrote:
This is the problem with separately compiling the boot -- the main routine of the boot must be called main(). After all, you're trying to compile the boot as a separate app. That means there must be a main() somewhere. That's all that is going on here.

Try changing the name of your main boot routine to main() and see what happens.

Stu


Stu,
yes and no :)
Yes if you want the whole C startup code to be around - int-vect, ....
No, if you want to use the whole bootloader area for your own purpose.
The latter of course needs to be explained in detail to the tool-chain. Precaution to start the app properly has to been take ( like "-e start" ... ) and of course you can't rely on cleared variables in your code. The bootloader was/is working now as expected.

Moving the paramater from the linker to the gcc part of the command works fine.
Knut