C++ noexcept关键字有时候会导致函数体变大

本身可以通过关闭C++异常支持,rtti支持来减少代码段的大小,使用如下的命令行参数:-fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables

但是有时候却并不能彻底关闭,比如说unity引擎开发的ios游戏,il2cpp后的C++代码与其它代码混在一起,il2cpp的代码是需要异常支持的。此时我们可以考虑将自己的C++代码加上noexcept关键字,这样也可以减少代码段。

但是有一些情况下,加noexcept并不能减少代码段,还可能会增加,看起来在这种情况下,“省略帧指针优化”将不起作用(这个优化的命令行为:omit-frame-pointer)

举个例子:

 1 //
 2 // Encodes input (uint32) into output (uint8).
 3 // Assumes len is a multiple of 4.
 4 //
 5 __attribute__((__noinline__))
 6 __attribute__((visibility("default")))
 7 void __appMD5Encode_common(uint8* output, const uint32* input, int len)
 8 {
 9     int i, j;
10 
11     for (i = 0, j = 0; j < len; i++, j += 4) {
12         output[j] = (uint8)(input[i] & 0xff);
13         output[j + 1] = (uint8)((input[i] >> 8) & 0xff);
14         output[j + 2] = (uint8)((input[i] >> 16) & 0xff);
15         output[j + 3] = (uint8)((input[i] >> 24) & 0xff);
16     }
17 }
18 
19 __attribute__((__noinline__))
20 __attribute__((visibility("default")))
21 void __appMD5Encode_noexcept(uint8* output, const uint32* input, int len) noexcept
22 {
23     int i, j;
24 
25     for (i = 0, j = 0; j < len; i++, j += 4) {
26         output[j] = (uint8)(input[i] & 0xff);
27         output[j + 1] = (uint8)((input[i] >> 8) & 0xff);
28         output[j + 2] = (uint8)((input[i] >> 16) & 0xff);
29         output[j + 3] = (uint8)((input[i] >> 24) & 0xff);
30     }
31 }
32 
33 typedef void (*func_type)(uint8*, const uint32*, int);
34 
35 void* g_commonFuncPtr = (void*) & __appMD5Encode_common;
36 void* g_noexceptFuncPtr = (void*)&__appMD5Encode_noexcept;
37 
38 
39 __attribute__((visibility("default"))) void appMD5Encode_noexcept_call_common(uint8* output, const uint32* input, int len) noexcept
40 {
41     __appMD5Encode_common(output, input, len);
42 }
43 
44 __attribute__((visibility("default"))) void appMD5Encode_noexcept_call_noexcept(uint8* output, const uint32* input, int len) noexcept
45 {
46     __appMD5Encode_noexcept(output, input, len);
47 }
48 
49 __attribute__((visibility("default"))) void appMD5Encode_noexcept_call_common_pointer(uint8* output, const uint32* input, int len) noexcept
50 {    
51     ((void (*)(uint8*, const uint32*, int))g_commonFuncPtr)(output, input, len);
52 }
53 
54 __attribute__((visibility("default"))) void appMD5Encode_noexcept_call_noexcept_pointer(uint8* output, const uint32* input, int len) noexcept
55 {
56     ((void (*)(uint8*, const uint32*, int))g_noexceptFuncPtr)(output, input, len);
57 }
58 
59 __attribute__((visibility("default"))) void appMD5Encode_noexcept_call_common_pointer_extra_noexcept(uint8* output, const uint32* input, int len) noexcept
60 {
61     ((void (*)(uint8*, const uint32*, int) noexcept )g_commonFuncPtr)(output, input, len);
62 }
63 
64 __attribute__((visibility("default"))) void appMD5Encode_noexcept_call_noexcept_pointer_extra_noexcept(uint8* output, const uint32* input, int len) noexcept
65 {
66     ((void (*)(uint8*, const uint32*, int) noexcept)g_noexceptFuncPtr)(output, input, len);
67 }
68 
69 __attribute__((visibility("default"))) void appMD5Encode_common_call_common(uint8* output, const uint32* input, int len)
70 {
71     __appMD5Encode_common(output, input, len);
72 }
73 
74 
75 __attribute__((visibility("default"))) void appMD5Encode_common_call_noexcept(uint8* output, const uint32* input, int len)
76 {
77     __appMD5Encode_noexcept(output, input, len);
78 }
79 
80 __attribute__((visibility("default"))) void appMD5Encode_common_call_common_pointer(uint8* output, const uint32* input, int len)
81 {
82     ((void (*)(uint8*, const uint32*, int))g_commonFuncPtr)(output, input, len);
83 }
84 
85 __attribute__((visibility("default"))) void appMD5Encode_common_call_noexcept_pointer(uint8* output, const uint32* input, int len)
86 {
87     ((void (*)(uint8*, const uint32*, int))g_noexceptFuncPtr)(output, input, len);
88 }
89 
90 __attribute__((visibility("default"))) void appMD5Encode_common_call_common_pointer_extra_noexcept(uint8* output, const uint32* input, int len)
91 {
92     ((void (*)(uint8*, const uint32*, int) noexcept)g_commonFuncPtr)(output, input, len);
93 }
94 
95 __attribute__((visibility("default"))) void appMD5Encode_common_call_noexcept_pointer_extra_noexcept(uint8* output, const uint32* input, int len)
96 {
97     ((void (*)(uint8*, const uint32*, int) noexcept )g_noexceptFuncPtr)(output, input, len);
98 }

 

