[riot-notifications] [RIOT-OS/RIOT] riscv_common: mark handle_trap as used (fixes LTO on RISC-V) (#16449)

nmeum notifications at github.com
Wed May 5 13:51:28 CEST 2021

### Contribution description

The handle_trap function is used internally by the trap_entry implementation from the same file. However, the trap_entry implementation calls handle_trap from inline assembly. This makes it difficult for the compiler to infer that the handle_trap function is used at all. This causes issues when LTO is enabled.

Without this patch compiling any RISC-V RIOT code with `LTO=1` causes the following linker error:

	RIOT/cpu/riscv_common/irq_arch.c:134: undefined reference to `handle_trap'
	/tmp/hello-world.elf.Nngidp.ltrans0.ltrans.o:cpu/riscv_common/irq_arch.c:134:(.text.trap_entry+0x34):relocation truncated to fit: R_RISCV_GPREL_I against undefined symbol `handle_trap'

This commit fixes LTO support for RISC-V.

### Testing procedure

Try compiling `examples/hello-world` with and without this patch as follows:

$ LTO=1 BOARD=hifive1 make -C examples/hello-world/

Without this PR compilation should fail with the error message from above, with it a functioning LTO binary should be produced.

### Issues/PRs references


You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * riscv_common: explicitly mark handle_trap as used

-- File Changes --

    M cpu/riscv_common/irq_arch.c (2)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210505/80a8c098/attachment.htm>

More information about the notifications mailing list