# Is dso\_local set in LLVM IR output?

**URL:** <https://discourse.julialang.org/t/is-dso-local-set-in-llvm-ir-output/52707>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [January 1, 2021, 7:20pm UTC](https://discourse.julialang.org/t/is-dso-local-set-in-llvm-ir-output/52707 "2021-01-01T19:20:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaskRay](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maskray/32/10424_2.png) [@MaskRay](https://discourse.julialang.org/u/MaskRay)\
**Post date:** [January 1, 2021, 7:20pm UTC](https://discourse.julialang.org/t/is-dso-local-set-in-llvm-ir-output/52707/1 "2021-01-01T19:20:18Z")

</div>

[https://github.com/llvm/llvm-project/commit/2047c10c22b071cccc57a7e2779d6603512e9113](https://github.com/llvm/llvm-project/commit/2047c10c22b071cccc57a7e2779d6603512e9113) was to clean up `llvm::TargetMachine::shouldAssumeDSOLocal`. For Clang, that code is unneeded because Clang sets dso\_local [https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CodeGenModule.cpp#L910](https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CodeGenModule.cpp#L910)

I am thinking whether [https://github.com/llvm/llvm-project/commit/2047c10c22b071cccc57a7e2779d6603512e9113](https://github.com/llvm/llvm-project/commit/2047c10c22b071cccc57a7e2779d6603512e9113) should be reverted (or be replaced with `if (RM == Reloc::Static && !GV->isDeclarationForLinker()) return true`) as a workaround before IR producers set dso\_local properly.

**But for Julia, it’d be nice to explicitly set dso\_local like Clang.**

About dso\_local in LLVM IR, it was introduced to model “whether references to a function/global variable (either definition or declaration) can be assumed to be resolved within the linkage unit”.

On ELF, `STV_DEFAULT STB_GLOBAL/STB_WEAK` symbols are preemptible (interposable) for a shared object (`ld -shared`). Such -fpic produced symbols are modeled with dso\_preemptable. (Yes, “preemptible” is used more frequently than “preemptable” in ELF)

On COFF, only extern\_weak or dllimport symbols can be dso\_preemptable.

On Mach-O, the current rule is

```julia
  if (TT.isOSBinFormatMachO()) {
    if (RM == llvm::Reloc::Static)
      return true;
    return GV->isStrongDefinitionForLinker();
  }

```

It’d be nice if someone can clarify whether the `GV->isStrongDefinitionForLinker()` condition can be generalized to `!GV->isDeclaractionForLinker` in non-static relocation models (`llc -relocation-model=pic` or `llc -relocation-model=dynamic-no-pic`)

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [April 27, 2023, 2:35pm UTC](https://discourse.julialang.org/t/is-dso-local-set-in-llvm-ir-output/52707/2 "2023-04-27T14:35:35Z")

</div>

Thanks for the info! I am working on this now. I think I missed this comment initially, but Google found it for me now, so it turned out to be helpful 2 years later anyways! For Mach-O I found the main challenge is that clang neither permits `visibility(protected)` in the clang parser nor allows aliases, so it is rather difficult to get clang to mark an exported symbol as dso\_local. Do you have any thoughts on what that should do instead?
