[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
Fri Dec 4 11:11:39 PST 2020


MaskRay added a comment.

In D92633#2434231 <https://reviews.llvm.org/D92633#2434231>, @tmsriram wrote:

> Sorry just one more thing which is a bit concerning:
>
> When I do  :
>
> $ clang -fPIC -frxternal-data-access foo.c
>
> You will omit the GOT but this object can go into a shared object and break the build as this does not apply to shared objects?  Should we allow this at all for -fPIC?  I dont see a need for this but if you want to,  maybe warn?  The user should know that this cannot go into a shared object right?
> I am also ok with commenting that this option can do bad things for -fPIC and the user should know what they are doing.

`clang -fPIC -fdirect-access-eternal-data -c a.c; ld -no-pie a.o; ld -pie a.o` (producing an executable with either `-no-pie` or `-pie`) is fine.

For `-shared`, because an ELF linker assumes interposition for non-local STV_DEFAULT symbols by default, linking such an object files requires some mechanism to make it non-preemptible.
The simplest is `clang -fPIC -fdirect-access-external-data -c a.c; ld -shared -Bsymbolic a.o`
Other mechanisms include: `--dynamic-list` (don't list the symbol) and `--version-script` (localize the symbol).
This is going to be tricky and I don't know how to fit the information into the few-line description of the option.

I just checked how to make -fdirect-access-eternal-data work for -fno-pic (both TargetMachine::shouldAssumeDSOLocal and CodeGenModule.cpp:shouldAssumeDSOLocal should not assume false for Reloc::Static), unfortunately there are 200 tests needing updates. (This reminds me that LLVM doesn't get the default for dso_local right, so many tests have `dso_local` in ELF/COFF but no `dso_local` in Mach-O. Unfortunately it is extremely difficult to fix it today (D76561 <https://reviews.llvm.org/D76561>))


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92633/new/

https://reviews.llvm.org/D92633



More information about the cfe-commits mailing list