-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LTO][MC] Discard non-prevailing defined symbols in module-level asse…
…mbly This is the alternative approach to D96931. In LTO, for each module with inlineasm block, prepend directive ".lto_discard <sym>, <sym>*" to the beginning of the inline asm. ".lto_discard" is both a module inlineasm block marker and (optionally) provides a list of symbols to be discarded. In MC while emitting for inlineasm, discard symbol binding & symbol definitions according to ".lto_disard". Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D98762
- Loading branch information
Yuanfang Chen
committed
Mar 18, 2021
1 parent
2df65f8
commit b4a8c0e
Showing
8 changed files
with
231 additions
and
3 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
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,87 @@ | ||
; Check that non-prevailing symbols in module inline assembly are discarded | ||
; during regular LTO otherwise the final symbol binding could be wrong. | ||
|
||
; RUN: split-file %s %t | ||
; RUN: opt %t/t1.ll -o %t1 | ||
; RUN: opt %t/t2.ll -o %t2 | ||
; RUN: opt %t/t3.ll -o %t3 | ||
; RUN: opt %t/t4.ll -o %t4 | ||
|
||
; RUN: llvm-lto2 run -o %to1 -save-temps %t1 %t2 \ | ||
; RUN: -r %t1,foo,px \ | ||
; RUN: -r %t2,foo, \ | ||
; RUN: -r %t2,bar,pl | ||
; RUN: llvm-dis < %to1.0.0.preopt.bc | FileCheck %s --check-prefix=ASM1 | ||
; RUN: llvm-nm %to1.0 | FileCheck %s --check-prefix=SYM | ||
; RUN: llvm-objdump -d --disassemble-symbols=foo %to1.0 \ | ||
; RUN: | FileCheck %s --check-prefix=DEF | ||
|
||
; RUN: llvm-lto2 run -o %to2 -save-temps %t2 %t3 \ | ||
; RUN: -r %t2,foo, \ | ||
; RUN: -r %t2,bar,pl \ | ||
; RUN: -r %t3,foo,px | ||
; RUN: llvm-dis < %to2.0.0.preopt.bc | FileCheck %s --check-prefix=ASM2 | ||
; RUN: llvm-nm %to2.0 | FileCheck %s --check-prefix=SYM | ||
; RUN: llvm-objdump -d --disassemble-symbols=foo %to2.0 \ | ||
; RUN: | FileCheck %s --check-prefix=DEF | ||
|
||
; Check that ".symver" is properly handled. | ||
; RUN: llvm-lto2 run -o %to3 -save-temps %t4 \ | ||
; RUN: -r %t4,bar, \ | ||
; RUN: -r %t4,foo, \ | ||
; RUN: -r %t4,foo@@VER1,px | ||
; RUN: llvm-dis < %to3.0.0.preopt.bc | FileCheck %s --check-prefix=ASM3 | ||
|
||
; ASM1: module asm ".lto_discard foo" | ||
; ASM1-NEXT: module asm ".weak foo" | ||
; ASM1-NEXT: module asm ".equ foo,bar" | ||
|
||
; ASM2: module asm ".lto_discard foo" | ||
; ASM2-NEXT: module asm ".weak foo" | ||
; ASM2-NEXT: module asm ".equ foo,bar" | ||
; ASM2-NEXT: module asm ".lto_discard" | ||
; ASM2-NEXT: module asm " .global foo ; foo: leal 2(%rdi), %eax" | ||
|
||
; ASM3-NOT: module asm ".lto_discard foo" | ||
|
||
; SYM: T foo | ||
|
||
; DEF: leal 2(%rdi), %eax | ||
|
||
;--- t1.ll | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define dso_local i32 @foo(i32 %0) { | ||
%2 = add nsw i32 %0, 2 | ||
ret i32 %2 | ||
} | ||
|
||
;--- t2.ll | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
module asm ".weak foo" | ||
module asm ".equ foo,bar" | ||
|
||
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (i32)* @bar to i8*)], section "llvm.metadata" | ||
|
||
define internal i32 @bar(i32 %0) { | ||
%2 = add nsw i32 %0, 1 | ||
ret i32 %2 | ||
} | ||
|
||
;--- t3.ll | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
module asm " .global foo ; foo: leal 2(%rdi), %eax" | ||
|
||
;--- t4.ll | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
module asm ".global foo" | ||
module asm "foo: call bar" | ||
module asm ".symver foo,foo@@@VER1" | ||
module asm ".symver bar,bar@@@VER1" |
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,29 @@ | ||
; Check that | ||
; 1. ".lto_discard" works as module inlineasm marker and its argument symbols | ||
; are discarded. | ||
; 2. there is no reassignment error in the presence of ".lto_discard" | ||
; RUN: llc < %s | FileCheck %s | ||
|
||
; CHECK: .data | ||
; CHECK-NOT: .weak foo | ||
; CHECK-NOT: .set foo, bar | ||
; CHECK: .globl foo | ||
; CHECK: foo: | ||
; CHECK: .byte 1 | ||
|
||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
module asm ".lto_discard foo" | ||
module asm " .text" | ||
module asm "bar:" | ||
module asm " .data" | ||
module asm ".weak foo" | ||
module asm ".set foo, bar" | ||
module asm ".weak foo" | ||
module asm ".set foo, bar" | ||
|
||
module asm ".lto_discard" | ||
module asm ".globl foo" | ||
module asm "foo:" | ||
module asm " .byte 1" |
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,31 @@ | ||
// Check that ".lto_discard" ignores symbol assignments and attribute changes | ||
// for the specified symbols. | ||
// RUN: llvm-mc -triple x86_64 < %s | FileCheck %s | ||
|
||
// Check that ".lto_discard" only accepts identifiers. | ||
// RUN: not llvm-mc -filetype=obj -triple x86_64 --defsym ERR=1 %s 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=ERR | ||
|
||
// CHECK: .weak foo | ||
// CHECK: foo: | ||
// CHECK: .byte 1 | ||
// CHECK: .weak bar | ||
// CHECK: bar: | ||
// CHECK: .byte 2 | ||
|
||
.lto_discard foo | ||
.weak foo | ||
foo: | ||
.byte 1 | ||
|
||
.lto_discard | ||
.weak bar | ||
bar: | ||
.byte 2 | ||
|
||
|
||
.ifdef ERR | ||
.text | ||
# ERR: {{.*}}.s:[[#@LINE+1]]:14: error: expected identifier in directive | ||
.lto_discard 1 | ||
.endif |