[PATCH] D44543: [AsmPrinter] Emit .weak directive for weak linkage on COFF

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 15 14:26:58 PDT 2018


smeenai created this revision.
smeenai added reviewers: pcc, rnk.

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.

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, and
ensure it only occurs for weak symbols and not linkonce symbols (which
should have different semantics). I'm not quite happy about weak_odr
also resolving to the .weak directive, since that doesn't quite match
its semantics from the language reference (where it's only supposed to
be merged with equivalent definitions), but it matches the existing
behavior for ELF.


Repository:
  rL LLVM

https://reviews.llvm.org/D44543

Files:
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  test/CodeGen/X86/coff-linkonce.ll
  test/CodeGen/X86/coff-weak.ll
  test/CodeGen/X86/dllexport-x86_64.ll
  test/CodeGen/X86/dllexport.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44543.138630.patch
Type: text/x-patch
Size: 3019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180315/921ad54c/attachment.bin>


More information about the llvm-commits mailing list