forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: (Restores r327459 with handling for old plugin-api.h) Utilize new gold plugin api interface for obtaining --wrap option arguments, and LTO API handling (added for --wrap support in lld LTO), to mark symbols so that LTO does not optimize them inappropriately. Note the test cases will be in a new gold test subdirectory that is dependent on the next release of gold which will contain the new interfaces. Reviewers: pcc, tmsriram Subscribers: mehdi_amini, llvm-commits, inglorion Differential Revision: https://reviews.llvm.org/D44235 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327506 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
1 parent
7c95150
commit ead8765
Showing
5 changed files
with
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define hidden void @bar() { | ||
ret void | ||
} | ||
|
||
define hidden void @__real_bar() { | ||
ret void | ||
} | ||
|
||
define hidden void @__wrap_bar() { | ||
ret void | ||
} |
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,28 @@ | ||
import re | ||
import subprocess | ||
|
||
def is_gold_v1_16_linker_available(): | ||
|
||
if not config.gold_executable: | ||
return False | ||
try: | ||
ld_cmd = subprocess.Popen([config.gold_executable, '-v'], | ||
stdout = subprocess.PIPE, | ||
stderr = subprocess.PIPE) | ||
ld_out, _ = ld_cmd.communicate() | ||
ld_out = ld_out.decode() | ||
except: | ||
return False | ||
|
||
match = re.search(r'GNU gold \(.*\) (\d+)\.(\d+)', ld_out) | ||
if not match: | ||
return False | ||
major = int(match.group(1)) | ||
minor = int(match.group(2)) | ||
if major < 1 or (major == 1 and minor < 16): | ||
return False | ||
|
||
return True | ||
|
||
if not is_gold_v1_16_linker_available(): | ||
config.unsupported = True |
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,42 @@ | ||
; LTO | ||
; RUN: llvm-as %s -o %t.o | ||
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext %t.o -o %t.out -wrap=bar -plugin-opt=save-temps | ||
; RUN: llvm-readobj -t %t.out | FileCheck %s | ||
; RUN: cat %t.out.resolution.txt | FileCheck -check-prefix=RESOLS %s | ||
|
||
; ThinLTO | ||
; RUN: opt -module-summary %s -o %t.o | ||
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext %t.o -o %t.out -wrap=bar -plugin-opt=save-temps | ||
; RUN: llvm-readobj -t %t.out | FileCheck %s | ||
; RUN: cat %t.out.resolution.txt | FileCheck -check-prefix=RESOLS %s | ||
|
||
; CHECK: Name: __wrap_bar | ||
; CHECK-NEXT: Value: | ||
; CHECK-NEXT: Size: | ||
; CHECK-NEXT: Binding: Global | ||
; CHECK-NEXT: Type: Function | ||
|
||
; Make sure that the 'r' (linker redefined) bit is set for bar and __real_bar | ||
; in the resolutions file, and that the 'x' (visible to regular obj) bit is set | ||
; for bar and __wrap_bar. | ||
; RESOLS: ,bar,lxr | ||
; RESOLS: ,__wrap_bar,plx | ||
; RESOLS: ,__real_bar,plr | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
declare void @bar() | ||
|
||
define void @_start() { | ||
call void @bar() | ||
ret void | ||
} | ||
|
||
define void @__wrap_bar() { | ||
ret void | ||
} | ||
|
||
define void @__real_bar() { | ||
ret void | ||
} |
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,55 @@ | ||
; LTO | ||
; This doesn't currently work with gold, because it does not apply defsym | ||
; renaming to symbols in the same module (apparently by design for consistency | ||
; with GNU ld). Because regular LTO hands back a single object file to gold, | ||
; it doesn't perform the desired defsym renaming. This isn't an issue with | ||
; ThinLTO which hands back multiple native objects to gold. For regular | ||
; LTO defsym handling, gold will need a fix (not the gold plugin). | ||
; RUN-TODO: llvm-as %s -o %t.o | ||
; RUN-TODO: llvm-as %S/Inputs/wrap-bar.ll -o %t1.o | ||
; RUN-TODO: %gold -plugin %llvmshlibdir/LLVMgold%shlibext %t.o %t1.o -shared -o %t.so -wrap=bar | ||
; RUN-TODO: llvm-objdump -d %t.so | FileCheck %s | ||
; RUN-TODO: llvm-readobj -t %t.so | FileCheck -check-prefix=BIND %s | ||
|
||
; ThinLTO | ||
; RUN: opt -module-summary %s -o %t.o | ||
; RUN: opt -module-summary %S/Inputs/wrap-bar.ll -o %t1.o | ||
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext %t.o %t1.o -shared -o %t.so -wrap=bar | ||
; RUN: llvm-objdump -d %t.so | FileCheck %s -check-prefix=THIN | ||
; RUN: llvm-readobj -t %t.so | FileCheck -check-prefix=BIND %s | ||
|
||
; Make sure that calls in foo() are not eliminated and that bar is | ||
; routed to __wrap_bar and __real_bar is routed to bar. | ||
|
||
; CHECK: foo: | ||
; CHECK-NEXT: pushq %rax | ||
; CHECK-NEXT: callq{{.*}}<__wrap_bar> | ||
; CHECK-NEXT: callq{{.*}}<bar> | ||
|
||
; THIN: foo: | ||
; THIN-NEXT: pushq %rax | ||
; THIN-NEXT: callq{{.*}}<__wrap_bar> | ||
; THIN-NEXT: popq %rax | ||
; THIN-NEXT: jmp{{.*}}<bar> | ||
|
||
; Check that bar and __wrap_bar retain their original binding. | ||
; BIND: Name: bar | ||
; BIND-NEXT: Value: | ||
; BIND-NEXT: Size: | ||
; BIND-NEXT: Binding: Local | ||
; BIND: Name: __wrap_bar | ||
; BIND-NEXT: Value: | ||
; BIND-NEXT: Size: | ||
; BIND-NEXT: Binding: Local | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
declare void @bar() | ||
declare void @__real_bar() | ||
|
||
define void @foo() { | ||
call void @bar() | ||
call void @__real_bar() | ||
ret void | ||
} |
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