[all-commits] [llvm/llvm-project] d2ef8c: [ThinLTO] Drop dso_local if a GlobalVariable satis...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Apr 7 15:47:37 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: d2ef8c1f2ca33457247be26374852573098553c7
      https://github.com/llvm/llvm-project/commit/d2ef8c1f2ca33457247be26374852573098553c7
  Author: Fangrui Song <maskray at google.com>
  Date:   2020-04-07 (Tue, 07 Apr 2020)

  Changed paths:
    M llvm/include/llvm/Transforms/IPO/FunctionImport.h
    M llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
    M llvm/lib/LTO/LTOBackend.cpp
    M llvm/lib/LTO/ThinLTOCodeGenerator.cpp
    M llvm/lib/Transforms/IPO/FunctionImport.cpp
    M llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
    M llvm/test/LTO/Resolution/X86/local-def-dllimport.ll
    M llvm/test/ThinLTO/X86/Inputs/index-const-prop-gvref.ll
    M llvm/test/ThinLTO/X86/funcimport_alwaysinline.ll
    M llvm/test/ThinLTO/X86/index-const-prop-alias.ll
    M llvm/test/ThinLTO/X86/index-const-prop-comdat.ll
    M llvm/test/ThinLTO/X86/index-const-prop-dead.ll
    M llvm/test/ThinLTO/X86/index-const-prop-full-lto.ll
    A llvm/test/ThinLTO/X86/index-const-prop-gvref-pie.ll
    M llvm/test/ThinLTO/X86/index-const-prop-gvref.ll
    M llvm/test/ThinLTO/X86/index-const-prop-ldst.ll
    M llvm/test/ThinLTO/X86/index-const-prop-linkage.ll
    M llvm/test/ThinLTO/X86/index-const-prop2.ll
    M llvm/tools/llvm-link/llvm-link.cpp

  Log Message:
  -----------
  [ThinLTO] Drop dso_local if a GlobalVariable satisfies isDeclarationForLinker()

dso_local leads to direct access even if the definition is not within this compilation unit (it is
still in the same linkage unit). On ELF, such a relocation (e.g. R_X86_64_PC32) referencing a
STB_GLOBAL STV_DEFAULT object can cause a linker error in a -shared link.

If the linkage is changed to available_externally, the dso_local flag should be dropped, so that no
direct access will be generated.

The current behavior is benign, because -fpic does not assume dso_local
(clang/lib/CodeGen/CodeGenModule.cpp:shouldAssumeDSOLocal).
If we do that for -fno-semantic-interposition (D73865), there will be an
R_X86_64_PC32 linker error without this patch.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D74751




More information about the All-commits mailing list