[all-commits] [llvm/llvm-project] e6112a: [AsmPrinter] Emit .weak directive for weak linkage...

Martin Storsjö via All-commits all-commits at lists.llvm.org
Sat Mar 28 09:49:58 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: e6112a56dde6db13ea29721077cb9d294d01b54d
      https://github.com/llvm/llvm-project/commit/e6112a56dde6db13ea29721077cb9d294d01b54d
  Author: Martin Storsjö <martin at martin.st>
  Date:   2020-03-28 (Sat, 28 Mar 2020)

  Changed paths:
    M llvm/include/llvm/MC/MCAsmInfo.h
    M llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    M llvm/lib/MC/MCAsmInfoCOFF.cpp
    A llvm/test/CodeGen/X86/coff-linkonce.ll
    M llvm/test/CodeGen/X86/coff-weak.ll
    M llvm/test/CodeGen/X86/dllexport-x86_64.ll
    M llvm/test/CodeGen/X86/dllexport.ll

  Log Message:
  -----------
  [AsmPrinter] Emit .weak directive for weak linkage on COFF for symbols without a comdat

MC already knows how to emulate the .weak directive (with its ELF
semantics; i.e., an undefined weak symbol resolves to 0, and a defined
weak symbol has lower link precedence than a strong symbol of the same
name) using COFF weak externals. Plumb this through the ASM printer too,
so that definitions marked with __attribute__((weak)) at the language
level (which gets translated to weak linkage at the IR level) have the
corresponding .weak directive emitted. Note that declarations marked
with __attribute__((weak)) at the language level (which translates to
extern_weak at the IR level) already have .weak directives emitted.

Weak*/linkonce* symbols without an associated comdat (in particular, ones
generated with __attribute__((weak)) in C/C++) were earlier emitted as
normal unique globals, as the comdat is required to provide the linkonce
semantics. This change makes sure they are emitted as .weak instead,
allowing other symbols to override them.

Rename the existing coff-weak.ll test to coff-linkonce.ll. I'm not
quite sure what that test covers, since the behavior being tested in it
(the emission of a one_only section) is just a result of passing
-function-sections to llc; the linkonce_odr makes no difference.

Add a new coff-weak.ll which tests the new directive emission.

Based on an previous patch by Shoaib Meenai.

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




More information about the All-commits mailing list