public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "thiago at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/65886] [5/6 Regression] Copy reloc in PIE incompatible with DSO created by -Wl,-Bsymbolic
Date: Tue, 05 May 2015 15:54:00 -0000	[thread overview]
Message-ID: <bug-65886-4-CyqgBapdHp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65886-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #31 from Thiago Macieira <thiago at kde dot org> ---
(In reply to Jakub Jelinek from comment #29)
> You are missing the point of copy relocations.  Consider:
> int a = 1;
> extern int b, c;
> int foo (void)
> {
>   return a + b + c;
> }
> compiled with -fno-pic or -fpie.  a is known to be defined in the
> executable, but b and c are externals.  Without copy relocations you'd need
> to emit significantly slower code (extra .got reference or similar) for all
> the accesses to the externals, with copy relocations you can optimistically
> assume they will likely be defined in the executable (usual case for larger
> programs, at least for C shared libraries people avoid exporting variables
> from shared libraries if easily possible), and if not, the linker will
> create copy relocations.

That is true.

But if you place the same code in a library, then now all accesses must be
indirect, even for a. My assertion isn't about the usefulness of copy
relocations, it's that they are optimising for the wrong thing. The size and
complexity of libraries and plugins in desktop applications is orders of
magnitude above that of the application codebases.

> Only with whole program (LTO or similar) compilation, when you can talk to
> the linker, you could find out if the externals from some TU are defined
> within the executable or not.

Or if we tag them appropriately.

int a = 1;
extern int b;
__attribute__((dllimport)) extern int c;
int foo(void)
{
    return a + b + c;
}

Now the compiler knows that a is in the local executable and it can assume that
b is too, but it  also knows that c isn't and must be accessed indirectly. This
did not require LTO.

Modern libraries already all have a macro preceding all the function and
variable declarations meant to be used by other DSOs, ever since Ulrich
Drepper's "dso-howto" manual. The macro tags are required so that we have a
proper __attribute__((visibility("default"))) when the library is compiled with
-fvisibility=hidden. Moreover, the same tag expands to __declspec(dllexport) or
__declspec(dllimport) on Windows if the library is cross-platform. So the
precedent is there and modern libraries are mostly ready to make use of the
feature.


  parent reply	other threads:[~2015-05-05 15:54 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-25 13:45 [Bug target/65886] New: [5/6 Regression] External reference in PIE to DSO created with -Wl,-Bsymbolic hjl.tools at gmail dot com
2015-04-25 13:46 ` [Bug target/65886] " hjl.tools at gmail dot com
2015-04-25 15:47 ` [Bug target/65886] [5/6 Regression] External reference in PIE incompatible with DSO created by -Wl,-Bsymbolic hjl.tools at gmail dot com
2015-04-25 16:33 ` hjl.tools at gmail dot com
2015-04-25 16:51 ` [Bug target/65886] [5/6 Regression] Copy reloc " thiago at kde dot org
2015-04-25 17:06 ` hjl.tools at gmail dot com
2015-04-25 17:08 ` hjl.tools at gmail dot com
2015-04-25 17:25 ` hjl.tools at gmail dot com
2015-04-25 17:30 ` thiago at kde dot org
2015-04-25 17:37 ` hjl.tools at gmail dot com
2015-04-25 17:42 ` hjl.tools at gmail dot com
2015-04-27  9:05 ` rguenth at gcc dot gnu.org
2015-04-27 12:14 ` jakub at gcc dot gnu.org
2015-04-27 12:22 ` hjl.tools at gmail dot com
2015-04-27 12:37 ` jakub at gcc dot gnu.org
2015-04-27 12:44 ` hjl.tools at gmail dot com
2015-04-27 13:14 ` hjl.tools at gmail dot com
2015-04-27 13:51 ` jakub at gcc dot gnu.org
2015-04-27 19:18 ` thiago at kde dot org
2015-04-29 19:05 ` hjl.tools at gmail dot com
2015-04-29 19:06 ` hjl.tools at gmail dot com
2015-05-05 15:03 ` thiago at kde dot org
2015-05-05 15:09 ` hjl.tools at gmail dot com
2015-05-05 15:12 ` jakub at gcc dot gnu.org
2015-05-05 15:14 ` jakub at gcc dot gnu.org
2015-05-05 15:38 ` hjl.tools at gmail dot com
2015-05-05 15:47 ` jakub at gcc dot gnu.org
2015-05-05 15:48 ` thiago at kde dot org
2015-05-05 15:54 ` thiago at kde dot org [this message]
2015-06-30 10:32 ` rguenth at gcc dot gnu.org
2015-07-16  9:17 ` rguenth at gcc dot gnu.org
2015-08-06 18:06 ` thiago at kde dot org
2015-08-06 18:24 ` hjl.tools at gmail dot com
2015-08-06 18:27 ` thiago at kde dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-65886-4-CyqgBapdHp@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).