brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.8 KiB · 399b764 Raw
262 lines · plain
1; REQUIRES: x862; RUN: rm -rf %t; split-file %s %t3 4; RUN: llvm-as %t/framework.ll -o %t/framework.o5; RUN: %lld -lSystem %t/framework.o -o %t/frame6; RUN: llvm-otool -l %t/frame | FileCheck --check-prefix=FRAME %s \7; RUN:  --implicit-check-not LC_LOAD_DYLIB8; FRAME:          cmd LC_LOAD_DYLIB9; FRAME-NEXT: cmdsize10; FRAME-NEXT:    name /usr/lib/libSystem.dylib11; FRAME:          cmd LC_LOAD_DYLIB12; FRAME-NEXT: cmdsize13; FRAME-NEXT:    name /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation14 15; RUN: not %lld %t/framework.o -o %t/frame_no_autolink -ignore_auto_link 2>&1 | FileCheck --check-prefix=NO-AUTOLINK %s16; RUN: not %lld %t/framework.o -o %t/frame_no_autolink --ignore-auto-link-option CoreFoundation 2>&1 | FileCheck --check-prefix=NO-AUTOLINK %s17; RUN: not %lld %t/framework.o -o %t/frame_no_autolink --ignore-auto-link-option=CoreFoundation 2>&1 | FileCheck --check-prefix=NO-AUTOLINK %s18; NO-AUTOLINK: error: undefined symbol: __CFBigNumGetInt12819 20; RUN: llvm-as %t/l.ll -o %t/l.o21;; The dynamic call to _CFBigNumGetInt128 uses dyld_stub_binder,22;; which needs -lSystem from LC_LINKER_OPTION to get resolved.23;; The reference to __cxa_allocate_exception will require -lc++ from24;; LC_LINKER_OPTION to get resolved.25; RUN: %no-lsystem-lld %t/l.o -o %t/l -framework CoreFoundation26; RUN: llvm-otool -l %t/l | FileCheck --check-prefix=LIB %s \27; RUN:  --implicit-check-not LC_LOAD_DYLIB28; LIB:          cmd LC_LOAD_DYLIB29; LIB-NEXT: cmdsize30; LIB-NEXT:    name /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation31; LIB:          cmd LC_LOAD_DYLIB32; LIB-NEXT: cmdsize33; LIB-NEXT:    name /usr/lib/libSystem.dylib34; LIB:          cmd LC_LOAD_DYLIB35; LIB-NEXT: cmdsize36; LIB-NEXT:    name /usr/lib/libc++abi.dylib37 38;; Check that we don't create duplicate LC_LOAD_DYLIBs.39; RUN: %no-lsystem-lld -lSystem %t/l.o -o %t/l -framework CoreFoundation40; RUN: llvm-otool -l %t/l | FileCheck --check-prefix=LIB2 %s \41; RUN:  --implicit-check-not LC_LOAD_DYLIB42; LIB2:          cmd LC_LOAD_DYLIB43; LIB2-NEXT: cmdsize44; LIB2-NEXT:    name /usr/lib/libSystem.dylib45; LIB2:          cmd LC_LOAD_DYLIB46; LIB2-NEXT: cmdsize47; LIB2-NEXT:    name /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation48; LIB2:          cmd LC_LOAD_DYLIB49; LIB2-NEXT: cmdsize50; LIB2-NEXT:    name /usr/lib/libc++abi.dylib51 52; RUN: llvm-as %t/invalid.ll -o %t/invalid.o53; RUN: not %lld %t/invalid.o -o /dev/null 2>&1 | FileCheck --check-prefix=INVALID %s54; INVALID: error: -why_load is not allowed in LC_LINKER_OPTION55 56;; This is a regression test for a dangling string reference issue that occurred57;; when loading an archive-based framework via LC_LINKER_OPTION (see58;; D111706). Prior to the fix, this would trigger a heap-use-after-free when run59;; under ASAN.60; RUN: llc %t/foo.ll -o %t/foo.o -filetype=obj61; RUN: mkdir -p %t/Foo.framework62;; In a proper framework, this is technically supposed to be a symlink to the63;; actual archive at Foo.framework/Versions/Current, but we skip that here so64;; that this test can run on Windows.65; RUN: llvm-ar rcs %t/Foo.framework/Foo %t/foo.o66; RUN: llc %t/load-framework-foo.ll -o %t/load-framework-foo.o -filetype=obj67; RUN: llc %t/load-framework-undefined-symbol.ll -o %t/load-framework-undefined-symbol.o -filetype=obj68; RUN: llc %t/load-missing.ll -o %t/load-missing.o -filetype=obj69; RUN: llc %t/main.ll -o %t/main.o -filetype=obj70; RUN: %lld %t/load-framework-foo.o %t/main.o -o %t/main -F%t71; RUN: llvm-objdump --macho --syms %t/main | FileCheck %s --check-prefix=SYMS72 73;; Make sure -all_load and -ObjC have no effect on libraries loaded via74;; LC_LINKER_OPTION flags.75; RUN: llc %t/load-library-foo.ll -o %t/load-library-foo.o -filetype=obj76; RUN: llvm-ar rcs %t/libfoo.a %t/foo.o77; RUN: %lld -all_load -ObjC %t/load-framework-foo.o %t/load-library-foo.o \78; RUN:   %t/main.o -o %t/main -F%t -L%t79; RUN: llvm-objdump --macho --syms %t/main | FileCheck %s --check-prefix=SYMS80 81;; Note that _OBJC_CLASS_$_TestClass is *not* included here.82; SYMS:       SYMBOL TABLE:83; SYMS-NEXT:  g     F __TEXT,__text _main84; SYMS-NEXT:  g     F __TEXT,__text __mh_execute_header85; SYMS-NEXT:  *UND* dyld_stub_binder86; SYMS-EMPTY:87 88;; Make sure -all_load has effect when libraries are loaded via LC_LINKER_OPTION flags and explicitly passed as well89; RUN: %lld -all_load %t/load-framework-foo.o %t/load-library-foo.o %t/main.o -o %t/main -F%t -L%t -lfoo90; RUN: llvm-objdump --macho --syms %t/main | FileCheck %s --check-prefix=SYMS-ALL-LOAD91 92;; Note that _OBJC_CLASS_$_TestClass is *included* here.93; SYMS-ALL-LOAD:       SYMBOL TABLE:94; SYMS-ALL-LOAD-NEXT:  g     F __TEXT,__text _main95; SYMS-ALL-LOAD-NEXT:  g     O __DATA,__objc_data _OBJC_CLASS_$_TestClass96; SYMS-ALL-LOAD-NEXT:  g     F __TEXT,__text __mh_execute_header97; SYMS-ALL-LOAD-NEXT:  *UND* dyld_stub_binder98; SYMS-ALL-LOAD-EMPTY:99 100;; Make sure -force_load has effect when libraries are loaded via LC_LINKER_OPTION flags and explicitly passed as well101; RUN: %lld %t/load-library-foo.o %t/main.o -o %t/main -F%t -L%t -force_load %t/libfoo.a102; RUN: llvm-objdump --macho --syms %t/main | FileCheck %s --check-prefix=SYMS-FORCE-LOAD103 104;; Note that _OBJC_CLASS_$_TestClass is *included* here.105; SYMS-FORCE-LOAD:       SYMBOL TABLE:106; SYMS-FORCE-LOAD-NEXT:  g     F __TEXT,__text _main107; SYMS-FORCE-LOAD-NEXT:  g     O __DATA,__objc_data _OBJC_CLASS_$_TestClass108; SYMS-FORCE-LOAD-NEXT:  g     F __TEXT,__text __mh_execute_header109; SYMS-FORCE-LOAD-NEXT:  *UND* dyld_stub_binder110; SYMS-FORCE-LOAD-EMPTY:111 112;; Make sure -ObjC has effect when frameworks are loaded via LC_LINKER_OPTION flags and explicitly passed as well113; RUN: %lld -ObjC %t/load-framework-foo.o %t/load-library-foo.o %t/main.o -o %t/main -F%t -L%t -framework Foo114; RUN: llvm-objdump --macho --syms %t/main | FileCheck %s --check-prefix=SYMS-OBJC-LOAD115 116;; Note that _OBJC_CLASS_$_TestClass is *included* here.117; SYMS-OBJC-LOAD:       SYMBOL TABLE:118; SYMS-OBJC-LOAD-NEXT:  g     F __TEXT,__text _main119; SYMS-OBJC-LOAD-NEXT:  g     O __DATA,__objc_data _OBJC_CLASS_$_TestClass120; SYMS-OBJC-LOAD-NEXT:  g     F __TEXT,__text __mh_execute_header121; SYMS-OBJC-LOAD-NEXT:  *UND* dyld_stub_binder122; SYMS-OBJC-LOAD-EMPTY:123 124;; Make sure that frameworks containing object files or bitcode instead of125;; dylibs or archives do not cause duplicate symbol errors126; RUN: mkdir -p %t/Foo.framework127; RUN: llc --filetype=obj %t/foo.ll -o %t/Foo.framework/Foo128; RUN: llc --filetype=obj %t/load-framework-twice.ll -o %t/main129;; Order of the object with the LC_LINKER_OPTION vs -framework arg is important.130; RUN: %lld %t/main -F %t -framework Foo -framework Foo -o /dev/null131; RUN: %lld -F %t -framework Foo -framework Foo %t/main -o /dev/null132 133; RUN: llvm-as %t/foo.ll -o %t/Foo.framework/Foo134; RUN: llvm-as %t/load-framework-twice.ll -o %t/main135;; Order of the object with the LC_LINKER_OPTION vs -framework arg is important.136; RUN: %lld %t/main -F %t -framework Foo -framework Foo -o /dev/null137; RUN: %lld -F %t -framework Foo -framework Foo %t/main -o /dev/null138 139;; Checks that "framework not found" errors from LC_LINKER_OPTIONS are not140;; emitted unless the link fails or --strict-auto-link is passed.141; RUN: %lld -ObjC %t/load-framework-foo.o %t/main.o -o %t/main-no-foo.out142; RUN: llvm-objdump --macho --syms %t/main-no-foo.out | FileCheck %s --check-prefix=SYMS-NO-FOO143; RUN: not %lld --strict-auto-link -ObjC %t/load-missing.o %t/main.o -o %t/main-no-foo.out 2>&1 \144; RUN:   | FileCheck %s --check-prefix=MISSING-AUTO-LINK145; RUN: %no-fatal-warnings-lld --strict-auto-link -ObjC %t/load-missing.o %t/main.o -o %t/main-no-foo.out 2>&1 \146; RUN:   | FileCheck %s --check-prefix=MISSING-AUTO-LINK147; RUN: not %lld -ObjC %t/load-framework-undefined-symbol.o %t/load-missing.o %t/main.o -o %t/main-no-foo.out 2>&1 \148; RUN:   | FileCheck %s --check-prefixes=UNDEFINED-SYMBOL,MISSING-AUTO-LINK149 150;; Verify that nothing from the framework is included.151; SYMS-NO-FOO:       SYMBOL TABLE:152; SYMS-NO-FOO-NEXT:  g     F __TEXT,__text _main153; SYMS-NO-FOO-NOT:   g     O __DATA,__objc_data _OBJC_CLASS_$_TestClass154 155; UNDEFINED-SYMBOL: undefined symbol: __SomeUndefinedSymbol156; MISSING-AUTO-LINK: {{.+}}: auto-linked framework not found for -framework Foo157; MISSING-AUTO-LINK: {{.+}}: auto-linked library not found for -lBar158 159;--- framework.ll160target triple = "x86_64-apple-macosx10.15.0"161target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"162 163!0 = !{!"-framework", !"CoreFoundation"}164!llvm.linker.options = !{!0}165 166declare void @_CFBigNumGetInt128(...)167 168define void @main() {169  call void @_CFBigNumGetInt128()170  ret void171}172 173;--- l.ll174target triple = "x86_64-apple-macosx10.15.0"175target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"176 177!0 = !{!"-lSystem"}178!1 = !{!"-lc++"}179!llvm.linker.options = !{!0, !0, !1}180 181declare void @_CFBigNumGetInt128(...)182declare ptr @__cxa_allocate_exception(i64)183 184define void @main() {185  call void @_CFBigNumGetInt128()186  call ptr @__cxa_allocate_exception(i64 4)187  ret void188}189 190;--- invalid.ll191 192target triple = "x86_64-apple-macosx10.15.0"193target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"194 195!0 = !{!"-why_load"}196!llvm.linker.options = !{!0}197 198define void @main() {199  ret void200}201 202;--- load-framework-foo.ll203target triple = "x86_64-apple-macosx10.15.0"204target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"205 206!0 = !{!"-framework", !"Foo"}207!llvm.linker.options = !{!0}208 209;--- load-missing.ll210target triple = "x86_64-apple-macosx10.15.0"211target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"212 213!0 = !{!"-framework", !"Foo"}214!1 = !{!"-lBar"}215!llvm.linker.options = !{!0, !1}216 217;--- load-framework-undefined-symbol.ll218target triple = "x86_64-apple-macosx10.15.0"219target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"220 221declare void @_SomeUndefinedSymbol(...)222define void @foo() {223  call void @_SomeUndefinedSymbol()224  ret void225}226 227;--- load-framework-twice.ll228target triple = "x86_64-apple-macosx10.15.0"229target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"230 231!0 = !{!"-framework", !"Foo"}232!llvm.linker.options = !{!0, !0}233 234define void @main() {235  ret void236}237 238;--- load-library-foo.ll239target triple = "x86_64-apple-macosx10.15.0"240target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"241 242!0 = !{!"-lfoo"}243!llvm.linker.options = !{!0}244 245;--- main.ll246target triple = "x86_64-apple-macosx10.15.0"247target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"248 249define void @main() {250  ret void251}252 253!0 = !{!"-framework", !"Foo"}254!llvm.linker.options = !{!0}255 256;--- foo.ll257target triple = "x86_64-apple-macosx10.15.0"258target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"259 260%struct._class_t = type {}261@"OBJC_CLASS_$_TestClass" = global %struct._class_t {}, section "__DATA, __objc_data", align 8262