Question about ld's symbol resolution

Alan Modra amodra@gmail.com
Wed Jun 17 03:35:07 GMT 2020


On Tue, Jun 16, 2020 at 05:20:14PM -0700, A Wang via Binutils wrote:
> arm-none-eabi-gcc -g -Os -mthumb -mcpu=cortex-m4 -ffunction-sections
> -fdata-sections --specs=nano.specs --specs=nosys.specs -Wl,--gc-sections -o
> main.elf -Wl,--start-group main.a _my_write.a -lc -Wl,--end-group
> 
> If newlib (-lc) referenced a new symbol, the symbol will be added to the
> list of undefined references. Would the linker start searching for this new
> undefined reference from the beginning of the library list? Or would it
> continue searching through libc's object files from the point where it
> found the new reference? For example, libc_nano.a's lib_a-stdio.o
> references `_write`, should the linker choose the definition of `_write`
> from `_my_write.a` since it comes before libc in the linked library order?

If the new undefined reference comes from an object file extracted
from libc.a, the linker will continue searching libc.a as it would
usually do without the addition of --start-group/--end-group to the
command line.  You can imagine that the linker command line is
... -o main.elf main.a _my_write.a -lc main.a _my_write.a -lc
 main.a_my_write.a -lc ...
with the part between --start-group/--end-group repeated as much as
necessary to resolve circular references.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list