public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98112] New: Add -fdirect-access-external-data & drop HAVE_LD_PIE_COPYRELOC
@ 2020-12-03  1:26 i at maskray dot me
  2020-12-03 12:16 ` [Bug target/98112] " hjl.tools at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: i at maskray dot me @ 2020-12-03  1:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98112
           Summary: Add -fdirect-access-external-data & drop
                    HAVE_LD_PIE_COPYRELOC
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i at maskray dot me
  Target Milestone: ---

After "x86-64: Optimize access to globals in PIE with copy reloc", GCC x86-64
asks the assembler to produce an R_X86_64_PC32 for an external data access.

* It introduced a configure-time variable HAVE_LD_PIE_COPYRELOC which has a
misleading name: PC32 does not necessarily cause a copy relocation.
  If the external data
* It affects users who want to configure GCC not to emit R_X86_64_PC32 for an
external data access so that copy relocations can be avoided if the data turns
out to be defined in a different shared object/executable
* While it made sense (in turns of performance) before H.J. Lu added GOTPCRELX
to x86-64, it hardly matters if any nowadays.
* This optimization can actually benefit non-x86-64. An option is more
suitable.

In Clang, the GCC style HAVE_LD_PIE_COPYRELOC is implemented as
-mpie-copy-relocations, which has a misleading name.
I agree that this should be implemented as an option, instead of a
configure-time variable.

I suggest that we add a new architecture-independent option
-f[no-]direct-access-external-data (I am happy to add a similar one in Clang
once consensus is made) and delete HAVE_LD_PIE_COPYRELOC. The option means
whether a direct access (PC-relative relocation) can be generated for an
external data access.
The value can default to true for -fno-pic code (it seems that most
architectures behave this way).
For non-x86-64, the value defaults to false for -fpie/-fpic code (I believe
most architectures use a GOT).

In the future, for x86-64, please consider defaulting to
-fno-direct-access-external-data for -fpie/-fpic so that issues related to
STV_PROTECTED data can be properly fixed (see my analysis last year
https://gcc.gnu.org/legacy-ml/gcc/2019-05/msg00215.html )

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

end of thread, other threads:[~2023-01-04 18:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03  1:26 [Bug c/98112] New: Add -fdirect-access-external-data & drop HAVE_LD_PIE_COPYRELOC i at maskray dot me
2020-12-03 12:16 ` [Bug target/98112] " hjl.tools at gmail dot com
2020-12-03 17:51 ` i at maskray dot me
2020-12-15  0:25 ` i at maskray dot me
2020-12-28  7:34 ` segher at gcc dot gnu.org
2020-12-28  8:36 ` i at maskray dot me
2020-12-28  9:54 ` segher at gcc dot gnu.org
2020-12-28 17:43 ` i at maskray dot me
2023-01-02 19:54 ` [Bug target/98112] Add -f[no-]direct-access-external-data " foom at fuhm dot net
2023-01-04 18:50 ` thiago at kde dot org
2023-01-04 18:54 ` pinskia 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).