Skip to content

Commit

Permalink
Revert "[MC] Always emit relocations for same-section function refere…
Browse files Browse the repository at this point in the history
…nces"

This reverts commit 5a5ac65.

(cherry picked from commit ae2638d)
  • Loading branch information
vchuravy committed Feb 7, 2022
1 parent 75e33f7 commit 05848b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
12 changes: 5 additions & 7 deletions llvm/lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,12 @@ void WinCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
bool InSet, bool IsPCRel) const {
// Don't drop relocations between functions, even if they are in the same text
// section. Multiple Visual C++ linker features depend on having the
// relocations present. The /INCREMENTAL flag will cause these relocations to
// point to thunks, and the /GUARD:CF flag assumes that it can use relocations
// to approximate the set of all address taken functions. LLD's implementation
// of /GUARD:CF also relies on the existance of these relocations.
// MS LINK expects to be able to replace all references to a function with a
// thunk to implement their /INCREMENTAL feature. Make sure we don't optimize
// away any relocations to functions.
uint16_t Type = cast<MCSymbolCOFF>(SymA).getType();
if ((Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
if (Asm.isIncrementalLinkerCompatible() &&
(Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
return false;
return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
InSet, IsPCRel);
Expand Down
25 changes: 8 additions & 17 deletions llvm/test/MC/COFF/diff.s
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// RUN: llvm-mc -filetype=obj -triple i686-pc-mingw32 %s | llvm-readobj -S --sr --sd - | FileCheck %s

// COFF resolves differences between labels in the same section, unless that
// label is declared with function type.

.section baz, "xr"
.def X
.scl 2;
.type 32;
.endef
.globl X
X:
mov Y-X+42, %eax
retl

.def Y
.scl 2;
.type 32;
.endef
.globl Y
Y:
retl
Expand All @@ -25,11 +30,6 @@ _foobar: # @foobar
# %bb.0:
ret

.globl _baz
_baz:
calll _foobar
retl

.data
.globl _rust_crate # @rust_crate
.align 4
Expand All @@ -39,15 +39,6 @@ _rust_crate:
.long _foobar-_rust_crate
.long _foobar-_rust_crate

// Even though _baz and _foobar are in the same .text section, we keep the
// relocation for compatibility with the VC linker's /guard:cf and /incremental
// flags, even on mingw.

// CHECK: Name: .text
// CHECK: Relocations [
// CHECK-NEXT: 0x12 IMAGE_REL_I386_REL32 _foobar
// CHECK-NEXT: ]

// CHECK: Name: .data
// CHECK: Relocations [
// CHECK-NEXT: 0x4 IMAGE_REL_I386_DIR32 _foobar
Expand Down

0 comments on commit 05848b6

Please sign in to comment.