[PATCH] D77248: [llvm][IR] Add dso_local_equivalent Constant

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 19:08:57 PDT 2020


leonardchan added inline comments.


================
Comment at: llvm/docs/LangRef.rst:3784
+  may need to be emitted explicitly.
+- If the global is a variable or alias to a variable, this can be implemented
+  by copying the contents
----------------
pcc wrote:
> rjmccall wrote:
> > pcc wrote:
> > > I would make this specific to functions. I don't think this can be made to work with globals at least with existing ELF linkers because I don't think you can get the copy relocation behavior without the symbol's value being overridden by the linkage unit with the copy relocation, and it doesn't make sense to have more than one linkage unit override the address of the same global.
> > Oh, does ELF's copy relocation necessarily steal the symbol so that it resolves into the copying linkage unit?  I thought it might be separable so that you could just get a local copy of the data without changing symbol resolution.  That would be a much more generically useful feature.
> I think the behaviors may be separable at the binary level (i.e. you could hand-craft an executable that only copies but doesn't override), but at the linker level the copying and overriding happen at the same time when the linker sees a non-GOT-generating relocation pointing to the symbol.
I'm fine with applying this to just functions for now since that was what I was initially planning to support. If possible, support for variables could be rolled out in the future. It looks like, off the bat, we could just use a GOT entry if we know the symbol is `dso_local`, but I think we can already achieve this by having a hidden global that points to your symbol.

Took me some time to research copy relocations, so correct me if I'm wrong, but should it be `R_*_GLOB_DATA` that overrides the symbol address during linking, whereas the copy relocation (`R_*_COPY`) just does the copying as @rjmccall suggests? I think it's `R_*_GLOB_DATA` that the GOT uses for getting addresses(?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77248



More information about the llvm-commits mailing list