观察汇编可以发现端倪:

 

.text:000000000000F10C ; =============== S U B R O U T I N E =======================================
.text:000000000000F10C
.text:000000000000F10C
.text:000000000000F10C ; __int64 __fastcall __appMD5Encode_common(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F10C                 EXPORT _Z21__appMD5Encode_commonPhPKji
.text:000000000000F10C _Z21__appMD5Encode_commonPhPKji         ; CODE XREF: __appMD5Encode_common(uchar *,uint const*,int)+C↑j
.text:000000000000F10C                                         ; appMD5Encode_noexcept_call_common_pointer_extra_noexcept(uchar *,uint const*,int)+C↓j ...
.text:000000000000F10C ; __unwind {
.text:000000000000F10C                 SUBS            W8, W2, #1
.text:000000000000F110                 B.LT            locret_F150
.text:000000000000F114                 LSR             W8, W8, #2
.text:000000000000F118                 ADD             W8, W8, #1
.text:000000000000F11C                 ADD             X9, X0, #3
.text:000000000000F120
.text:000000000000F120 loc_F120                                ; CODE XREF: __appMD5Encode_common(uchar *,uint const*,int)+40↓j
.text:000000000000F120                 LDR             W10, [X1]
.text:000000000000F124                 SUBS            X8, X8, #1
.text:000000000000F128                 STURB           W10, [X9,#-3]
.text:000000000000F12C                 LDR             W10, [X1]
.text:000000000000F130                 LSR             W10, W10, #8
.text:000000000000F134                 STURB           W10, [X9,#-2]
.text:000000000000F138                 LDRH            W10, [X1,#2]
.text:000000000000F13C                 STURB           W10, [X9,#-1]
.text:000000000000F140                 LDRB            W10, [X1,#3]
.text:000000000000F144                 ADD             X1, X1, #4
.text:000000000000F148                 STRB            W10, [X9],#4
.text:000000000000F14C                 B.NE            loc_F120
.text:000000000000F150
.text:000000000000F150 locret_F150                             ; CODE XREF: __appMD5Encode_common(uchar *,uint const*,int)+4↑j
.text:000000000000F150                 RET
.text:000000000000F150 ; } // starts at F10C
.text:000000000000F150 ; End of function __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F150
.text:000000000000F154
.text:000000000000F154 ; =============== S U B R O U T I N E =======================================
.text:000000000000F154
.text:000000000000F154
.text:000000000000F154 ; __int64 __fastcall __appMD5Encode_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F154                 EXPORT _Z23__appMD5Encode_noexceptPhPKji
.text:000000000000F154 _Z23__appMD5Encode_noexceptPhPKji       ; CODE XREF: __appMD5Encode_noexcept(uchar *,uint const*,int)+C↑j
.text:000000000000F154                                         ; appMD5Encode_noexcept_call_noexcept_pointer_extra_noexcept(uchar *,uint const*,int)+C↓j ...
.text:000000000000F154 ; __unwind {
.text:000000000000F154                 SUBS            W8, W2, #1
.text:000000000000F158                 B.LT            locret_F198
.text:000000000000F15C                 LSR             W8, W8, #2
.text:000000000000F160                 ADD             W8, W8, #1
.text:000000000000F164                 ADD             X9, X0, #3
.text:000000000000F168
.text:000000000000F168 loc_F168                                ; CODE XREF: __appMD5Encode_noexcept(uchar *,uint const*,int)+40↓j
.text:000000000000F168                 LDR             W10, [X1]
.text:000000000000F16C                 SUBS            X8, X8, #1
.text:000000000000F170                 STURB           W10, [X9,#-3]
.text:000000000000F174                 LDR             W10, [X1]
.text:000000000000F178                 LSR             W10, W10, #8
.text:000000000000F17C                 STURB           W10, [X9,#-2]
.text:000000000000F180                 LDRH            W10, [X1,#2]
.text:000000000000F184                 STURB           W10, [X9,#-1]
.text:000000000000F188                 LDRB            W10, [X1,#3]
.text:000000000000F18C                 ADD             X1, X1, #4
.text:000000000000F190                 STRB            W10, [X9],#4
.text:000000000000F194                 B.NE            loc_F168
.text:000000000000F198
.text:000000000000F198 locret_F198                             ; CODE XREF: __appMD5Encode_noexcept(uchar *,uint const*,int)+4↑j
.text:000000000000F198                 RET
.text:000000000000F198 ; } // starts at F154
.text:000000000000F198 ; End of function __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F198
.text:000000000000F19C
.text:000000000000F19C ; =============== S U B R O U T I N E =======================================
.text:000000000000F19C
.text:000000000000F19C
.text:000000000000F19C ; __int64 __fastcall appMD5Encode_noexcept_call_common(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F19C                 EXPORT _Z33appMD5Encode_noexcept_call_commonPhPKji
.text:000000000000F19C _Z33appMD5Encode_noexcept_call_commonPhPKji
.text:000000000000F19C                                         ; DATA XREF: LOAD:0000000000003310↑o
.text:000000000000F19C ; __unwind {
.text:000000000000F19C                 B               ._Z21__appMD5Encode_commonPhPKji ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F19C ; } // starts at F19C
.text:000000000000F19C ; End of function appMD5Encode_noexcept_call_common(uchar *,uint const*,int)
.text:000000000000F19C
.text:000000000000F1A0
.text:000000000000F1A0 ; =============== S U B R O U T I N E =======================================
.text:000000000000F1A0
.text:000000000000F1A0
.text:000000000000F1A0 ; __int64 __fastcall appMD5Encode_noexcept_call_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F1A0                 EXPORT _Z35appMD5Encode_noexcept_call_noexceptPhPKji
.text:000000000000F1A0 _Z35appMD5Encode_noexcept_call_noexceptPhPKji
.text:000000000000F1A0                                         ; DATA XREF: LOAD:0000000000002650↑o
.text:000000000000F1A0 ; __unwind {
.text:000000000000F1A0                 B               ._Z23__appMD5Encode_noexceptPhPKji ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F1A0 ; } // starts at F1A0
.text:000000000000F1A0 ; End of function appMD5Encode_noexcept_call_noexcept(uchar *,uint const*,int)
.text:000000000000F1A0
.text:000000000000F1A4
.text:000000000000F1A4 ; =============== S U B R O U T I N E =======================================
.text:000000000000F1A4
.text:000000000000F1A4
.text:000000000000F1A4 ; __int64 __fastcall appMD5Encode_noexcept_call_common_pointer(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F1A4                 EXPORT _Z41appMD5Encode_noexcept_call_common_pointerPhPKji
.text:000000000000F1A4 _Z41appMD5Encode_noexcept_call_common_pointerPhPKji
.text:000000000000F1A4                                         ; DATA XREF: LOAD:0000000000002F98↑o
.text:000000000000F1A4
.text:000000000000F1A4 var_10          = -0x10
.text:000000000000F1A4
.text:000000000000F1A4 ; __unwind { // __gxx_personality_v0
.text:000000000000F1A4                 STR             X30, [SP,#var_10]!
.text:000000000000F1A8                 ADRP            X8, #g_commonFuncPtr_ptr@PAGE
.text:000000000000F1AC                 LDR             X8, [X8,#g_commonFuncPtr_ptr@PAGEOFF]
.text:000000000000F1B0                 LDR             X8, [X8] ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F1B4 ;   try {
.text:000000000000F1B4                 BLR             X8
.text:000000000000F1B4 ;   } // starts at F1B4
.text:000000000000F1B8                 LDR             X30, [SP+0x10+var_10],#0x10
.text:000000000000F1BC                 RET
.text:000000000000F1C0 ; ---------------------------------------------------------------------------
.text:000000000000F1C0 ;   catch(...) // owned by F1B4
.text:000000000000F1C0                 BL              __clang_call_terminate
.text:000000000000F1C0 ; } // starts at F1A4
.text:000000000000F1C0 ; End of function appMD5Encode_noexcept_call_common_pointer(uchar *,uint const*,int)
.text:000000000000F1C0
.text:000000000000F1C4
.text:000000000000F1C4 ; =============== S U B R O U T I N E =======================================
.text:000000000000F1C4
.text:000000000000F1C4
.text:000000000000F1C4 ; __int64 __fastcall appMD5Encode_noexcept_call_noexcept_pointer(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F1C4                 EXPORT _Z43appMD5Encode_noexcept_call_noexcept_pointerPhPKji
.text:000000000000F1C4 _Z43appMD5Encode_noexcept_call_noexcept_pointerPhPKji
.text:000000000000F1C4                                         ; DATA XREF: LOAD:0000000000003C40↑o
.text:000000000000F1C4
.text:000000000000F1C4 var_10          = -0x10
.text:000000000000F1C4
.text:000000000000F1C4 ; __unwind { // __gxx_personality_v0
.text:000000000000F1C4                 STR             X30, [SP,#var_10]!
.text:000000000000F1C8                 ADRP            X8, #g_noexceptFuncPtr_ptr@PAGE
.text:000000000000F1CC                 LDR             X8, [X8,#g_noexceptFuncPtr_ptr@PAGEOFF]
.text:000000000000F1D0                 LDR             X8, [X8] ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F1D4 ;   try {
.text:000000000000F1D4                 BLR             X8
.text:000000000000F1D4 ;   } // starts at F1D4
.text:000000000000F1D8                 LDR             X30, [SP+0x10+var_10],#0x10
.text:000000000000F1DC                 RET
.text:000000000000F1E0 ; ---------------------------------------------------------------------------
.text:000000000000F1E0 ;   catch(...) // owned by F1D4
.text:000000000000F1E0                 BL              __clang_call_terminate
.text:000000000000F1E0 ; } // starts at F1C4
.text:000000000000F1E0 ; End of function appMD5Encode_noexcept_call_noexcept_pointer(uchar *,uint const*,int)
.text:000000000000F1E0
.text:000000000000F1E4
.text:000000000000F1E4 ; =============== S U B R O U T I N E =======================================
.text:000000000000F1E4
.text:000000000000F1E4
.text:000000000000F1E4 ; __int64 __fastcall appMD5Encode_noexcept_call_common_pointer_extra_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F1E4                 EXPORT _Z56appMD5Encode_noexcept_call_common_pointer_extra_noexceptPhPKji
.text:000000000000F1E4 _Z56appMD5Encode_noexcept_call_common_pointer_extra_noexceptPhPKji
.text:000000000000F1E4                                         ; DATA XREF: LOAD:0000000000002AA0↑o
.text:000000000000F1E4 ; __unwind {
.text:000000000000F1E4                 ADRP            X8, #g_commonFuncPtr_ptr@PAGE
.text:000000000000F1E8                 LDR             X8, [X8,#g_commonFuncPtr_ptr@PAGEOFF]
.text:000000000000F1EC                 LDR             X3, [X8] ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F1F0                 BR              X3      ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F1F0 ; } // starts at F1E4
.text:000000000000F1F0 ; End of function appMD5Encode_noexcept_call_common_pointer_extra_noexcept(uchar *,uint const*,int)
.text:000000000000F1F0
.text:000000000000F1F4
.text:000000000000F1F4 ; =============== S U B R O U T I N E =======================================
.text:000000000000F1F4
.text:000000000000F1F4
.text:000000000000F1F4 ; __int64 __fastcall appMD5Encode_noexcept_call_noexcept_pointer_extra_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F1F4                 EXPORT _Z58appMD5Encode_noexcept_call_noexcept_pointer_extra_noexceptPhPKji
.text:000000000000F1F4 _Z58appMD5Encode_noexcept_call_noexcept_pointer_extra_noexceptPhPKji
.text:000000000000F1F4                                         ; DATA XREF: LOAD:00000000000024D0↑o
.text:000000000000F1F4 ; __unwind {
.text:000000000000F1F4                 ADRP            X8, #g_noexceptFuncPtr_ptr@PAGE
.text:000000000000F1F8                 LDR             X8, [X8,#g_noexceptFuncPtr_ptr@PAGEOFF]
.text:000000000000F1FC                 LDR             X3, [X8] ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F200                 BR              X3      ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F200 ; } // starts at F1F4
.text:000000000000F200 ; End of function appMD5Encode_noexcept_call_noexcept_pointer_extra_noexcept(uchar *,uint const*,int)
.text:000000000000F200
.text:000000000000F204
.text:000000000000F204 ; =============== S U B R O U T I N E =======================================
.text:000000000000F204
.text:000000000000F204
.text:000000000000F204 ; __int64 __fastcall appMD5Encode_common_call_common(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F204                 EXPORT _Z31appMD5Encode_common_call_commonPhPKji
.text:000000000000F204 _Z31appMD5Encode_common_call_commonPhPKji
.text:000000000000F204                                         ; DATA XREF: LOAD:0000000000002EA8↑o
.text:000000000000F204 ; __unwind {
.text:000000000000F204                 B               ._Z21__appMD5Encode_commonPhPKji ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F204 ; } // starts at F204
.text:000000000000F204 ; End of function appMD5Encode_common_call_common(uchar *,uint const*,int)
.text:000000000000F204
.text:000000000000F208
.text:000000000000F208 ; =============== S U B R O U T I N E =======================================
.text:000000000000F208
.text:000000000000F208
.text:000000000000F208 ; __int64 __fastcall appMD5Encode_common_call_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F208                 EXPORT _Z33appMD5Encode_common_call_noexceptPhPKji
.text:000000000000F208 _Z33appMD5Encode_common_call_noexceptPhPKji
.text:000000000000F208                                         ; DATA XREF: LOAD:0000000000002320↑o
.text:000000000000F208 ; __unwind {
.text:000000000000F208                 B               ._Z23__appMD5Encode_noexceptPhPKji ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F208 ; } // starts at F208
.text:000000000000F208 ; End of function appMD5Encode_common_call_noexcept(uchar *,uint const*,int)
.text:000000000000F208
.text:000000000000F20C
.text:000000000000F20C ; =============== S U B R O U T I N E =======================================
.text:000000000000F20C
.text:000000000000F20C
.text:000000000000F20C ; __int64 __fastcall appMD5Encode_common_call_common_pointer(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F20C                 EXPORT _Z39appMD5Encode_common_call_common_pointerPhPKji
.text:000000000000F20C _Z39appMD5Encode_common_call_common_pointerPhPKji
.text:000000000000F20C                                         ; DATA XREF: LOAD:0000000000002230↑o
.text:000000000000F20C ; __unwind {
.text:000000000000F20C                 ADRP            X8, #g_commonFuncPtr_ptr@PAGE
.text:000000000000F210                 LDR             X8, [X8,#g_commonFuncPtr_ptr@PAGEOFF]
.text:000000000000F214                 LDR             X3, [X8] ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F218                 BR              X3      ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F218 ; } // starts at F20C
.text:000000000000F218 ; End of function appMD5Encode_common_call_common_pointer(uchar *,uint const*,int)
.text:000000000000F218
.text:000000000000F21C
.text:000000000000F21C ; =============== S U B R O U T I N E =======================================
.text:000000000000F21C
.text:000000000000F21C
.text:000000000000F21C ; __int64 __fastcall appMD5Encode_common_call_noexcept_pointer(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F21C                 EXPORT _Z41appMD5Encode_common_call_noexcept_pointerPhPKji
.text:000000000000F21C _Z41appMD5Encode_common_call_noexcept_pointerPhPKji
.text:000000000000F21C                                         ; DATA XREF: LOAD:0000000000002D10↑o
.text:000000000000F21C ; __unwind {
.text:000000000000F21C                 ADRP            X8, #g_noexceptFuncPtr_ptr@PAGE
.text:000000000000F220                 LDR             X8, [X8,#g_noexceptFuncPtr_ptr@PAGEOFF]
.text:000000000000F224                 LDR             X3, [X8] ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F228                 BR              X3      ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F228 ; } // starts at F21C
.text:000000000000F228 ; End of function appMD5Encode_common_call_noexcept_pointer(uchar *,uint const*,int)
.text:000000000000F228
.text:000000000000F22C
.text:000000000000F22C ; =============== S U B R O U T I N E =======================================
.text:000000000000F22C
.text:000000000000F22C
.text:000000000000F22C ; __int64 __fastcall appMD5Encode_common_call_common_pointer_extra_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F22C                 EXPORT _Z54appMD5Encode_common_call_common_pointer_extra_noexceptPhPKji
.text:000000000000F22C _Z54appMD5Encode_common_call_common_pointer_extra_noexceptPhPKji
.text:000000000000F22C                                         ; DATA XREF: LOAD:0000000000002620↑o
.text:000000000000F22C ; __unwind {
.text:000000000000F22C                 ADRP            X8, #g_commonFuncPtr_ptr@PAGE
.text:000000000000F230                 LDR             X8, [X8,#g_commonFuncPtr_ptr@PAGEOFF]
.text:000000000000F234                 LDR             X3, [X8] ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F238                 BR              X3      ; __appMD5Encode_common(uchar *,uint const*,int)
.text:000000000000F238 ; } // starts at F22C
.text:000000000000F238 ; End of function appMD5Encode_common_call_common_pointer_extra_noexcept(uchar *,uint const*,int)
.text:000000000000F238
.text:000000000000F23C
.text:000000000000F23C ; =============== S U B R O U T I N E =======================================
.text:000000000000F23C
.text:000000000000F23C
.text:000000000000F23C ; __int64 __fastcall appMD5Encode_common_call_noexcept_pointer_extra_noexcept(unsigned __int8 *, const unsigned int *, int)
.text:000000000000F23C                 EXPORT _Z56appMD5Encode_common_call_noexcept_pointer_extra_noexceptPhPKji
.text:000000000000F23C _Z56appMD5Encode_common_call_noexcept_pointer_extra_noexceptPhPKji
.text:000000000000F23C                                         ; DATA XREF: LOAD:0000000000001EB8↑o
.text:000000000000F23C ; __unwind {
.text:000000000000F23C                 ADRP            X8, #g_noexceptFuncPtr_ptr@PAGE
.text:000000000000F240                 LDR             X8, [X8,#g_noexceptFuncPtr_ptr@PAGEOFF]
.text:000000000000F244                 LDR             X3, [X8] ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F248                 BR              X3      ; __appMD5Encode_noexcept(uchar *,uint const*,int)
.text:000000000000F248 ; } // starts at F23C
.text:000000000000F248 ; End of function appMD5Encode_common_call_noexcept_pointer_extra_noexcept(uchar *,uint const*,int)
.text:000000000000F248

     当使用noexcept的函数调用普通函数时并没有什么问题,如果在noexcept的函数中调用普通的函数指针,那么编译器会安插一些额外的指令来确保noexcept函数中抛出异常时执行terminate操作。所以,此时需要将函数指针也标记成noexcept,那么它将按照常规的方式来调用目标函数指针了。

((void (*)(uint8*, const uint32*, int) noexcept)g_noexceptFuncPtr)(output, input, len);

     如上所示。

posted @ 2022-05-12 16:08  bodong  阅读(178)  评论(0编辑  收藏  举报