Skip to content

Commit

Permalink
[asan] Fixed link error by setting jump symbol to R_X86_64_PLT32.
Browse files Browse the repository at this point in the history
Fixing this link error:
ld: error: relocation R_X86_64_PC32 cannot be used against symbol __asan_report_load...; recompile with -fPIC

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D109183
  • Loading branch information
kstoimenov committed Sep 2, 2021
1 parent 04ed6e7 commit cf53c6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/X86MCInstLower.cpp
Expand Up @@ -1526,7 +1526,8 @@ void X86AsmPrinter::emitAsanReportError(Module &M, unsigned Reg,
STI);
OutStreamer->emitInstruction(
MCInstBuilder(X86::JMP_1)
.addExpr(MCSymbolRefExpr::create(ReportError, OutContext)),
.addExpr(MCSymbolRefExpr::create(ReportError, MCSymbolRefExpr::VK_PLT,
OutContext)),
STI);
}

Expand Down
10 changes: 5 additions & 5 deletions llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
Expand Up @@ -166,7 +166,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: jl [[RET]]
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store1
; CHECK-NEXT: jmp __asan_report_store1@PLT

; CHECK: .type __asan_check_store2_rn[[RN2]],@function
; CHECK-NEXT: .weak __asan_check_store2_rn[[RN2]]
Expand All @@ -188,7 +188,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: jl [[RET]]
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store2
; CHECK-NEXT: jmp __asan_report_store2@PLT

; CHECK: .type __asan_check_store4_rn[[RN4]],@function
; CHECK-NEXT: .weak __asan_check_store4_rn[[RN4]]
Expand All @@ -210,7 +210,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: jl [[RET]]
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store4
; CHECK-NEXT: jmp __asan_report_store4@PLT

; CHECK: .type __asan_check_store8_rn[[RN8]],@function
; CHECK-NEXT: .weak __asan_check_store8_rn[[RN8]]
Expand All @@ -224,7 +224,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: retq
; CHECK-NEXT: [[FAIL]]:
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store8
; CHECK-NEXT: jmp __asan_report_store8@PLT

; CHECK: .type __asan_check_store16_rn[[RN16]],@function
; CHECK-NEXT: .weak __asan_check_store16_rn[[RN16]]
Expand All @@ -238,6 +238,6 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: retq
; CHECK-NEXT: [[FAIL]]:
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store16
; CHECK-NEXT: jmp __asan_report_store16@PLT

declare void @llvm.asan.check.memaccess(i8*, i32 immarg)
10 changes: 5 additions & 5 deletions llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
Expand Up @@ -172,7 +172,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: jl [[RET]]
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store1
; CHECK-NEXT: jmp __asan_report_store1@PLT

; CHECK: .type __asan_check_store2_rn[[RN2]],@function
; CHECK-NEXT: .weak __asan_check_store2_rn[[RN2]]
Expand All @@ -195,7 +195,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: jl [[RET]]
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store2
; CHECK-NEXT: jmp __asan_report_store2@PLT

; CHECK: .type __asan_check_store4_rn[[RN4]],@function
; CHECK-NEXT: .weak __asan_check_store4_rn[[RN4]]
Expand All @@ -218,7 +218,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: jl [[RET]]
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store4
; CHECK-NEXT: jmp __asan_report_store4@PLT

; CHECK: .type __asan_check_store8_rn[[RN8]],@function
; CHECK-NEXT: .weak __asan_check_store8_rn[[RN8]]
Expand All @@ -233,7 +233,7 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: retq
; CHECK-NEXT: [[FAIL]]:
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store8
; CHECK-NEXT: jmp __asan_report_store8@PLT

; CHECK: .type __asan_check_store16_rn[[RN16]],@function
; CHECK-NEXT: .weak __asan_check_store16_rn[[RN16]]
Expand All @@ -248,6 +248,6 @@ define void @load16(i128* nocapture readonly %x) {
; CHECK-NEXT: retq
; CHECK-NEXT: [[FAIL]]:
; CHECK-NEXT: movq [[REG:.*]], %rdi
; CHECK-NEXT: jmp __asan_report_store16
; CHECK-NEXT: jmp __asan_report_store16@PLT

declare void @llvm.asan.check.memaccess(i8*, i32 immarg)

0 comments on commit cf53c6c

Please sign in to comment.