Hello,
I would like to ask for help regarding the build process. It seems to
be
ignoring functions defined in a source code file for some reason and I
can't figure it out.
I am attempting to reimplement up_udelay for AVR, so I created file
arch/avr/src/avrdx/avrdx_delay.c . To my understanding, since the
function is defined as weak in sched/clock/clock_delay.c , the only
thing needed is to define another function with the same name and it
will override the weak one. I also added CHIP_CSRCS += avrdx_delay.c
to
arch/avr/src/avrdx/Make.defs . Tried to build everything, build
succeeded but - looking at the disassembly - the original
implementation
was used.
So then I started experimenting:
1. I tried if the source file avrdx_delay.c is actually being compiled
by adding #error test . The compiler issued an error, as expected.
2. I tried to remove weak attribute from up_udelay in clock_delay.c to
force "multiple definition" error in linking step to verify that my
code
is getting to the linker. No error though, build completed.
3. I also tried to force the same error with different function,
randomly picked nxtask_start and added a dummy implementation of it to
avrdx_delay.c. Still no error.
4. Still thinking there may be something wrong with the new file, I
moved my implementation of nxtask_start to already existing and
relatively well-tested arch/avr/src/avrdx/avrdx_serial.c . The build
failed, multiple definition of `nxtask_init' (finally)
5. I then put my implementation of up_udelay to avrdx_serial.c (and
removed nxtask_init from there.) The build succeeded and up_udelay
used
my implementation.
6. Now the really strange part (for me at least) - I added
somerandomfunc() to avrdx_delay.c and called it from my application.
Attempted to build and it failed because multiple definition of
nxtask_init which was left there from previous experiments. To verify,
I
kept somerandomfunc in avrdx_delay.c but removed the call to it from
my
application. The build succeeded. I added the call to somerandomfunc
back to the application, got build error again.
So now I am at loss. From what I see, the linker is ignoring duplicate
functions in an source code/object file unless the file also contains
a
function that is not a duplicate and that is actually called from
somewhere.
Could anyone shed some light on this? I am out of my league here
unfortunately. Did some web search, found --whole-archive flag for the
linker but experimenting with it led to nowhere (couldn't even make it
to work, makes the build fail because linker then finds duplicates
between libgcc and NuttX code and even within libgcc itself.)
Tested with avr-gcc 14.2 and 5.4