Failed to Compile a bare metal code at 0x80000000

546 views
Skip to first unread message

Vinod Ganesan

unread,
Aug 9, 2018, 8:36:19 AM8/9/18
to RISC-V SW Dev
Hi, 
    I am trying to compile a code at 0x80000000 but the linking part fails with the following error. 

/home/vinod/tools/riscv/bin/../lib/gcc/riscv64-unknown-elf/7.2.0/../../../../riscv64-unknown-elf/lib/libm.a(lib_a-s_floor.o): In function `floor':


s_floor.c:(.text+0x30): relocation truncated to fit: R_RISCV_HI20 against `.LC0'


/home/vinod/tools/riscv/bin/../lib/gcc/riscv64-unknown-elf/7.2.0/../../../../riscv64-unknown-elf/bin/ld: final link failed: Symbol needs debug section which does not exist


I see this failure whenever the software includes math.h. I have been circumventing this problem till now by changing the starting address of the processor to elsewhere (say 0x1000000) and the compilation works fine. So I guess it had something to do with RISC-V code models but unfortunately this error doesn't get resolved even when I set my mcodel to medany.

Does this error have something to do with RISC-V Code models? Can I circumvent this error by adding something in the linker-script? I am using the Vanilla linker-script from RISC-V tests repository (https://github.com/riscv/riscv-tests/blob/master/benchmarks/common/test.ld).  

I see a similar issue in the issues of RISC-V tests (https://github.com/riscv/riscv-tests/issues/145).

Is there a known fix for this? Please let me know.



Regards
Vinod

Tommy Murphy

unread,
Aug 9, 2018, 8:48:34 AM8/9/18
to RISC-V SW Dev
You haven't attached a full log of your compilation to show the command line options used etc.
That makes it more difficult to suggest solutions.
However does adding -mcmodel=medany to the compile/link commands make any difference?

etc...

Vinod Ganesan

unread,
Aug 9, 2018, 9:37:45 AM8/9/18
to RISC-V SW Dev

Hi Tommy, 
  Sorry for the ambiguity. Please find the compilation flags used. I tried -mcmodel=medany as I had mentioned in my previous mail. Didn't help. I use similar crt.S and syscalls.c files as is provided in the riscv-tests repository.

 riscv64-unknown-elf-gcc -w -g -mcmodel=medany -static -std=gnu99 -fno-builtin-printf -c paranoia.c -o paranoia.o
 riscv64-unknown-elf-gcc -march=rv64imafd  -mcmodel=medany -static -std=gnu99 -fno-common -fno-builtin-printf -D__ASSEMBLY__=1 -c crt.S -o crt.o
 riscv64-unknown-elf-gcc -march=rv64imafd  -mcmodel=medany -static -std=gnu99 -fno-common -fno-builtin-printf  -c syscalls.c -o syscalls.shakti
 riscv64-unknown-elf-gcc -T ./link.ld paranoia.o crt.o syscalls.shakti -o paranoia.elf -static -nostartfiles -lm -lgcc

I have attached the link.ld as well for your reference. The source code I am trying to compile at 0x80000000 can be found here. I am reiterating the fact that the code compiles perfectly for a start address of 0x20000 or 0x1000000. I tried using -fPIC flag as suggested by my friend, that didn't help as well.



Regards
Vinod
link.ld

Tommy Murphy

unread,
Aug 9, 2018, 9:40:36 AM8/9/18
to RISC-V SW Dev
Try -mcmodel=medany in the link line too.

Vinod Ganesan

unread,
Aug 9, 2018, 9:50:04 AM8/9/18
to RISC-V SW Dev
Hi Tommy,
         That doesn't help. Still the same error.


Regards
Vinod

Andreas Schwab

unread,
Aug 9, 2018, 9:52:28 AM8/9/18
to Vinod Ganesan, RISC-V SW Dev
On Aug 09 2018, Vinod Ganesan <g.vin...@gmail.com> wrote:

> /home/vinod/tools/riscv/bin/../lib/gcc/riscv64-unknown-elf/7.2.0
> /../../../../riscv64-unknown-elf/lib/libm.a(lib_a-s_floor.o): In function
> `floor':
>
> s_floor.c:(.text+0x30): relocation truncated to fit: R_RISCV_HI20 against `.
> LC0'

How did you compile libm.a? I'd guess it needs to be recompiled with
the same code model.

Andreas.

--
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

Jim Wilson

unread,
Aug 9, 2018, 10:43:37 AM8/9/18
to Andreas Schwab, Vinod Ganesan, RISC-V SW Dev
On Thu, Aug 9, 2018 at 6:52 AM, Andreas Schwab <sch...@suse.de> wrote:
> On Aug 09 2018, Vinod Ganesan <g.vin...@gmail.com> wrote:
>
>> /home/vinod/tools/riscv/bin/../lib/gcc/riscv64-unknown-elf/7.2.0
>> /../../../../riscv64-unknown-elf/lib/libm.a(lib_a-s_floor.o): In function
>> `floor':
>>
>> s_floor.c:(.text+0x30): relocation truncated to fit: R_RISCV_HI20 against `.
>> LC0'
>
> How did you compile libm.a? I'd guess it needs to be recompiled with
> the same code model.

With riscv-gnu-toolchain, you can use --with-cmodel=medany to
configure a compiler that uses medany by default. That will give you
libraries built with medany. Otherwise, medlow is the default.

The elf and linux compilers don't have multilib support for code
models though, so that isn't a possible solution.

Jim
Reply all
Reply to author
Forward
0 new messages