Skip to content

Commit

Permalink
[lld-macho][nfc] Test that -ObjC will import bitcode with category se…
Browse files Browse the repository at this point in the history
…ctions

The functionality was originally added in {D95265}, but the test in that
diff only checked if `-ObjC` would cause bitcode containing ObjC class
symbols to be loaded. It neglected to test for bitcode containing
categories but no class symbols.

This diff also changes the lto-archive.ll test to use `-why_load`
instead of inspecting the output binary's symbol table. This is
motivated by the stacked diff {D99105}, which will hide irrelevant
bitcode symbols.

Reviewed By: #lld-macho, oontvoo

Differential Revision: https://reviews.llvm.org/D99215
  • Loading branch information
int3 committed Mar 31, 2021
1 parent 4ced958 commit 09aed38
Showing 1 changed file with 37 additions and 49 deletions.
86 changes: 37 additions & 49 deletions lld/test/MachO/lto-archive.ll
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
; REQUIRES: x86
; RUN: rm -rf %t; split-file %s %t
; RUN: llvm-as %t/foo.ll -o %t/foo.o
; RUN: llvm-as %t/objc.ll -o %t/objc.o
; RUN: llvm-as %t/has-objc-symbol.ll -o %t/has-objc-symbol.o
; RUN: llvm-as %t/has-objc-category.ll -o %t/has-objc-category.o
; RUN: llvm-ar rcs %t/foo.a %t/foo.o
; RUN: llvm-ar rcs %t/objc.a %t/objc.o
; RUN: llvm-ar rcs %t/objc.a %t/has-objc-symbol.o %t/has-objc-category.o

; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o
; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/references-foo.s -o %t/references-foo.o

; RUN: %lld -lSystem %t/references-foo.o %t/foo.a -o %t/test
; RUN: llvm-objdump --macho --syms %t/test | FileCheck %s --check-prefix=FOO
; RUN: %lld -lSystem %t/references-foo.o %t/foo.a -o /dev/null -why_load | FileCheck %s --check-prefix=FOO
; FOO: _foo forced load of foo.o

; RUN: %lld -lSystem -force_load %t/foo.a %t/main.o -o %t/force-load
; RUN: llvm-objdump --macho --syms %t/force-load | FileCheck %s --check-prefix=FOO
; RUN: %lld -lSystem -force_load %t/foo.a %t/main.o -o /dev/null -why_load | FileCheck %s --check-prefix=FORCE-LOAD
; FORCE-LOAD: -force_load forced load of foo.o

; RUN: %lld -lSystem %t/foo.a %t/main.o -o %t/no-force-load
; RUN: llvm-objdump --macho --syms %t/no-force-load | FileCheck %s --check-prefix=NO-FOO
; RUN: %lld -lSystem -ObjC -framework CoreFoundation %t/objc.a %t/main.o \
; RUN: -o /dev/null -why_load | FileCheck %s --check-prefix=OBJC
; OBJC: -ObjC forced load of has-objc-category.o
; OBJC: _OBJC_CLASS_$_Foo forced load of has-objc-symbol.o

; RUN: %lld -lSystem -ObjC -framework CoreFoundation %t/objc.a %t/main.o -o %t/objc
; RUN: llvm-objdump --macho --syms %t/objc | FileCheck %s --check-prefix=OBJC
; RUN: %lld -lSystem %t/foo.a %t/main.o -o %t/no-force-load -why_load | \
; RUN: FileCheck %s --allow-empty --check-prefix=NO-LOAD

; RUN: %lld -lSystem -framework CoreFoundation %t/objc.a %t/main.o -o %t/no-objc
; RUN: llvm-objdump --macho --syms %t/no-objc | FileCheck %s --check-prefix=NO-OBJC
; RUN: %lld -lSystem -framework CoreFoundation %t/objc.a %t/main.o -o %t/no-objc -why_load | \
; RUN: FileCheck %s --allow-empty --check-prefix=NO-LOAD

; FOO: _foo

; NO-FOO-NOT: _foo

; OBJC-DAG: _OBJC_CLASS_$_Foo
; OBJC-DAG: _OBJC_METACLASS_$_Foo

; NO-OBJC-NOT: _OBJC_CLASS_$_Foo
; NO-OBJC-NOT: _OBJC_METACLASS_$_Foo
; NO-LOAD-NOT: forced load

;--- foo.ll

Expand All @@ -42,38 +37,31 @@ define void @foo() {
ret void
}

;--- objc.ll
;--- has-objc-symbol.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"

%struct._class_t = type { %struct._class_t*, %struct._class_t*, %struct._class_ro_t* }
%struct._class_ro_t = type { i8* }

@"OBJC_METACLASS_$_NSObject" = external global %struct._class_t
@OBJC_CLASS_NAME_ = private unnamed_addr constant [4 x i8] c"Foo\00",
section "__TEXT,__objc_classname,cstring_literals"
@"_OBJC_METACLASS_RO_$_Foo" = internal global %struct._class_ro_t {
i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_CLASS_NAME_, i32 0, i32 0)
},
section "__DATA, __objc_const"
@"OBJC_METACLASS_$_Foo" = global %struct._class_t {
%struct._class_t* @"OBJC_METACLASS_$_NSObject",
%struct._class_t* @"OBJC_METACLASS_$_NSObject",
%struct._class_ro_t* @"_OBJC_METACLASS_RO_$_Foo"
},
section "__DATA, __objc_data"
@"OBJC_CLASS_$_NSObject" = external global %struct._class_t
@"_OBJC_CLASS_RO_$_Foo" = internal global %struct._class_ro_t {
i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_CLASS_NAME_, i32 0, i32 0)
},
section "__DATA, __objc_const"
@"OBJC_CLASS_$_Foo" = global %struct._class_t {
%struct._class_t* @"OBJC_METACLASS_$_Foo",
%struct._class_t* @"OBJC_CLASS_$_NSObject",
%struct._class_ro_t* @"_OBJC_CLASS_RO_$_Foo"
},
section "__DATA, __objc_data"
%struct._class_t = type { i8 }
@"OBJC_CLASS_$_Foo" = global %struct._class_t { i8 123 }

;--- has-objc-category.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"

%struct._category_t = type { i8 }

@"_OBJC_$_CATEGORY_Foo_$_Bar" = internal global %struct._category_t { i8 123 },
section "__DATA, __objc_const", align 8

@"OBJC_LABEL_CATEGORY_$" = private global [1 x i8*] [
i8* bitcast (%struct._category_t* @"_OBJC_$_CATEGORY_Foo_$_Bar" to i8*)
], section "__DATA,__objc_catlist,regular,no_dead_strip", align 8

@llvm.compiler.used = appending global [1 x i8*] [
i8* bitcast ([1 x i8*]* @"OBJC_LABEL_CATEGORY_$" to i8*)
], section "llvm.metadata"

;--- main.s

Expand Down

0 comments on commit 09aed38

Please sign in to comment.