Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate symbol problem in nuttx #12603

Open
inochisa opened this issue Jul 1, 2024 · 7 comments
Open

Duplicate symbol problem in nuttx #12603

inochisa opened this issue Jul 1, 2024 · 7 comments

Comments

@inochisa
Copy link
Contributor

inochisa commented Jul 1, 2024

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?

@acassis
Copy link
Contributor

acassis commented Jul 1, 2024

@lupyuen any idea?

@lupyuen
Copy link
Member

lupyuen commented Jul 1, 2024

@acassis Sorry I'm not sure how we might fix this

@inochisa
Copy link
Contributor Author

inochisa commented Jul 5, 2024

@lupyuen Is it possible to always enable "--whole-archive" for all library? As DEBUG_OPT_UNUSED_SECTIONS is enabled by default, it may have no change for the final binary.

@lupyuen
Copy link
Member

lupyuen commented Jul 5, 2024

Is it possible to always enable "--whole-archive" for all library? As DEBUG_OPT_UNUSED_SECTIONS is enabled by default, it may have no change for the final binary.

@xiaoxiang781216 and @tmedicci would you know about "--whole-archive" and DEBUG_OPT_UNUSED_SECTIONS? Sorry I'm not sure about this.

@inochisa
Copy link
Contributor Author

inochisa commented Jul 5, 2024

It seems that only using --whole-archive" for kernel library is better idea. I found an example in zephyr.

https://github.com/zephyrproject-rtos/zephyr/blob/main/cmake/linker/ld/target.cmake#L127-L143

@xiaoxiang781216
Copy link
Contributor

Is it possible to always enable "--whole-archive" for all library? As DEBUG_OPT_UNUSED_SECTIONS is enabled by default, it may have no change for the final binary.

@xiaoxiang781216 and @tmedicci would you know about "--whole-archive" and DEBUG_OPT_UNUSED_SECTIONS? Sorry I'm not sure about this.

--whole-archive will pack all library into one before linking.

@inochisa
Copy link
Contributor Author

inochisa commented Jul 5, 2024

Is it possible to always enable "--whole-archive" for all library? As DEBUG_OPT_UNUSED_SECTIONS is enabled by default, it may have no change for the final binary.

@xiaoxiang781216 and @tmedicci would you know about "--whole-archive" and DEBUG_OPT_UNUSED_SECTIONS? Sorry I'm not sure about this.

--whole-archive will pack all library into one before linking.

The man says it changes the symbol searching, not packing archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants