Skip to content

Commit 1642111

Browse files
vchuravymaleadt
authored andcommitted
Revert "[MC] Always emit relocations for same-section function references"
This reverts commit 5a5ac65. (cherry picked from commit ae2638d) (cherry picked from commit 05848b6)
1 parent 99b5474 commit 1642111

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

llvm/lib/MC/WinCOFFObjectWriter.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -1190,14 +1190,12 @@ void WinCOFFObjectWriter::reset() {
11901190
bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
11911191
const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
11921192
bool InSet, bool IsPCRel) const {
1193-
// Don't drop relocations between functions, even if they are in the same text
1194-
// section. Multiple Visual C++ linker features depend on having the
1195-
// relocations present. The /INCREMENTAL flag will cause these relocations to
1196-
// point to thunks, and the /GUARD:CF flag assumes that it can use relocations
1197-
// to approximate the set of all address taken functions. LLD's implementation
1198-
// of /GUARD:CF also relies on the existance of these relocations.
1193+
// MS LINK expects to be able to replace all references to a function with a
1194+
// thunk to implement their /INCREMENTAL feature. Make sure we don't optimize
1195+
// away any relocations to functions.
11991196
uint16_t Type = cast<MCSymbolCOFF>(SymA).getType();
1200-
if ((Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
1197+
if (Asm.isIncrementalLinkerCompatible() &&
1198+
(Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
12011199
return false;
12021200
return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
12031201
InSet, IsPCRel);

llvm/test/MC/COFF/diff.s

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// RUN: llvm-mc -filetype=obj -triple i686-pc-mingw32 %s | llvm-readobj -S --sr --sd - | FileCheck %s
22

3-
// COFF resolves differences between labels in the same section, unless that
4-
// label is declared with function type.
5-
63
.section baz, "xr"
4+
.def X
5+
.scl 2;
6+
.type 32;
7+
.endef
78
.globl X
89
X:
910
mov Y-X+42, %eax
1011
retl
1112

13+
.def Y
14+
.scl 2;
15+
.type 32;
16+
.endef
1217
.globl Y
1318
Y:
1419
retl
@@ -25,11 +30,6 @@ _foobar: # @foobar
2530
# %bb.0:
2631
ret
2732

28-
.globl _baz
29-
_baz:
30-
calll _foobar
31-
retl
32-
3333
.data
3434
.globl _rust_crate # @rust_crate
3535
.align 4
@@ -39,15 +39,6 @@ _rust_crate:
3939
.long _foobar-_rust_crate
4040
.long _foobar-_rust_crate
4141

42-
// Even though _baz and _foobar are in the same .text section, we keep the
43-
// relocation for compatibility with the VC linker's /guard:cf and /incremental
44-
// flags, even on mingw.
45-
46-
// CHECK: Name: .text
47-
// CHECK: Relocations [
48-
// CHECK-NEXT: 0x12 IMAGE_REL_I386_REL32 _foobar
49-
// CHECK-NEXT: ]
50-
5142
// CHECK: Name: .data
5243
// CHECK: Relocations [
5344
// CHECK-NEXT: 0x4 IMAGE_REL_I386_DIR32 _foobar

0 commit comments

Comments
 (0)