[lld-macho] Fix & fold reexport-nested-libs test into stub-link.s

The reexport-nested-libs test added in D97438 was a bit wonky.

First, it was linking against libReexportSystem.tbd which targets the
iOS simulator, and which in turn attempted to re-export the iOS
simulator's libSystem. However, due to the way `-syslibroot` works, it
was actually re-exporting the macOS libSystem.

As a result, the test was not actually able to resolve the symbols in
the desired libSystem. I'm guessing that @oontvoo was confused by this
and therefore included those symbols in libReexportSystem.tbd itself.
But this means that the test wasn't actually testing the resolution of
re-exported symbols (though it did at least verify that the re-exported
libraries could be located).

After some consideration, I figured that stub-link.s could be extended
to cover what reexport-nested-libs.s was attempting to do. The test
targets macOS, so we only have one `-syslibroot` and no chance of
confusion.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D97866
This commit is contained in:
Jez Ng 2021-03-04 14:36:46 -05:00
parent 5d9aafc09a
commit 8601be809e
6 changed files with 23 additions and 35 deletions

View File

@ -576,9 +576,9 @@ findDylib(StringRef path, DylibFile *umbrella,
if (currentTopLevelTapi) {
for (InterfaceFile &child :
make_pointee_range(currentTopLevelTapi->documents())) {
assert(child.documents().empty());
if (path == child.getInstallName())
return make<DylibFile>(child, umbrella);
assert(child.documents().empty());
}
}

View File

@ -11,3 +11,4 @@ exports:
objc-classes: [ NSObject ]
objc-ivars: [ NSConstantArray._count ]
objc-eh-types: [ NSException ]
...

View File

@ -6,7 +6,7 @@ install-name: '/usr/lib/libSystem.dylib'
current-version: 1281
exports:
- archs: [ i386, x86_64 ]
re-exports: [ '/usr/lib/system/libcache.dylib', ]
re-exports: [ '/usr/lib/system/libcache.dylib' ]
symbols: [ __crashreporter_info__, _cache_create ]
--- !tapi-tbd-v3
archs: [ i386, x86_64 ]

View File

@ -1,10 +1,9 @@
--- !tapi-tbd-v3
archs: [ i386, x86_64 ]
uuids: [ 'i386: 00000000-0000-0000-0000-000000000000', 'x86_64: 00000000-0000-0000-0000-000000000001' ]
platform: ios
platform: macosx
install-name: '/usr/lib/libReexportSystem.dylib'
exports:
- archs: [ i386, x86_64 ]
re-exports: [ '/usr/lib/libSystem' ]
symbols: [ __crashreporter_info__, _cache_create ]
re-exports: [ '/usr/lib/libSystem.dylib' ]
...

View File

@ -1,28 +0,0 @@
# REQUIRES: x86
#
# This tests that we can reference symbols from a dylib,
# re-exported by a top-level tapi document, which itself is
# re-exported by another top-level tapi document.
#
# RUN: rm -rf %t; mkdir -p %t
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: %lld -o %t/test -syslibroot %S/Inputs/iPhoneSimulator.sdk -lReexportSystem %t/test.o
# RUN: llvm-objdump %t/test --macho --bind %t/test | FileCheck %s
# CHECK: segment section address type addend dylib symbol
# CHECK: __DATA __data 0x{{[0-9a-f]*}} pointer 0 libReexportSystem __crashreporter_info__
# CHECK: __DATA __data 0x{{[0-9a-f]*}} pointer 0 libReexportSystem _cache_create
.text
.globl _main
_main:
ret
.data
// This symbol is from libSystem, which is re-exported by libReexportSystem.
// Reference it here to verify that it is visible.
.quad __crashreporter_info__
// This symbol is from /usr/lib/system/libcache.dylib, which is re-exported in libSystem.
.quad _cache_create

View File

@ -3,10 +3,16 @@
# RUN: mkdir -p %t
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: %lld -o %t/test -lSystem -lc++ -framework CoreFoundation %t/test.o
#
# RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/test | FileCheck %s
## libReexportSystem.tbd tests that we can reference symbols from a dylib,
## re-exported by a top-level tapi document, which itself is re-exported by
## another top-level tapi document.
# RUN: %lld -o %t/with-reexport %S/Inputs/libReexportSystem.tbd -lc++ -framework CoreFoundation %t/test.o
# RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/with-reexport | FileCheck %s
# CHECK: Disassembly of section __TEXT,__text:
# CHECK: movq {{.*}} # [[ADDR:[0-9a-f]+]]
@ -21,6 +27,9 @@
# RUN: llvm-objdump --macho --all-headers %t/test | \
# RUN: FileCheck --check-prefix=LOAD %s
# RUN: llvm-objdump --macho --all-headers %t/with-reexport | \
# RUN: FileCheck --check-prefixes=LOAD,LOAD-REEXPORT %s
# LOAD: cmd LC_LOAD_DYLIB
# LOAD-NEXT: cmdsize
# LOAD-NEXT: name /usr/lib/libSystem.dylib
@ -28,6 +37,13 @@
# LOAD-NEXT: current version 1.1.1
# LOAD-NEXT: compatibility version
# LOAD-REEXPORT: cmd LC_LOAD_DYLIB
# LOAD-REEXPORT-NEXT: cmdsize
# LOAD-REEXPORT-NEXT: name /usr/lib/libReexportSystem.dylib
# LOAD-REEXPORT-NEXT: time stamp
# LOAD-REEXPORT-NEXT: current version 1.0.0
# LOAD-REEXPORT-NEXT: compatibility version
.section __TEXT,__text
.global _main