-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[lld-macho] Implement -load_hidden"
This flag was introduced in ld64-609. It instructs the linker to link to a static library while treating its symbols as if they had hidden visibility. This is useful when building a dylib that links to static libraries but we don't want the symbols from those to be exported. Closes #51505 This reland adds bitcode file handling, so we won't get any compile errors due to BitcodeFile::forceHidden being unused. Differential Revision: https://reviews.llvm.org/D130473
- Loading branch information
Showing
8 changed files
with
160 additions
and
31 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,28 @@ | ||
; REQUIRES: x86 | ||
; RUN: rm -rf %t; split-file %s %t | ||
; RUN: llvm-as %t/archive.ll -o %t/archive.o | ||
; RUN: llvm-ar rcs %t/archive.a %t/archive.o | ||
; RUN: llvm-as %t/obj.ll -o %t/obj.o | ||
|
||
; RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/archive.a -o %t/test.dylib | ||
; RUN: llvm-nm %t/test.dylib | FileCheck %s | ||
; CHECK: t _foo | ||
|
||
;--- archive.ll | ||
target triple = "x86_64-apple-macosx10.15.0" | ||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
|
||
define void @foo() noinline optnone { | ||
ret void | ||
} | ||
|
||
;--- obj.ll | ||
target triple = "x86_64-apple-macosx10.15.0" | ||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
|
||
declare void @foo(); | ||
|
||
define void @main() { | ||
call void @foo() | ||
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,72 @@ | ||
# REQUIRES: x86 | ||
# RUN: rm -rf %t; split-file %s %t | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-foo.s -o %t/archive-foo.o | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-baz.s -o %t/archive-baz.o | ||
# RUN: llvm-ar rcs %t/foo.a %t/archive-foo.o | ||
# RUN: llvm-ar rcs %t/baz.a %t/archive-baz.o | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/obj.s -o %t/obj.o | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/obj-bar.s -o %t/obj-bar.o | ||
|
||
# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a -o %t/test.dylib | ||
# RUN: llvm-nm %t/test.dylib | FileCheck %s | ||
# CHECK-DAG: t _foo | ||
# CHECK-DAG: d _bar | ||
|
||
## If an archive has already been loaded without -load_hidden earlier in the command line, | ||
## -load_hidden does not have an effect. | ||
# RUN: %lld -dylib -lSystem %t/obj.o %t/foo.a -load_hidden %t/foo.a -o %t/test-regular-then-hidden.dylib | ||
# RUN: llvm-nm %t/test-regular-then-hidden.dylib | FileCheck %s --check-prefix=REGULAR-THEN-HIDDEN | ||
# REGULAR-THEN-HIDDEN-DAG: T _foo | ||
# REGULAR-THEN-HIDDEN-DAG: D _bar | ||
|
||
## If -load_hidden comes first, the symbols will have hidden visibility. | ||
# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a %t/foo.a -o %t/test-hidden-then-regular.dylib | ||
# RUN: llvm-nm %t/test-hidden-then-regular.dylib | FileCheck %s --check-prefix=HIDDEN-THEN-REGULAR | ||
# HIDDEN-THEN-REGULAR-DAG: t _foo | ||
# HIDDEN-THEN-REGULAR-DAG: d _bar | ||
|
||
## If both -load_hidden and -force_load are specified, the earlier one will have an effect. | ||
# RUN: %lld -dylib -lSystem %t/obj.o %t/foo.a -force_load %t/baz.a -load_hidden %t/baz.a -o %t/test-force-then-hidden.dylib | ||
# RUN: llvm-nm %t/test-force-then-hidden.dylib | FileCheck %s --check-prefix=FORCE-THEN-HIDDEN | ||
# FORCE-THEN-HIDDEN: T _baz | ||
# RUN: %lld -dylib -lSystem %t/obj.o %t/foo.a -load_hidden %t/baz.a -force_load %t/baz.a -o %t/test-hidden-then-force.dylib | ||
# RUN: llvm-nm %t/test-hidden-then-force.dylib | FileCheck %s --check-prefix=HIDDEN-THEN-FORCE | ||
# HIDDEN-THEN-FORCE-NOT: _baz | ||
|
||
## -load_hidden does not cause the library to be loaded eagerly. | ||
# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a -load_hidden %t/baz.a -o %t/test-lazy.dylib | ||
# RUN: llvm-nm %t/test-lazy.dylib | FileCheck %s --check-prefix=LAZY | ||
# LAZY-NOT: _baz | ||
|
||
## Specifying the same library twice is fine. | ||
# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a -load_hidden %t/foo.a -o %t/test-twice.dylib | ||
# RUN: llvm-nm %t/test-twice.dylib | FileCheck %s --check-prefix=TWICE | ||
# TWICE-DAG: t _foo | ||
# TWICE-DAG: d _bar | ||
|
||
## -load_hidden causes the symbols to have "private external" visibility, so duplicate definitions | ||
## are not allowed. | ||
# RUN: not %lld -dylib -lSystem %t/obj.o %t/obj-bar.o -load_hidden %t/foo.a 2>&1 | FileCheck %s --check-prefix=DUP | ||
# DUP: error: duplicate symbol: _bar | ||
|
||
#--- archive-foo.s | ||
.globl _foo | ||
_foo: | ||
|
||
.data | ||
.globl _bar | ||
_bar: | ||
|
||
#--- archive-baz.s | ||
.globl _baz | ||
_baz: | ||
|
||
#--- obj-bar.s | ||
.data | ||
.globl _bar | ||
_bar: | ||
|
||
#--- obj.s | ||
.globl _test | ||
_test: | ||
call _foo |
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