public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/12306] GOT pointer (r12) reloaded unnecessarily
       [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
@ 2012-07-18 19:25 ` olegendo at gcc dot gnu.org
  2013-11-24 17:16 ` olegendo at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-07-18 19:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12306

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|sh-elf                      |sh*-*-*
   Last reconfirmed|2005-09-07 17:58:48         |2012-07-18
                 CC|                            |olegendo at gcc dot gnu.org

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-07-18 19:25:41 UTC ---
As of rev 189601 (4.8.0 20120718 (experimental)) this issue still persists.


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

* [Bug target/12306] GOT pointer (r12) reloaded unnecessarily
       [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
  2012-07-18 19:25 ` [Bug target/12306] GOT pointer (r12) reloaded unnecessarily olegendo at gcc dot gnu.org
@ 2013-11-24 17:16 ` olegendo at gcc dot gnu.org
  2013-11-24 23:02 ` kkojima at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: olegendo at gcc dot gnu.org @ 2013-11-24 17:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12306

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

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

--- Comment #3 from Oleg Endo <olegendo at gcc dot gnu.org> ---
If I understand correctly, rebuilding the GOT pointer in r12 is necessary at
function entry, since it is generally not known if r12 is a valid GOT pointer
at function entry when mixing PIC code and non-PIC code.  Calling a PIC
function from a non-PIC function could result in a clobbered GOT pointer.

non_pic_func:
     mov.l  r12,@-r15
     mov.l  r11,@-r15

     <do stuff and clobber r12>

     <call PIC function here (r12 clobbered)>

     mov.l  @r15+,r11
     rts
     mov.l  @r15+,r12

Kaz, could you please confirm or refute this?


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

* [Bug target/12306] GOT pointer (r12) reloaded unnecessarily
       [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
  2012-07-18 19:25 ` [Bug target/12306] GOT pointer (r12) reloaded unnecessarily olegendo at gcc dot gnu.org
  2013-11-24 17:16 ` olegendo at gcc dot gnu.org
@ 2013-11-24 23:02 ` kkojima at gcc dot gnu.org
  2013-11-25 12:39 ` chrbr at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: kkojima at gcc dot gnu.org @ 2013-11-24 23:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12306

--- Comment #4 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
(In reply to Oleg Endo from comment #3)
> If I understand correctly, rebuilding the GOT pointer in r12 is necessary at
> function entry, since it is generally not known if r12 is a valid GOT
> pointer at function entry when mixing PIC code and non-PIC code.  Calling a
> PIC function from a non-PIC function could result in a clobbered GOT > 

Yep.  If a pic function is called from a pic function, that
save&restore can be removed.  The case like

non_pic_function:
    mov.l    r12,@-r15
    sts.l    pr,@-r15

    <use r12 as a variable x>

    <call PIC function here (r12 should not be clobbered)>

    <use r12 as a variable x>

    lds.l    @r15+,pr
    rts    
    mov.l    @r15+,r12

needs it.  If we knew that that pic function can't be called from
any non-pic functions by some additional information, we could
optimize the code with removing that save&restore r12.


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

* [Bug target/12306] GOT pointer (r12) reloaded unnecessarily
       [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2013-11-24 23:02 ` kkojima at gcc dot gnu.org
@ 2013-11-25 12:39 ` chrbr at gcc dot gnu.org
  2013-11-25 16:22 ` olegendo at gcc dot gnu.org
  2013-11-26  6:05 ` kkojima at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: chrbr at gcc dot gnu.org @ 2013-11-25 12:39 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12306

chrbr at gcc dot gnu.org changed:

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

--- Comment #5 from chrbr at gcc dot gnu.org ---

> 
> needs it.  If we knew that that pic function can't be called from
> any non-pic functions by some additional information, we could
> optimize the code with removing that save&restore r12.

or from a pic function from the same module. using visibility protected perhaps
?


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

* [Bug target/12306] GOT pointer (r12) reloaded unnecessarily
       [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2013-11-25 12:39 ` chrbr at gcc dot gnu.org
@ 2013-11-25 16:22 ` olegendo at gcc dot gnu.org
  2013-11-26  6:05 ` kkojima at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: olegendo at gcc dot gnu.org @ 2013-11-25 16:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12306

--- Comment #6 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Maybe something like function multi-versioning could be used for that?

When compiling as PIC, each function would be output twice.  Once with the
assumption that it can be called from non-PIC functions and once with the
assumption that it can't.  So we'll have one function that does the r12 stuff
and another that doesn't.  Then the linker could figure it out by e.g. dead
code stripping, and maybe also taking into account the visibility.  In the
worst case, if the linker can't make a decision, it should leave the
"with-r12-stuff" version.


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

* [Bug target/12306] GOT pointer (r12) reloaded unnecessarily
       [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2013-11-25 16:22 ` olegendo at gcc dot gnu.org
@ 2013-11-26  6:05 ` kkojima at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: kkojima at gcc dot gnu.org @ 2013-11-26  6:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12306

--- Comment #7 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
Even a static pic function can be called from non-pic functions
via function pointer.  Functions with hidden visibility in static
libraries can be compiled with -fPIC.  A typical example is libgcc.a.
Something based on WPA may be possible, though in general, it would
be not easy to assure a pic function can never be called from any
non-pic functions.  An explicit attribute or a flag which assures
that will work, though might be not so attractive.


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

end of thread, other threads:[~2013-11-26  6:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-12306-4@http.gcc.gnu.org/bugzilla/>
2012-07-18 19:25 ` [Bug target/12306] GOT pointer (r12) reloaded unnecessarily olegendo at gcc dot gnu.org
2013-11-24 17:16 ` olegendo at gcc dot gnu.org
2013-11-24 23:02 ` kkojima at gcc dot gnu.org
2013-11-25 12:39 ` chrbr at gcc dot gnu.org
2013-11-25 16:22 ` olegendo at gcc dot gnu.org
2013-11-26  6:05 ` kkojima 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).