[all-commits] [llvm/llvm-project] e018cb: [IR] Make stack protector symbol dso_local accordi...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue May 23 09:50:10 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e018cbf7208b3d34f18997ddee84c66cee32fb1b
      https://github.com/llvm/llvm-project/commit/e018cbf7208b3d34f18997ddee84c66cee32fb1b
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/test/CodeGen/dso-local-executable.c
    M llvm/include/llvm/IR/Module.h
    M llvm/lib/CodeGen/TargetLoweringBase.cpp
    M llvm/lib/IR/Module.cpp
    M llvm/lib/Target/X86/X86ISelLowering.cpp
    M llvm/test/CodeGen/AArch64/arm64_32.ll
    M llvm/test/CodeGen/AArch64/stack-guard-sve.ll
    M llvm/test/CodeGen/AArch64/stack-guard-vaarg.ll
    M llvm/test/CodeGen/AArch64/stack_guard_remat.ll
    M llvm/test/CodeGen/ARM/expand-pseudos.ll
    M llvm/test/CodeGen/ARM/stack-guard-rwpi.ll
    M llvm/test/CodeGen/ARM/stack_guard_remat.ll
    M llvm/test/CodeGen/Inputs/stack-guard-reassign.ll
    M llvm/test/CodeGen/PowerPC/stack-guard-oob.ll
    M llvm/test/CodeGen/Thumb/stack_guard_remat.ll
    M llvm/test/CodeGen/Thumb2/stack_guard_remat.ll
    M llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
    M llvm/test/CodeGen/X86/2010-09-17-SideEffectsInChain.ll
    M llvm/test/CodeGen/X86/stack-protector-3.ll

  Log Message:
  -----------
  [IR] Make stack protector symbol dso_local according to -f[no-]direct-access-external-data

There are two motivations.

`-fno-pic -fstack-protector -mstack-protector-guard=global` created
`__stack_chk_guard` is referenced directly on all ELF OSes except FreeBSD.
This patch allows referencing the symbol indirectly with
-fno-direct-access-external-data.

Some Linux kernel folks want
`-fno-pic -fstack-protector -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard`
created `__stack_chk_guard` to be referenced directly, avoiding
R_X86_64_REX_GOTPCRELX (even if the relocation may be optimized out by the linker).
https://github.com/llvm/llvm-project/issues/60116
Why they need this isn't so clear to me.

---

Add module flag "direct-access-external-data" and set the dso_local property of
the stack protector symbol. The module flag can benefit other LLVMCodeGen
synthesized symbols that are not represented in LLVM IR.

Nowadays, with `-fno-pic` being uncommon, ideally we should set
"direct-access-external-data" when it is true. However, doing so would require
~90 clang/test tests to be updated, which are too much.

As a compromise, we set "direct-access-external-data" only when it's different
from the implied default value.

Reviewed By: nickdesaulniers

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




More information about the All-commits mailing list