Skip to content

Commit bfd0f01

Browse files
committed
Don't produce relocations for a difference in a section with no symbols.
We were producing a relocation for ---------------- .section foo,bar La: Lb: .long La-Lb -------------- but not for --------------------- .section foo,bar zed: La: Lb: .long La-Lb ---------------- This patch handles the case where both fragments are part of the first atom in a section and there is no corresponding symbol to that atom. This fixes pr21328. llvm-svn: 221304
1 parent 4f5cbc1 commit bfd0f01

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,19 +726,18 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
726726
return false;
727727
}
728728

729+
// If they are not in the same section, we can't compute the diff.
730+
if (&SecA != &SecB)
731+
return false;
732+
729733
const MCFragment *FA = Asm.getSymbolData(SA).getFragment();
730734

731735
// Bail if the symbol has no fragment.
732736
if (!FA)
733737
return false;
734738

735739
A_Base = FA->getAtom();
736-
if (!A_Base)
737-
return false;
738-
739740
B_Base = FB.getAtom();
740-
if (!B_Base)
741-
return false;
742741

743742
// If the atoms are the same, they are guaranteed to have the same address.
744743
if (A_Base == B_Base)

llvm/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ L_var2:
1212
// CHECK-NEXT: Section __data {
1313
// CHECK-NEXT: 0x4 0 2 0 X86_64_RELOC_SUBTRACTOR 0 0x2
1414
// CHECK-NEXT: 0x4 0 2 0 X86_64_RELOC_UNSIGNED 0 0x2
15-
// CHECK-NEXT: 0x0 0 2 0 X86_64_RELOC_SUBTRACTOR 0 0x2
16-
// CHECK-NEXT: 0x0 0 2 0 X86_64_RELOC_UNSIGNED 0 0x2
1715
// CHECK-NEXT: }
1816
// CHECK-NEXT: ]

llvm/test/MC/X86/reloc-macho.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: llvm-mc -filetype=obj -triple x86_64-apple-darwin %s -o - | llvm-readobj -r | FileCheck %s
2+
3+
// CHECK: Relocations [
4+
// CHECK-NEXT: ]
5+
6+
.section foo,bar
7+
La:
8+
Lb:
9+
.long La-Lb

0 commit comments

Comments
 (0)