avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem linking *without* avr-libc, libm, etc.


From: dvalin
Subject: Re: Problem linking *without* avr-libc, libm, etc.
Date: Fri, 30 Apr 2021 19:22:40 +0930


On 30.04.21 10:03, David Brown wrote:
> On 29/04/2021 21:43, Ian Molton wrote:
> > Hi,
> >
> > I'm attempting to build my project, which does not use libc, or libm,
> > but I do want to link with libgcc.
> >
> > additionally, I don't want any startup code to be linked - the project
> > is intended to be fully standalone.
> >
>
> If you don't use any functions from these libraries, nothing from them
> will be linked into your project - it doesn't matter if the linker has them.

Still dabbling a little with AVR once in a while, I add -nostartfiles to
Ian's -nostdlib, to avoid startup code. As my most recent dabble is
-mmcu=attiny2313, with only 1k instructions, any extraneous code bytes
would quickly be noticed.

As for libm, I've always had to -lm that explicitly when needed.

And for libgcc, my makefile remembers better than I, a choice to use
avr-gcc, not just avr-ld for linking on a project which needed libgcc.
That residual choice in the attiny2313 project confirms David's reminder
that stuff is only linked if you use it.

Erik

makefile:
=========
# vim:noexpandtab list foldmethod=manual

INC_DIR=include
OBJDIR=obj

CC = avr-gcc
CFLAGS = -g -O2 -nostartfiles -nostdlib -mmcu=attiny2313 -DMCU=attiny2313
AS = /usr/local/avr/bin/avr-as
ASFLAGS = -gstabs -mmcu=attiny2313
LD = /usr/local/avr/bin/avr-ld

# Let avr-gcc link, so it can find libgcc.a:
LDFLAGS = -Wl,-M

.SUFFIXES :
.SUFFIXES : .c .h .o .s .S

%.o: %.c
   $(CC) -c $(CFLAGS) -o $(OBJDIR)/$@ $<

%.o: %.s
   $(AS) -I$(INC_DIR) $(ASFLAGS) -o $(OBJDIR)/$@ $<

%.o: %.S
   $(CC) -c -I$(INC_DIR) -x assembler-with-cpp $(CFLAGS) -Wa,-alms=$(OBJDIR)/$@.lst -o $(OBJDIR)/$@ $<

dimmer:  init.o os.o timer.o lamps.o eepromo serial.o comms.o
      ( cd $(OBJDIR) ; $(CC) $(LDFLAGS) $(CFLAGS) -o $@.elf $^ > map )
      avr-objcopy -O srec obj/dimmer.elf -S -R .eeprom --gap-fill=0xff obj/flash.srec
      avr-objcopy -O ihex obj/dimmer.elf -S -j .eeprom --gap-fill=0xff obj/eeprom.ihex
      avr-objdump -D obj/$@.elf > obj/dimmer.dump

load:
      avrdude -P /dev/ttyUSB0 -p t2313 -c stk500 -e -U flash:w:obj/flash.srec \
                                                    -U eeprom:w:obj/eeprom.ihex

reply via email to

[Prev in Thread] Current Thread [Next in Thread]