[llvm] cf53c6c - [asan] Fixed link error by setting jump symbol to R_X86_64_PLT32.

Kirill Stoimenov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 14:51:41 PDT 2021


Author: Kirill Stoimenov
Date: 2021-09-02T21:50:56Z
New Revision: cf53c6c9710617ea465863e117dda695af2c3ebb

URL: https://github.com/llvm/llvm-project/commit/cf53c6c9710617ea465863e117dda695af2c3ebb
DIFF: https://github.com/llvm/llvm-project/commit/cf53c6c9710617ea465863e117dda695af2c3ebb.diff

LOG: [asan] Fixed link error by setting jump symbol to R_X86_64_PLT32.

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

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86MCInstLower.cpp
    llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
    llvm/test/CodeGen/X86/asan-check-memaccess-or.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp
index e827afef848bd..d49b99eff914a 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -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);
 }
 

diff  --git a/llvm/test/CodeGen/X86/asan-check-memaccess-add.ll b/llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
index 04d45d4e223ec..40cd8f7f91975 100644
--- a/llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
+++ b/llvm/test/CodeGen/X86/asan-check-memaccess-add.ll
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store2_rn[[RN2]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store2_rn[[RN2]]
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store4_rn[[RN4]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store4_rn[[RN4]]
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store8_rn[[RN8]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store8_rn[[RN8]]
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store16_rn[[RN16]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store16_rn[[RN16]]
@@ -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 at PLT
 
 declare void @llvm.asan.check.memaccess(i8*, i32 immarg)

diff  --git a/llvm/test/CodeGen/X86/asan-check-memaccess-or.ll b/llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
index e3f7eb3e9926f..4b2e6a80e87a3 100644
--- a/llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
+++ b/llvm/test/CodeGen/X86/asan-check-memaccess-or.ll
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store2_rn[[RN2]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store2_rn[[RN2]]
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store4_rn[[RN4]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store4_rn[[RN4]]
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store8_rn[[RN8]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store8_rn[[RN8]]
@@ -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 at PLT
 
 ; CHECK:              .type   __asan_check_store16_rn[[RN16]], at function
 ; CHECK-NEXT:         .weak   __asan_check_store16_rn[[RN16]]
@@ -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 at PLT
 
 declare void @llvm.asan.check.memaccess(i8*, i32 immarg)


        


More information about the llvm-commits mailing list