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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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 ` kkojima at gcc dot gnu.org
  2015-08-24  1:59 ` bugdal at aerifal dot cx
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-08-23  8:48 UTC (permalink / raw)
  To: gcc-bugs

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

Kazumoto Kojima <kkojima at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kkojima at gcc dot gnu.org

--- Comment #1 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
Created attachment 36246
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36246&action=edit
patch

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

looks to be reasonable.  It seems that sh backend shouldn't
use UNSPEC_SYMOFF for that case in the first place.  Does
the patch attached work for you?


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2015-08-24  1:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Rich Felker <bugdal at aerifal dot cx> ---
The patch in comment 1 applies successfully to GCC 5.2.0 and fixes both the
test case and the real-world code I was experiencing problems with.
Unfortunately it doesn't apply to some of the older GCC versions I need to
support, but I think I can backport it. Thanks!


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-08-24  2:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
(In reply to Rich Felker from comment #2)

Thanks for the confirmation.  I'll commit the patch after the undergoing
additional test done.


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-08-24 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
Author: kkojima
Date: Mon Aug 24 23:23:00 2015
New Revision: 227155

URL: https://gcc.gnu.org/viewcvs?rev=227155&root=gcc&view=rev
Log:
PR target/66609
* [SH] Take into account weak symbols for pc relative calls/sibcalls.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sh/sh-protos.h
    trunk/gcc/config/sh/sh.c
    trunk/gcc/config/sh/sh.md


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (3 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-09-19  3:39 UTC (permalink / raw)
  To: gcc-bugs

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

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |olegendo at gcc dot gnu.org

--- Comment #5 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Kaz, do you think it's OK to backport this to GCC 5?  It looks like the patch
is not so intrusive...


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kkojima at gcc dot gnu.org @ 2015-09-19 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
(In reply to Oleg Endo from comment #5)
> Kaz, do you think it's OK to backport this to GCC 5?  It looks like the
> patch is not so intrusive...

Changing relocation is always intrusive, I think.  I won't
object to backport it, though.  The patch does the right thing
and will affect only very limited cases.


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2015-09-21  7:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Rich Felker <bugdal at aerifal dot cx> ---
Created attachment 36359
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36359&action=edit
preprocessed source still affected by the bug

Oddly I'm still experiencing this bug for some functions but not others, even
with the patch applied. I've attached preprocessed output of a file which is
being miscompiled: the reference to __do_cleanup_push wrongly binds locally,
but the reference to __do_cleanup_pop is overridable like it should be.


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2015-09-21  7:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Rich Felker <bugdal at aerifal dot cx> ---
Perhaps hold off on worrying about this; it's only happening with -mfdpic (with
my forward-port of the fdpic patch applied) so it's possible that the bug is on
my end in code that's not in upstream gcc. I'll follow up on this more later.


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2015-09-23 18:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Rich Felker <bugdal at aerifal dot cx> ---
Indeed, the fdpic patch I forward-ported introduced new duplicates of some of
the fragments that were changed in sh.md by the above patch. Once I fixed
those, the problem went away. Sorry for the noise.


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

* [Bug target/66609] [sh] Relative address expressions bind at as-time, even if symbol is weak
  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
                   ` (8 preceding siblings ...)
  2015-09-23 18:10 ` bugdal at aerifal dot cx
@ 2015-10-26 12:24 ` olegendo at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-10-26 12:24 UTC (permalink / raw)
  To: gcc-bugs

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

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Oleg Endo <olegendo at gcc dot gnu.org> ---
I think we can close this as fixed.


^ 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).