This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RISC-V problem with weak function references and -mcmodel=medany


On 05/29/2018 04:19 AM, Sebastian Huber wrote:
Changing the code to something like this

void f(void) __attribute__((__weak__));

void _start(void)
{
         void (*g)(void) = f;

         if (g != 0) {
                 (*g)();
         }
}

This testcase works for me also, using -mcmodel=medany -O tmp.c -Ttext=0x80000000 -nostdlib -nostartfiles.

I need enough info to reproduce your problem in order to look at it.

One thing you can try is adding -Wl,--noinhibit-exec, which will produce an executable even though there was a linker error, and then you can disassemble the binary to see what you have for the weak call. That might give a clue as to what is wrong.

Why doesn't the RISC-V generate a trampoline code to call far functions?

RISC-V is a new target. The answer to questions like this is that we haven't needed it yet, and hence haven't implemented it yet. But I don't see any need for trampolines to support a call to 0. We can reach anywhere in the low 32-bit address space with auipc/jalr. We can also use zero-relative addressing via the x0 register if necessary. We already have some linker relaxation support for that, but it doesn't seem to be triggering for this testcase.

Jim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]