|
| 1 | +From 4370214628487ac8495f963ae05960b5ecc31103 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jameson Nash < [email protected]> |
| 3 | +Date: Thu, 12 Sep 2019 11:45:07 -0400 |
| 4 | +Subject: [PATCH] Revert "[MC] Always emit relocations for same-section |
| 5 | + function references" |
| 6 | + |
| 7 | +This reverts commit 9232972575cafac29c3e4817c8714c9aca0e8585. |
| 8 | +--- |
| 9 | + lib/MC/WinCOFFObjectWriter.cpp | 12 +++++------- |
| 10 | + test/MC/COFF/diff.s | 25 ++++++++----------------- |
| 11 | + 2 files changed, 13 insertions(+), 24 deletions(-) |
| 12 | + |
| 13 | +diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp |
| 14 | +index 9ffecd99df6..0214161e03c 100644 |
| 15 | +--- a/lib/MC/WinCOFFObjectWriter.cpp |
| 16 | ++++ b/lib/MC/WinCOFFObjectWriter.cpp |
| 17 | +@@ -690,14 +690,12 @@ void WinCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm, |
| 18 | + bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( |
| 19 | + const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, |
| 20 | + bool InSet, bool IsPCRel) const { |
| 21 | +- // Don't drop relocations between functions, even if they are in the same text |
| 22 | +- // section. Multiple Visual C++ linker features depend on having the |
| 23 | +- // relocations present. The /INCREMENTAL flag will cause these relocations to |
| 24 | +- // point to thunks, and the /GUARD:CF flag assumes that it can use relocations |
| 25 | +- // to approximate the set of all address taken functions. LLD's implementation |
| 26 | +- // of /GUARD:CF also relies on the existance of these relocations. |
| 27 | ++ // MS LINK expects to be able to replace all references to a function with a |
| 28 | ++ // thunk to implement their /INCREMENTAL feature. Make sure we don't optimize |
| 29 | ++ // away any relocations to functions. |
| 30 | + uint16_t Type = cast<MCSymbolCOFF>(SymA).getType(); |
| 31 | +- if ((Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION) |
| 32 | ++ if (Asm.isIncrementalLinkerCompatible() && |
| 33 | ++ (Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION) |
| 34 | + return false; |
| 35 | + return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB, |
| 36 | + InSet, IsPCRel); |
| 37 | +diff --git a/test/MC/COFF/diff.s b/test/MC/COFF/diff.s |
| 38 | +index f89e4ed8901..d68e628577b 100644 |
| 39 | +--- a/test/MC/COFF/diff.s |
| 40 | ++++ b/test/MC/COFF/diff.s |
| 41 | +@@ -1,14 +1,19 @@ |
| 42 | + // RUN: llvm-mc -filetype=obj -triple i686-pc-mingw32 %s | llvm-readobj -s -sr -sd | FileCheck %s |
| 43 | + |
| 44 | +-// COFF resolves differences between labels in the same section, unless that |
| 45 | +-// label is declared with function type. |
| 46 | +- |
| 47 | + .section baz, "xr" |
| 48 | ++ .def X |
| 49 | ++ .scl 2; |
| 50 | ++ .type 32; |
| 51 | ++ .endef |
| 52 | + .globl X |
| 53 | + X: |
| 54 | + mov Y-X+42, %eax |
| 55 | + retl |
| 56 | + |
| 57 | ++ .def Y |
| 58 | ++ .scl 2; |
| 59 | ++ .type 32; |
| 60 | ++ .endef |
| 61 | + .globl Y |
| 62 | + Y: |
| 63 | + retl |
| 64 | +@@ -25,11 +30,6 @@ _foobar: # @foobar |
| 65 | + # %bb.0: |
| 66 | + ret |
| 67 | + |
| 68 | +- .globl _baz |
| 69 | +-_baz: |
| 70 | +- calll _foobar |
| 71 | +- retl |
| 72 | +- |
| 73 | + .data |
| 74 | + .globl _rust_crate # @rust_crate |
| 75 | + .align 4 |
| 76 | +@@ -39,15 +39,6 @@ _rust_crate: |
| 77 | + .long _foobar-_rust_crate |
| 78 | + .long _foobar-_rust_crate |
| 79 | + |
| 80 | +-// Even though _baz and _foobar are in the same .text section, we keep the |
| 81 | +-// relocation for compatibility with the VC linker's /guard:cf and /incremental |
| 82 | +-// flags, even on mingw. |
| 83 | +- |
| 84 | +-// CHECK: Name: .text |
| 85 | +-// CHECK: Relocations [ |
| 86 | +-// CHECK-NEXT: 0x12 IMAGE_REL_I386_REL32 _foobar |
| 87 | +-// CHECK-NEXT: ] |
| 88 | +- |
| 89 | + // CHECK: Name: .data |
| 90 | + // CHECK: Relocations [ |
| 91 | + // CHECK-NEXT: 0x4 IMAGE_REL_I386_DIR32 _foobar |
| 92 | +-- |
| 93 | +2.17.1 |
| 94 | + |
0 commit comments