[PATCH] D88625: [MC] Redirect fixup symbol to the aliasee (if exists)
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 21:31:35 PDT 2020
MaskRay updated this revision to Diff 297384.
MaskRay edited the summary of this revision.
MaskRay added a comment.
Fix clang-tidy issues
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88625/new/
https://reviews.llvm.org/D88625
Files:
llvm/lib/MC/MCAssembler.cpp
llvm/test/MC/ELF/relocation-alias.s
Index: llvm/test/MC/ELF/relocation-alias.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/relocation-alias.s
@@ -0,0 +1,38 @@
+# RUN: llvm-mc -filetype=obj -triple x86_64 %s -o %t
+# RUN: llvm-objdump -dr %t | FileCheck %s
+# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYM
+
+## If a fixup symbol is equated to an undefined symbol, convert the fixup
+## to be against the target symbol.
+# CHECK: callq {{.*}}
+# CHECK-NEXT: R_X86_64_PLT32 __GI_memcpy-0x4
+# CHECK: movabsq $0, %rax
+# CHECK-NEXT: R_X86_64_64 __GI_memcpy+0x2
+memcpy = __GI_memcpy
+call memcpy at PLT
+movabsq $memcpy+2, %rax
+
+## NOTE: GNU as redirects memcpy_plus_1.
+# CHECK: callq {{.*}}
+# CHECK-NEXT: R_X86_64_PLT32 memcpy_plus_1
+memcpy_plus_1 = __GI_memcpy+1
+call memcpy_plus_1 at PLT
+
+# CHECK: movabsq $0, %rbx
+# CHECK-NEXT: R_X86_64_64 data_alias
+.globl data_alias
+.set data_alias, data
+movabsq $data_alias, %rbx
+
+.data
+.byte 0
+.globl data
+data:
+
+## Redirected symbols do not have a symbol table entry.
+# SYM: NOTYPE LOCAL DEFAULT UND
+# SYM-NEXT: NOTYPE GLOBAL DEFAULT UND __GI_memcpy
+# SYM-NEXT: NOTYPE GLOBAL DEFAULT 4 data
+# SYM-NEXT: NOTYPE GLOBAL DEFAULT 4 data_alias
+# SYM-NEXT: NOTYPE GLOBAL DEFAULT UND memcpy_plus_1
+# SYM-NOT: {{.}}
Index: llvm/lib/MC/MCAssembler.cpp
===================================================================
--- llvm/lib/MC/MCAssembler.cpp
+++ llvm/lib/MC/MCAssembler.cpp
@@ -216,6 +216,21 @@
return true;
}
}
+ if (const MCSymbolRefExpr *RefA = Target.getSymA()) {
+ // If SymA is equated to an expression with an undefined symbol, GNU as
+ // converts the fixup to be against the target symbol. We only support a
+ // simple form `alias = aliasee` (MCSymbolRefExpr).
+ const auto &SymA = RefA->getSymbol();
+ if (SymA.isVariable()) {
+ if (const auto *SRE = dyn_cast<MCSymbolRefExpr>(SymA.getVariableValue()))
+ if (SRE->getSymbol().isUndefined() &&
+ SRE->getKind() != MCSymbolRefExpr::VK_WEAKREF) {
+ Target = MCValue::get(
+ MCSymbolRefExpr::create(&SRE->getSymbol(), RefA->getKind(), Ctx),
+ Target.getSymB(), Target.getConstant(), Target.getRefKind());
+ }
+ }
+ }
assert(getBackendPtr() && "Expected assembler backend");
bool IsTarget = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88625.297384.patch
Type: text/x-patch
Size: 2451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201010/fac935f7/attachment.bin>
More information about the llvm-commits
mailing list