OpenXiangShan / OpenXiangShan/LibCheckpoint
Build Failure on `riscv-linux-gnu-gcc-15` Because of Linking Error
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 4
- Forks
- 2
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
Problem
When building with riscv-linux-gnu-gcc-15, the linking step fails with the following error:
error: PHDR segment not covered by LOAD segment
The makefile uses gcc for the final linking step:
CROSS_COMPILE ?= riscv64-unknown-linux-gnu-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
When adding the --verbose flag to the linking step, part of the output shows:
/usr/lib/gcc/riscv64-linux-gnu/15.1.0/collect2 -plugin /usr/lib/gcc/riscv64-linux-gnu/15.1.0/liblto_plugin.so -plugin-opt=/usr/lib/gcc/riscv64-linux-gnu/15.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccNDDJCY.res --sysroot=/usr/riscv64-linux-gnu --build-id --eh-frame-hdr --hash-style=gnu -melf64lriscv -X -dynamic-linker /lib/ld-linux-riscv64-lp64d.so.1 -pie -o build/gcpt -L/usr/lib/gcc/riscv64-linux-gnu/15.1.0 -L/usr/lib/gcc/riscv64-linux-gnu/15.1.0/../../../../riscv64-linux-gnu/lib -L/usr/riscv64-linux-gnu/lib -L/usr/riscv64-linux-gnu/usr/lib build/obj/src/boot.o build/obj/src/decode_restore.o build/obj/src/gcpt.o build/obj/src/gcpt_trap.o build/obj/src/printf.o build/obj/src/restore.o build/obj/src/trap.o build/obj/src/utils.o build/obj/resource/nanopb/pb_common.o build/obj/resource/nanopb/pb_decode.o build/obj/resource/nanopb/pb_encode.o build/obj/src/checkpoint.pb.o -T restore.lds
/usr/lib/gcc/riscv64-linux-gnu/15.1.0/../../../../riscv64-linux-gnu/bin/ld: build/gcpt: error: PHDR segment not covered by LOAD segment
/usr/lib/gcc/riscv64-linux-gnu/15.1.0/../../../../riscv64-linux-gnu/bin/ld: warning: build/gcpt has a LOAD segment with RWX permissions
The failure occurs because gcc adds unnecessary flags that prevent the files from linking correctly.
Impact of This Problem
This issue causes the CI flow of NEMU to fail in xs-env when using the configuration riscv64-xs-cpt-with-libcheckpoint_defconfig. This configuration depends on LibCheckpoint.
Suggested Fix
Use ld directly in the final linking step to gain explicit control over the linking behavior:
CROSS_COMPILE ?= riscv64-unknown-linux-gnu-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
This fix has been verified to work.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Makefile entries for CC, LD, and the final link command, then inspect restore.lds and the verbose linker output. Verify the change against the riscv64-xs-cpt-with-libcheckpoint_defconfig CI flow in xs-env; done means the configuration links without the PHDR error or RWX warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100