Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[x86] Implement a tagged-globals backend feature.
The feature tells the backend to allow tags in the upper bits of global variable addresses. These tags will be ignored by upcoming CPUs with the Intel LAM feature but may be used in instrumentation passes (e.g., HWASan). This patch implements the feature by using @GOTPCREL relocations instead of direct references to the locally defined global. Thus the full tagged address can be loaded by a single instruction: movq global@GOTPCREL(%rip), %rax Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D111343
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; RUN: llc --relocation-model=pic < %s | FileCheck %s | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
@global = external global i32 | ||
declare void @func() | ||
|
||
define i32* @global_addr() #0 { | ||
; CHECK-LABEL: global_addr: | ||
; CHECK: movq global@GOTPCREL(%rip), %rax | ||
; CHECK: retq | ||
|
||
ret i32* @global | ||
} | ||
|
||
define i32 @global_load() #0 { | ||
; CHECK-LABEL: global_load: | ||
; CHECK: movq global@GOTPCREL(%rip), [[REG:%r[0-9a-z]+]] | ||
; CHECK: movl ([[REG]]), %eax | ||
; CHECK: retq | ||
|
||
%load = load i32, i32* @global | ||
ret i32 %load | ||
} | ||
|
||
define void @global_store() #0 { | ||
; CHECK-LABEL: global_store: | ||
; CHECK: movq global@GOTPCREL(%rip), [[REG:%r[0-9a-z]+]] | ||
; CHECK: movl $0, ([[REG]]) | ||
; CHECK: retq | ||
|
||
store i32 0, i32* @global | ||
ret void | ||
} | ||
|
||
define void ()* @func_addr() #0 { | ||
; CHECK-LABEL: func_addr: | ||
; CHECK: movq func@GOTPCREL(%rip), %rax | ||
; CHECK: retq | ||
|
||
ret void ()* @func | ||
} | ||
|
||
attributes #0 = { "target-features"="+tagged-globals" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; RUN: llc --relocation-model=static < %s | FileCheck %s | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
@global = external dso_local global i32 | ||
declare dso_local void @func() | ||
|
||
define i32* @global_addr() #0 { | ||
; CHECK-LABEL: global_addr: | ||
; CHECK: movq global@GOTPCREL(%rip), %rax | ||
; CHECK: retq | ||
|
||
ret i32* @global | ||
} | ||
|
||
define i32 @global_load() #0 { | ||
; CHECK-LABEL: global_load: | ||
; CHECK: movq global@GOTPCREL(%rip), [[REG:%r[0-9a-z]+]] | ||
; CHECK: movl ([[REG]]), %eax | ||
; CHECK: retq | ||
|
||
%load = load i32, i32* @global | ||
ret i32 %load | ||
} | ||
|
||
define void @global_store() #0 { | ||
; CHECK-LABEL: global_store: | ||
; CHECK: movq global@GOTPCREL(%rip), [[REG:%r[0-9a-z]+]] | ||
; CHECK: movl $0, ([[REG]]) | ||
; CHECK: retq | ||
|
||
store i32 0, i32* @global | ||
ret void | ||
} | ||
|
||
define void ()* @func_addr() #0 { | ||
; CHECK-LABEL: func_addr: | ||
; CHECK: movl $func, %eax | ||
; CHECK: retq | ||
|
||
ret void ()* @func | ||
} | ||
|
||
attributes #0 = { "target-features"="+tagged-globals" } |