public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/66609] New: [sh] Relative address expressions bind at as-time, even if symbol is weak
@ 2015-06-19 21:11 bugdal at aerifal dot cx
  2015-08-23  8:48 ` [Bug target/66609] " kkojima at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2015-06-19 21:11 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-10-26 12:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-19 21:11 [Bug target/66609] New: [sh] Relative address expressions bind at as-time, even if symbol is weak bugdal at aerifal dot cx
2015-08-23  8:48 ` [Bug target/66609] " kkojima at gcc dot gnu.org
2015-08-24  1:59 ` bugdal at aerifal dot cx
2015-08-24  2:50 ` kkojima at gcc dot gnu.org
2015-08-24 23:23 ` kkojima at gcc dot gnu.org
2015-09-19  3:39 ` olegendo at gcc dot gnu.org
2015-09-19 12:52 ` kkojima at gcc dot gnu.org
2015-09-21  7:29 ` bugdal at aerifal dot cx
2015-09-21  7:33 ` bugdal at aerifal dot cx
2015-09-23 18:10 ` bugdal at aerifal dot cx
2015-10-26 12:24 ` olegendo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).