[llvm] r258329 - Accept subtractions involving a weak symbol.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 20 10:57:48 PST 2016
Author: rafael
Date: Wed Jan 20 12:57:48 2016
New Revision: 258329
URL: http://llvm.org/viewvc/llvm-project?rev=258329&view=rev
Log:
Accept subtractions involving a weak symbol.
When a symbol S shows up in an expression in assembly there are two
possible interpretations
* The expression is referring to the value of S in this file.
* The expression is referring to the value after symbol resolution.
In the first case the assembler can reason about the value and try to
produce a relocation.
In the second case, that is only possible if the symbol cannot be
preempted.
Assemblers are not very consistent about which interpretation gets used.
This changes MC to agree with GAS in the case of an expression of the
form "Sym - WeakSym".
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/test/MC/AArch64/error-location.s
llvm/trunk/test/MC/ARM/error-location.s
llvm/trunk/test/MC/ELF/relocation.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=258329&r1=258328&r2=258329&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Jan 20 12:57:48 2016
@@ -655,12 +655,6 @@ void ELFObjectWriter::recordRelocation(M
return;
}
- if (::isWeak(SymB)) {
- Ctx.reportError(Fixup.getLoc(),
- "Cannot represent a subtraction with a weak symbol");
- return;
- }
-
uint64_t SymBOffset = Layout.getSymbolOffset(SymB);
uint64_t K = SymBOffset - FixupOffset;
IsPCRel = true;
Modified: llvm/trunk/test/MC/AArch64/error-location.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/error-location.s?rev=258329&r1=258328&r2=258329&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/error-location.s (original)
+++ llvm/trunk/test/MC/AArch64/error-location.s Wed Jan 20 12:57:48 2016
@@ -16,9 +16,6 @@
// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot represent a difference across sections
.word x_a - y_a
-// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot represent a subtraction with a weak symbol
- .word a - w
-
// CHECK: <unknown>:0: error: expression could not be evaluated
.set v1, -undef
Modified: llvm/trunk/test/MC/ARM/error-location.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/error-location.s?rev=258329&r1=258328&r2=258329&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/error-location.s (original)
+++ llvm/trunk/test/MC/ARM/error-location.s Wed Jan 20 12:57:48 2016
@@ -16,9 +16,6 @@
@ CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot represent a difference across sections
.word x_a - y_a
-@ CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot represent a subtraction with a weak symbol
- .word a - w
-
@ CHECK: <unknown>:0: error: expression could not be evaluated
.set v1, -undef
Modified: llvm/trunk/test/MC/ELF/relocation.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/relocation.s?rev=258329&r1=258328&r2=258329&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relocation.s (original)
+++ llvm/trunk/test/MC/ELF/relocation.s Wed Jan 20 12:57:48 2016
@@ -63,6 +63,11 @@ pr24486:
.code16
call pr23771
+ .weak weak_sym
+weak_sym:
+ .long pr23272-weak_sym
+
+
// CHECK: Section {
// CHECK: Name: .rela.text
// CHECK: Relocations [
@@ -101,5 +106,6 @@ pr24486:
// CHECK-NEXT: 0xDC R_X86_64_PLT32 foo 0x0
// CHECK-NEXT: 0xF0 R_X86_64_32 .text 0xF0
// CHECK-NEXT: 0xF5 R_X86_64_PC16 pr23771 0xFFFFFFFFFFFFFFFE
+// CHECK-NEXT: 0xF7 R_X86_64_PC32 pr23272 0x0
// CHECK-NEXT: ]
// CHECK-NEXT: }
More information about the llvm-commits
mailing list