2021-03-12 02:28:14 +08:00
|
|
|
# REQUIRES: x86
|
[lld-macho] Have tests default to targeting macos 10.15
D101114 enforced proper version checks, which exposed a variety of version
mismatch issues in our tests. We previously changed the test inputs to
target 10.0, which was the simpler thing to do, but we should really
just have our lit.local.cfg default to targeting 10.15, which is what is done
here. We're not likely to ever have proper support for the older versions
anyway, as that would require more work for unclear benefit; for instance,
llvm-mc seems to generate a different compact unwind format for older macOS
versions, which would cause our compact-unwind.s test to fail.
Targeting 10.15 by default causes the following behavioral changes:
* `__mh_execute_header` is now a section symbol instead of an absolute symbol
* LC_BUILD_VERSION gets emitted instead of LC_VERSION_MIN_MACOSX. The former is
32 bytes in size whereas the latter is 16 bytes, so a bunch of hardcoded
address offsets in our tests had to be updated.
* >= 10.6 executables are PIE by default
Note that this diff was stacked atop of a local revert of most of the test
changes in rG8c17a875150f8e736e8f9061ddf084397f45f4c5, to make review easier.
Reviewed By: #lld-macho, oontvoo
Differential Revision: https://reviews.llvm.org/D101119
2021-04-23 07:37:47 +08:00
|
|
|
# RUN: rm -rf %t; mkdir -p %t
|
2020-05-12 22:29:15 +08:00
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \
|
|
|
|
# RUN: -o %t/libhello.o
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
|
|
|
|
# RUN: -o %t/libgoodbye.o
|
2020-09-19 12:40:12 +08:00
|
|
|
# RUN: %lld -dylib \
|
2020-06-17 08:05:29 +08:00
|
|
|
# RUN: -install_name @executable_path/libhello.dylib %t/libhello.o \
|
|
|
|
# RUN: -o %t/libhello.dylib
|
2020-09-19 12:40:12 +08:00
|
|
|
# RUN: %lld -dylib \
|
2020-06-17 08:05:29 +08:00
|
|
|
# RUN: -install_name @executable_path/libgoodbye.dylib %t/libgoodbye.o \
|
|
|
|
# RUN: -o %t/libgoodbye.dylib
|
2020-05-12 22:29:15 +08:00
|
|
|
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink-lazy.o
|
2021-04-26 07:00:24 +08:00
|
|
|
# RUN: %lld -no_pie -data_const -o %t/dylink-lazy-no-pie \
|
2020-09-19 12:40:12 +08:00
|
|
|
# RUN: -L%t -lhello -lgoodbye %t/dylink-lazy.o -lSystem
|
2020-05-12 22:29:15 +08:00
|
|
|
|
|
|
|
## When looking at the __stubs section alone, we are unable to easily tell which
|
|
|
|
## symbol each entry points to. So we call objdump twice in order to get the
|
|
|
|
## disassembly of __text and the bind tables first, which allow us to check for
|
|
|
|
## matching entries in __stubs.
|
[lld-macho] Have tests default to targeting macos 10.15
D101114 enforced proper version checks, which exposed a variety of version
mismatch issues in our tests. We previously changed the test inputs to
target 10.0, which was the simpler thing to do, but we should really
just have our lit.local.cfg default to targeting 10.15, which is what is done
here. We're not likely to ever have proper support for the older versions
anyway, as that would require more work for unclear benefit; for instance,
llvm-mc seems to generate a different compact unwind format for older macOS
versions, which would cause our compact-unwind.s test to fail.
Targeting 10.15 by default causes the following behavioral changes:
* `__mh_execute_header` is now a section symbol instead of an absolute symbol
* LC_BUILD_VERSION gets emitted instead of LC_VERSION_MIN_MACOSX. The former is
32 bytes in size whereas the latter is 16 bytes, so a bunch of hardcoded
address offsets in our tests had to be updated.
* >= 10.6 executables are PIE by default
Note that this diff was stacked atop of a local revert of most of the test
changes in rG8c17a875150f8e736e8f9061ddf084397f45f4c5, to make review easier.
Reviewed By: #lld-macho, oontvoo
Differential Revision: https://reviews.llvm.org/D101119
2021-04-23 07:37:47 +08:00
|
|
|
# RUN: llvm-objdump -d --no-show-raw-insn --syms --rebase --bind --lazy-bind %t/dylink-lazy-no-pie > %t/objdump-no-pie
|
|
|
|
# RUN: llvm-objdump -D --no-show-raw-insn %t/dylink-lazy-no-pie >> %t/objdump-no-pie
|
|
|
|
# RUN: FileCheck %s --check-prefixes=CHECK,NO-PIE < %t/objdump-no-pie
|
|
|
|
|
|
|
|
# RUN: %lld -o %t/dylink-lazy -L%t -lhello -lgoodbye %t/dylink-lazy.o -lSystem
|
2021-03-12 02:28:14 +08:00
|
|
|
# RUN: llvm-objdump -d --no-show-raw-insn --syms --rebase --bind --lazy-bind %t/dylink-lazy > %t/objdump
|
|
|
|
# RUN: llvm-objdump -D --no-show-raw-insn %t/dylink-lazy >> %t/objdump
|
[lld-macho] Have tests default to targeting macos 10.15
D101114 enforced proper version checks, which exposed a variety of version
mismatch issues in our tests. We previously changed the test inputs to
target 10.0, which was the simpler thing to do, but we should really
just have our lit.local.cfg default to targeting 10.15, which is what is done
here. We're not likely to ever have proper support for the older versions
anyway, as that would require more work for unclear benefit; for instance,
llvm-mc seems to generate a different compact unwind format for older macOS
versions, which would cause our compact-unwind.s test to fail.
Targeting 10.15 by default causes the following behavioral changes:
* `__mh_execute_header` is now a section symbol instead of an absolute symbol
* LC_BUILD_VERSION gets emitted instead of LC_VERSION_MIN_MACOSX. The former is
32 bytes in size whereas the latter is 16 bytes, so a bunch of hardcoded
address offsets in our tests had to be updated.
* >= 10.6 executables are PIE by default
Note that this diff was stacked atop of a local revert of most of the test
changes in rG8c17a875150f8e736e8f9061ddf084397f45f4c5, to make review easier.
Reviewed By: #lld-macho, oontvoo
Differential Revision: https://reviews.llvm.org/D101119
2021-04-23 07:37:47 +08:00
|
|
|
# RUN: FileCheck %s --check-prefixes=CHECK,PIE < %t/objdump
|
2020-09-06 01:55:33 +08:00
|
|
|
|
2020-05-12 22:29:15 +08:00
|
|
|
# CHECK-LABEL: SYMBOL TABLE:
|
[lld/mac] Implement support for private extern symbols
Private extern symbols are used for things scoped to the linkage unit.
They cause duplicate symbol errors (so they're in the symbol table,
unlike TU-scoped truly local symbols), but they don't make it into the
export trie. They are created e.g. by compiling with
-fvisibility=hidden.
If two weak symbols have differing privateness, the combined symbol is
non-private external. (Example: inline functions and some TUs that
include the header defining it were built with
-fvisibility-inlines-hidden and some weren't).
A weak private external symbol implicitly has its "weak" dropped and
behaves like a regular strong private external symbol: Weak is an export
trie concept, and private symbols are not in the export trie.
If a weak and a strong symbol have different privateness, the strong
symbol wins.
If two common symbols have differing privateness, the larger symbol
wins. If they have the same size, the privateness of the symbol seen
later during the link wins (!) -- this is a bit lame, but it matches
ld64 and this behavior takes 2 lines less to implement than the less
surprising "result is non-private external), so match ld64.
(Example: `int a` in two .c files, both built with -fcommon,
one built with -fvisibility=hidden and one without.)
This also makes `__dyld_private` a true TU-local symbol, matching ld64.
To make this work, make the `const char*` StringRefZ ctor to correctly
set `size` (without this, writing the string table crashed when calling
getName() on the __dyld_private symbol).
Mention in CommonSymbol's comment that common symbols are now disabled
by default in clang.
Mention in -keep_private_externs's HelpText that the flag only has an
effect with `-r` (which we don't implement yet -- so this patch here
doesn't regress any behavior around -r + -keep_private_externs)). ld64
doesn't explicitly document it, but the commit text of
http://reviews.llvm.org/rL216146 does, and ld64's
OutputFile::buildSymbolTable() checks `_options.outputKind() ==
Options::kObjectFile` before calling `_options.keepPrivateExterns()`
(the only reference to that function).
Fixes PR48536.
Differential Revision: https://reviews.llvm.org/D93609
2020-12-18 02:30:18 +08:00
|
|
|
# CHECK: {{0*}}[[#%x, IMGLOADER:]] l {{.*}} __DATA,__data __dyld_private
|
2020-05-12 22:29:15 +08:00
|
|
|
|
|
|
|
# CHECK-LABEL: Disassembly of section __TEXT,__text:
|
|
|
|
# CHECK: callq 0x[[#%x, HELLO_STUB:]]
|
|
|
|
# CHECK-NEXT: callq 0x[[#%x, GOODBYE_STUB:]]
|
|
|
|
|
2020-09-06 01:55:33 +08:00
|
|
|
## Check that the rebase table is empty.
|
[lld-macho] Have tests default to targeting macos 10.15
D101114 enforced proper version checks, which exposed a variety of version
mismatch issues in our tests. We previously changed the test inputs to
target 10.0, which was the simpler thing to do, but we should really
just have our lit.local.cfg default to targeting 10.15, which is what is done
here. We're not likely to ever have proper support for the older versions
anyway, as that would require more work for unclear benefit; for instance,
llvm-mc seems to generate a different compact unwind format for older macOS
versions, which would cause our compact-unwind.s test to fail.
Targeting 10.15 by default causes the following behavioral changes:
* `__mh_execute_header` is now a section symbol instead of an absolute symbol
* LC_BUILD_VERSION gets emitted instead of LC_VERSION_MIN_MACOSX. The former is
32 bytes in size whereas the latter is 16 bytes, so a bunch of hardcoded
address offsets in our tests had to be updated.
* >= 10.6 executables are PIE by default
Note that this diff was stacked atop of a local revert of most of the test
changes in rG8c17a875150f8e736e8f9061ddf084397f45f4c5, to make review easier.
Reviewed By: #lld-macho, oontvoo
Differential Revision: https://reviews.llvm.org/D101119
2021-04-23 07:37:47 +08:00
|
|
|
# NO-PIE-LABEL: Rebase table:
|
|
|
|
# NO-PIE-NEXT: segment section address type
|
|
|
|
|
|
|
|
# PIE-LABEL: Rebase table:
|
|
|
|
# PIE-NEXT: segment section address type
|
|
|
|
# PIE-NEXT: __DATA __la_symbol_ptr 0x[[#%X, ADDR:]] pointer
|
|
|
|
# PIE-NEXT: __DATA __la_symbol_ptr 0x[[#ADDR + 8]] pointer
|
2020-09-06 01:55:33 +08:00
|
|
|
|
2021-05-11 00:16:18 +08:00
|
|
|
# CHECK-EMPTY:
|
2020-09-06 01:55:33 +08:00
|
|
|
# CHECK-NEXT: Bind table:
|
2020-05-12 22:29:15 +08:00
|
|
|
# CHECK: __DATA_CONST __got 0x[[#%x, BINDER:]] pointer 0 libSystem dyld_stub_binder
|
|
|
|
|
|
|
|
# CHECK-LABEL: Lazy bind table:
|
|
|
|
# CHECK-DAG: __DATA __la_symbol_ptr 0x{{0*}}[[#%x, HELLO_LAZY_PTR:]] libhello _print_hello
|
|
|
|
# CHECK-DAG: __DATA __la_symbol_ptr 0x{{0*}}[[#%x, GOODBYE_LAZY_PTR:]] libgoodbye _print_goodbye
|
|
|
|
|
|
|
|
# CHECK-LABEL: Disassembly of section __TEXT,__stubs:
|
|
|
|
# CHECK-DAG: [[#%x, HELLO_STUB]]: jmpq *[[#%u, HELLO_LAZY_PTR - HELLO_STUB - 6]](%rip)
|
|
|
|
# CHECK-DAG: [[#%x, GOODBYE_STUB]]: jmpq *[[#%u, GOODBYE_LAZY_PTR - GOODBYE_STUB - 6]](%rip)
|
|
|
|
|
|
|
|
# CHECK-LABEL: Disassembly of section __TEXT,__stub_helper:
|
|
|
|
# CHECK: {{0*}}[[#%x, STUB_HELPER_ENTRY:]] <__stub_helper>:
|
|
|
|
# CHECK-NEXT: leaq [[#%u, IMGLOADER - STUB_HELPER_ENTRY - 7]](%rip), %r11
|
|
|
|
# CHECK-NEXT: pushq %r11
|
|
|
|
# CHECK-NEXT: jmpq *[[#%u, BINDER_OFF:]](%rip)
|
|
|
|
# CHECK-NEXT: [[#%x, BINDER - BINDER_OFF]]: nop
|
|
|
|
# CHECK-NEXT: pushq $0
|
|
|
|
# CHECK-NEXT: jmp 0x[[#STUB_HELPER_ENTRY]]
|
|
|
|
# CHECK-NEXT: pushq $21
|
|
|
|
# CHECK-NEXT: jmp 0x[[#STUB_HELPER_ENTRY]]
|
|
|
|
|
|
|
|
.text
|
|
|
|
.globl _main
|
|
|
|
|
|
|
|
_main:
|
|
|
|
sub $8, %rsp # 16-byte-align the stack; dyld checks for this
|
|
|
|
callq _print_hello
|
|
|
|
callq _print_goodbye
|
|
|
|
add $8, %rsp
|
|
|
|
ret
|