This is the mail archive of the gcc-bugs@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]

[Bug target/66609] New: [sh] Relative address expressions bind at as-time, even if symbol is weak


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66609

            Bug ID: 66609
           Summary: [sh] Relative address expressions bind at as-time,
                    even if symbol is weak
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx
  Target Milestone: ---

Minimal test case (compile with -fPIC and -Os or higher, for sh2 or later):

__attribute__((__weak__,__visibility__("hidden"))) void foo()
{
}

void bar()
{
    foo();
}

For the call from bar to foo, gcc generates:

    mov.l .L3,r1
    braf r1
.LPCS0:
    nop
    .align 2
.L3:
    .long foo-(.LPCS0+2)

Gas in turn ignores the fact that foo is weak and assembles the literal to a
constant with no relocation. This is the following bug I just reported in
binutils:

https://sourceware.org/bugzilla/show_bug.cgi?id=18561

However, GCC can and probably should work around it, by instead generating the
equivalent form that gas assembles correctly:

    .long foo@PCREL-(.LPCS0+2-.)

This is easily changed at the following location:

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/sh/sh.c;h=e5fcd7683ef7e06d56a10427d792ba018d1af884;hb=HEAD#l1662

and changing it seems to have solved the problem for me, but I did not yet test
extensively. I'm not sure if the subsequent case for UNSPEC_PCREL_SYMOFF also
needs changes.


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