Hello,

I try to build a 64-bit RISC-V tool chain for RTEMS. RTEMS doesn't use virtual memory. The reference chips for 64-bit RISC-V such as FU540-C000 locate the RAM at 0x8000_0000. This forces me to use -mcmodel=medany in 64-bit mode. The ctrbegin.o contains this code (via crtstuff.c):

extern void *__deregister_frame_info (const void *)
         __attribute__ ((weak));
...
# 370 "libgcc/crtstuff.c"
static void __attribute__((used))
__do_global_dtors_aux (void)
{
  static _Bool completed;

  if (__builtin_expect (completed, 0))
    return;
# 413 "libgcc/crtstuff.c"
  deregister_tm_clones ();
# 423 "libgcc/crtstuff.c"
  if (__deregister_frame_info)
    __deregister_frame_info (__EH_FRAME_BEGIN__);



  completed = 1;
}

Which is:

    .text
    .align    1
    .type    __do_global_dtors_aux, @function
__do_global_dtors_aux:
    lbu    a5,completed.3298
    bnez    a5,.L22
    addi    sp,sp,-16
    sd    ra,8(sp)
    call    deregister_tm_clones
    lla    a5,__deregister_frame_info
    beqz    a5,.L17
    lla    a0,__EH_FRAME_BEGIN__
    call    __deregister_frame_info
.L17:
    ld    ra,8(sp)
    li    a5,1
    sb    a5,completed.3298,a4
    addi    sp,sp,16
    jr    ra
.L22:
    ret

If I link an executable I get this:

/opt/rtems/5/lib64/gcc/riscv64-rtems5/9.0.0/../../../../riscv64-rtems5/bin/ld: /opt/rtems/5/lib64/gcc/riscv64-rtems5/9.0.0/crtbegin.o: in function `.L0 ': crtstuff.c:(.text+0x72): relocation truncated to fit: R_RISCV_CALL against undefined symbol `__deregister_frame_info'

I guess, that the resolution of the weak reference to the undefined symbol __deregister_frame_info somehow sets __deregister_frame_info to the absolute address 0 which is illegal in the following "call __deregister_frame_info"? Is this construct with weak references and a -mcmodel=medany supported on RISC-V at all?

If I change crtstuff.c like this using weak function definitions

diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index 5e894455e16..770e3420c92 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -177,13 +177,24 @@ call_ ## FUNC (void)                                      \

 /* References to __register_frame_info and __deregister_frame_info should
    be weak in this file if at all possible.  */
-extern void __register_frame_info (const void *, struct object *)
-                                 TARGET_ATTRIBUTE_WEAK;
+extern void __register_frame_info (const void *, struct object *) ;
+TARGET_ATTRIBUTE_WEAK void __register_frame_info (const void *unused, struct object *unused2)
+{
+       (void)unused;
+       (void)unused2;
+}
+
 extern void __register_frame_info_bases (const void *, struct object *,
                                         void *, void *)
                                  TARGET_ATTRIBUTE_WEAK;
-extern void *__deregister_frame_info (const void *)
- TARGET_ATTRIBUTE_WEAK;
+
+extern void *__deregister_frame_info (const void *);
+TARGET_ATTRIBUTE_WEAK void *__deregister_frame_info (const void *unused)
+{
+       (void)unused;
+       return 0;
+}
+
 extern void *__deregister_frame_info_bases (const void *)
TARGET_ATTRIBUTE_WEAK;
 extern void __do_global_ctors_1 (void);

then the example program links.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

Reply via email to