commit | author | age
|
e0ec42
|
1 |
/* |
L |
2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* This source code is licensed under the license found in the |
|
6 |
* LICENSE file in the root directory of this source tree. |
|
7 |
*/ |
|
8 |
|
|
9 |
// These macros exist to allow templates to substitute names of the class and category |
|
10 |
#define FB_LINK_CATEGORY_INTERFACE(CLASS, CATEGORY) FB_LINK_REQUIRE_CATEGORY(CLASS ## _ ## CATEGORY) |
|
11 |
#define FB_LINK_CATEGORY_IMPLEMENTATION(CLASS, CATEGORY) FB_LINKABLE(CLASS ## _ ## CATEGORY) |
|
12 |
|
|
13 |
#if !TARGET_OS_TV && !defined(FB_LINK_REQUIRE_DISABLE_I_KNOW_WHAT_I_AM_DOING) |
|
14 |
// DO NOT USE this macro directly, use FB_LINK_REQUIRE_CATEGORY. |
|
15 |
#define FB_LINK_REQUIRE_(NAME) \ |
|
16 |
extern char FBLinkable_ ## NAME; \ |
|
17 |
extern const void *_Nonnull const OS_WEAK OS_CONCAT(FBLink_, NAME); \ |
|
18 |
OS_USED const void *_Nonnull const OS_WEAK OS_CONCAT(FBLink_, NAME) = &FBLinkable_ ## NAME; |
|
19 |
|
|
20 |
// Annotate category @implementation definitions with this macro. |
|
21 |
#ifdef DEBUG |
|
22 |
#define FB_LINKABLE(NAME) \ |
|
23 |
__attribute__((used)) __attribute__((visibility("default"))) char FBLinkable_ ## NAME = 'L'; |
|
24 |
#else |
|
25 |
#define FB_LINKABLE(NAME) \ |
|
26 |
__attribute__((visibility("default"))) char FBLinkable_ ## NAME = 'L'; |
|
27 |
#endif |
|
28 |
|
|
29 |
// Annotate category @interface declarations with this macro. |
|
30 |
#define FB_LINK_REQUIRE_CATEGORY(NAME) \ |
|
31 |
FB_LINK_REQUIRE_(NAME) |
|
32 |
|
|
33 |
// Annotate class @interface declarations with this macro if they are getting dropped by dead stripping due to a lack of static references. |
|
34 |
#define FB_LINK_REQUIRE_CLASS(NAME) \ |
|
35 |
FB_LINK_REQUIRE_(NAME) \ |
|
36 |
extern void *OBJC_CLASS_$_ ## NAME; \ |
|
37 |
extern const void *const OS_WEAK OS_CONCAT(FBLinkClass_, NAME); \ |
|
38 |
OS_USED const void *const OS_WEAK OS_CONCAT(FBLinkClass_, NAME) = (void *)&OBJC_CLASS_$_ ## NAME; |
|
39 |
|
|
40 |
// Annotate class @implementations with this macro if you know they |
|
41 |
// will have a lack of static references or even header imports and |
|
42 |
// you have ensured that the containing implementation will be linked |
|
43 |
// by other means (e.g., other used classes in the same file. |
|
44 |
#define FB_DONT_DEAD_STRIP_CLASS(NAME) \ |
|
45 |
asm (".no_dead_strip _OBJC_CLASS_$_" #NAME); |
|
46 |
|
|
47 |
#else |
|
48 |
|
|
49 |
#define FB_LINK_REQUIRE_(NAME) |
|
50 |
#define FB_LINKABLE(NAME) |
|
51 |
#define FB_LINK_REQUIRE_CATEGORY(NAME) |
|
52 |
#define FB_LINK_REQUIRE_CLASS(NAME) |
|
53 |
#define FB_DONT_DEAD_STRIP_CLASS(NAME) |
|
54 |
|
|
55 |
#endif |