apache / apache/nuttx

Duplicate symbol problem in nuttx

Open
#12,603 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

When enabling `CONFIG_DEBUG_LINK_WHOLE_ARCHIVE`, building flat mode nuttx with qemu-rv core always failed.

This is the log when building `flats64`
```
[0/1] Re-running _CMake..._
-- Configuring done (0.3s)
-- Generating done (0.2s)
-- Build files have been written to: /mnt/files/test/cache/mainline/nuttx/build
[1251/1252] Linking C executable nuttx
FAILED: nuttx
: && /mnt/files/test/toolchain/riscv-none-elf/bin/riscv-none-elf-gcc -Wl,-melf64lriscv -Wl,--gc-sections -Wl,--whole-archive -nostdlib -Wl,--entry=__start -Wl,--cref -Wl,-Map=nuttx.map CMakeFiles/nuttx.dir/empty.c.obj -o nuttx -Wl,--script=/mnt/files/test/cache/mainline/nuttx/build/ld.script.tmp -Wl,--start-group arch/libarch.a binfmt/libbinfmt.a drivers/libdrivers.a fs/libfs.a libs/libc/libc.a mm/libmm.a sched/libsched.a boards/libboard.a apps/libapps.a apps/builtin/libapps_builtin.a apps/system/nsh/libapps_nsh.a apps/system/nsh/libapps_sh.a apps/testing/getprime/libapps_getprime.a apps/testing/ostest/libapps_ostest.a apps/examples/hello/libapps_hello.a /mnt/files/test/toolchain/riscv-none-elf/bin/../lib/gcc/riscv-none-elf/13.2.0/rv64imafdc_zicsr/lp64d/libgcc.a -Wl,--end-group && :
/mnt/files/test/toolchain/riscv-none-elf/bin/../lib/gcc/riscv-none-elf/13.2.0/../../../../riscv-none-elf/bin/ld: arch/libarch.a(riscv_allocateheap.c.obj): in function `up_allocate_heap':
/mnt/files/test/cache/mainline/nuttx/arch/risc-v/src/common/riscv_allocateheap.c:70: multiple definition of `up_allocate_heap'; arch/libarch.a(qemu_rv_allocateheap.c.obj):/mnt/files/test/cache/mainline/nuttx/arch/risc-v/src/qemu-rv/qemu_rv_allocateheap.c:115: first defined here
/mnt/files/test/toolchain/riscv-none-elf/bin/../lib/gcc/riscv-none-elf/13.2.0/../../../../riscv-none-elf/bin/ld: warning: nuttx has a LOAD segment with RWX permissions
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
```

I have added `weak_function` to the definition of the function `up_allocate_heap` in riscv_allocateheap.c, but it may selected wrong symbol without enabling `CONFIG_DEBUG_LINK_WHOLE_ARCHIVE`. After googling, I found that ld only uses the first matched symbol in the archive (whether it is strong or weak). Is there any suggestion about how to fix this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.