[PATCH] D92633: Add -f[no-]direct-access-external-data to deprecate -mpie-copy-relocations

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 22:00:26 PST 2020


MaskRay created this revision.
MaskRay added reviewers: hjl.tools, rnk, tmsriram.
Herald added subscribers: dexonsmith, dang, pengfei, s.egerton, simoncook.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC r218397 "x86-64: Optimize access to globals in PIE with copy reloc" made
-fpie code emit R_X86_64_PC32 to reference external data symbols by default.
Clang adopted -mpie-copy-relocations D19996 <https://reviews.llvm.org/D19996> as a flexible alternative.

The name -mpie-copy-relocations is misleading [1] and does not capture the idea
that this option can actually apply to all of -fno-pic,-fpie,-fpie [2], so this
patch introduces -f[no-]direct-access-external-data and makes
-mpie-copy-relocations their aliases for compatibility.

[1]
For

  extern int var;
  int get() { return var; }

if var is defined in another translation unit in the link unit, there is no copy
relocation.

[2]
While -fno-pic code generally uses an absolute relocation to reference a data
symbol, GOT indirection can still be used.

-fpic can avoid GOT indirection as well, the user should be responsible for
defining var in another translation unit, otherwise the linker will error in a
-shared link (copy relocations are not available in shared objects).

Neither the -fno-pic nor the -fpic behavior is implemented in this patch, though.

GCC feature request https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98112 (the
description is much more complex than the Clang description because GCC/GNU ld
x86-64 have some STV_PROTECTED issues which originated from the default
HAVE_LD_PIE_COPYRELOC thing).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92633

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/dso-local-executable.c
  clang/test/Driver/fdirect-access-external-data.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92633.309456.patch
Type: text/x-patch
Size: 8939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201204/260639a8/attachment.bin>


More information about the cfe-commits mailing list