-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AsmPrinter] Emit .weak directive for weak linkage on COFF for symbol…
…s 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
- Loading branch information
Showing
7 changed files
with
80 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
; RUN: llc -function-sections -o - %s | FileCheck %s | ||
|
||
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-windows-msvc" | ||
|
||
; CHECK: .section{{.*}}one_only | ||
define linkonce_odr void @foo() { | ||
ret void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,50 @@ | ||
; RUN: llc -function-sections -o - %s | FileCheck %s | ||
; RUN: llc -mtriple=i686-windows-msvc -o - %s | FileCheck -check-prefix=X86 %s | ||
; RUN: llc -mtriple=x86_64-windows-msvc -o - %s | FileCheck -check-prefix=X64 %s | ||
|
||
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-windows-msvc" | ||
; X86: .weak _foo | ||
; X64: .weak foo | ||
define weak void @foo() { | ||
ret void | ||
} | ||
|
||
; X86: .weak _bar | ||
; X64: .weak bar | ||
define weak_odr void @bar() { | ||
ret void | ||
} | ||
|
||
; X86-NOT: .weak _bar_comdat | ||
; X64-NOT: .weak bar_comdat | ||
$bar_comdat = comdat any | ||
|
||
define weak_odr void @bar_comdat() comdat { | ||
ret void | ||
} | ||
|
||
; X86: .weak _baz | ||
; X64: .weak baz | ||
define linkonce void @baz() { | ||
ret void | ||
} | ||
|
||
; X86-NOT: .weak _baz_comdat | ||
; X64-NOT: .weak baz_comdat | ||
$baz_comdat = comdat any | ||
|
||
define linkonce void @baz_comdat() comdat { | ||
ret void | ||
} | ||
|
||
; X86: .weak _quux | ||
; X64: .weak quux | ||
define linkonce_odr void @quux() { | ||
ret void | ||
} | ||
|
||
; X86-NOT: .weak _quux_comdat | ||
; X64-NOT: .weak quux_comdat | ||
$quux_comdat = comdat any | ||
|
||
; CHECK: .section{{.*}}one_only | ||
define linkonce_odr void @foo() { | ||
define linkonce_odr void @quux_comdat() comdat { | ||
ret void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters