Created
April 15, 2020 17:55
-
-
Save tsafin/9729a5e0f3ca2823ae4a8a61205842fc to your computer and use it in GitHub Desktop.
Mocking with visibility=default
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcc -m64 -O2 -o export_api main.c | |
nm -a export_api |grep ' [tT] ' |tee nm-t-0.txt | |
gcc -m64 -O2 -o export_api_1 -fvisibility=hidden main.c | |
nm -a export_api_1 |grep ' [tT] ' |tee nm-t-1.txt | |
g++ -m64 -O2 -o export_api_cxx main.c | |
nm -a export_api_cxx |grep ' [tT] ' |tee nm-t-2.txt | |
g++ -m64 -O2 -o export_api_cxx_1 -fvisibility=hidden main.c | |
nm -a export_api_cxx_1 |grep ' [tT] ' |tee nm-t-3.txt | |
g++ -m64 -O2 -o export_api_cxx_2 -fuse-ld=gold main.c | |
nm -a export_api_cxx_2 |grep ' [tT] ' |tee nm-t-4.txt | |
g++ -m64 -O2 -o export_api_cxx_3 -fuse-ld=gold -fvisibility=hidden main.c | |
nm -a export_api_cxx_3 |grep ' [tT] ' |tee nm-t-5.txt | |
echo "diff nm-t-0.txt nm-t-1.txt" | |
diff nm-t-0.txt nm-t-1.txt | c++filt | |
echo "diff nm-t-1.txt nm-t-2.txt" | |
diff nm-t-1.txt nm-t-2.txt | c++filt | |
echo "diff nm-t-2.txt nm-t-3.txt" | |
diff nm-t-2.txt nm-t-3.txt | c++filt | |
echo "diff nm-t-3.txt nm-t-4.txt" | |
diff nm-t-3.txt nm-t-4.txt | c++filt | |
echo "diff nm-t-4.txt nm-t-5.txt" | |
diff nm-t-4.txt nm-t-5.txt | c++filt | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __cplusplus | |
# define EXTERN_C extern "C" | |
#else | |
# define EXTERN_C extern | |
#endif | |
#ifdef EXPORTING | |
# ifdef _MSC_VER | |
# define API __declspec(dllexport) | |
# else | |
# define API __attribute__((visibility("default"))) | |
# endif | |
#else | |
# if MSVC | |
# define API __declspec(dllimport) | |
# else | |
# define API __attribute__((visibility("default"))) | |
# endif | |
#endif | |
#define EXPORT_API EXTERN_C API |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define EXPORTING | |
#include "export-api.h" | |
// should be exported | |
EXTERN_C int api_a(void) | |
{ | |
return 1; | |
} | |
// may be exported | |
int main(void) | |
{ | |
return 0; | |
} | |
// should be hidden | |
int unexported_api_a(void) | |
{ | |
return 2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tsafin@M1BOOK6319:~/docs/examples/declspec-export$ ./do-all.sh | |
0000000000001140 T api_a | |
0000000000001080 t deregister_tm_clones | |
00000000000010f0 t __do_global_dtors_aux | |
0000000000003e20 t __do_global_dtors_aux_fini_array_entry | |
00000000000011c4 t .fini | |
00000000000011c4 T _fini | |
0000000000003e20 t .fini_array | |
0000000000001130 t frame_dummy | |
0000000000003e18 t __frame_dummy_init_array_entry | |
0000000000001000 t .init | |
0000000000001000 t _init | |
0000000000003e18 t .init_array | |
0000000000003e20 t __init_array_end | |
0000000000003e18 t __init_array_start | |
00000000000011c0 T __libc_csu_fini | |
0000000000001160 T __libc_csu_init | |
0000000000001040 T main | |
0000000000001020 t .plt | |
0000000000001030 t .plt.got | |
00000000000010b0 t register_tm_clones | |
0000000000001050 T _start | |
0000000000001040 t .text | |
0000000000001150 T unexported_api_a | |
0000000000001140 T api_a | |
0000000000001080 t deregister_tm_clones | |
00000000000010f0 t __do_global_dtors_aux | |
0000000000003e20 t __do_global_dtors_aux_fini_array_entry | |
00000000000011c4 t .fini | |
00000000000011c4 T _fini | |
0000000000003e20 t .fini_array | |
0000000000001130 t frame_dummy | |
0000000000003e18 t __frame_dummy_init_array_entry | |
0000000000001000 t .init | |
0000000000001000 t _init | |
0000000000003e18 t .init_array | |
0000000000003e20 t __init_array_end | |
0000000000003e18 t __init_array_start | |
00000000000011c0 T __libc_csu_fini | |
0000000000001160 T __libc_csu_init | |
0000000000001040 T main | |
0000000000001020 t .plt | |
0000000000001030 t .plt.got | |
00000000000010b0 t register_tm_clones | |
0000000000001050 T _start | |
0000000000001040 t .text | |
0000000000001150 T unexported_api_a | |
0000000000001140 T api_a | |
0000000000001080 t deregister_tm_clones | |
00000000000010f0 t __do_global_dtors_aux | |
0000000000003df0 t __do_global_dtors_aux_fini_array_entry | |
00000000000011c4 t .fini | |
00000000000011c4 T _fini | |
0000000000003df0 t .fini_array | |
0000000000001130 t frame_dummy | |
0000000000003de8 t __frame_dummy_init_array_entry | |
0000000000001000 t .init | |
0000000000001000 t _init | |
0000000000003de8 t .init_array | |
0000000000003df0 t __init_array_end | |
0000000000003de8 t __init_array_start | |
00000000000011c0 T __libc_csu_fini | |
0000000000001160 T __libc_csu_init | |
0000000000001040 T main | |
0000000000001020 t .plt | |
0000000000001030 t .plt.got | |
00000000000010b0 t register_tm_clones | |
0000000000001050 T _start | |
0000000000001040 t .text | |
0000000000001150 T _Z16unexported_api_av | |
0000000000001140 T api_a | |
0000000000001080 t deregister_tm_clones | |
00000000000010f0 t __do_global_dtors_aux | |
0000000000003df0 t __do_global_dtors_aux_fini_array_entry | |
00000000000011c4 t .fini | |
00000000000011c4 T _fini | |
0000000000003df0 t .fini_array | |
0000000000001130 t frame_dummy | |
0000000000003de8 t __frame_dummy_init_array_entry | |
0000000000001000 t .init | |
0000000000001000 t _init | |
0000000000003de8 t .init_array | |
0000000000003df0 t __init_array_end | |
0000000000003de8 t __init_array_start | |
00000000000011c0 T __libc_csu_fini | |
0000000000001160 T __libc_csu_init | |
0000000000001040 T main | |
0000000000001020 t .plt | |
0000000000001030 t .plt.got | |
00000000000010b0 t register_tm_clones | |
0000000000001050 T _start | |
0000000000001040 t .text | |
0000000000001150 T _Z16unexported_api_av | |
0000000000000630 T api_a | |
0000000000002018 T __bss_start | |
0000000000000570 t deregister_tm_clones | |
00000000000005e0 t __do_global_dtors_aux | |
0000000000001da0 t __do_global_dtors_aux_fini_array_entry | |
0000000000002018 T _edata | |
0000000000002019 T _end | |
00000000000006c4 t _fini | |
0000000000000620 t frame_dummy | |
0000000000001da8 t __frame_dummy_init_array_entry | |
00000000000004f0 t _init | |
0000000000001db0 t __init_array_end | |
0000000000001da8 t __init_array_start | |
00000000000006c0 T __libc_csu_fini | |
0000000000000660 T __libc_csu_init | |
0000000000000530 T main | |
00000000000005a0 t register_tm_clones | |
0000000000000540 T _start | |
0000000000000640 T _Z16unexported_api_av | |
0000000000000630 t api_a | |
0000000000002018 T __bss_start | |
0000000000000570 t deregister_tm_clones | |
00000000000005e0 t __do_global_dtors_aux | |
0000000000001da0 t __do_global_dtors_aux_fini_array_entry | |
0000000000002018 T _edata | |
0000000000002019 T _end | |
00000000000006c4 t _fini | |
0000000000000620 t frame_dummy | |
0000000000001da8 t __frame_dummy_init_array_entry | |
00000000000004f0 t _init | |
0000000000001db0 t __init_array_end | |
0000000000001da8 t __init_array_start | |
00000000000006c0 T __libc_csu_fini | |
0000000000000660 T __libc_csu_init | |
0000000000000530 t main | |
00000000000005a0 t register_tm_clones | |
0000000000000540 T _start | |
0000000000000640 t _Z16unexported_api_av | |
diff nm-t-0.txt nm-t-1.txt | |
diff nm-t-1.txt nm-t-2.txt | |
4c4 | |
< 0000000000003e20 t __do_global_dtors_aux_fini_array_entry | |
--- | |
> 0000000000003df0 t __do_global_dtors_aux_fini_array_entry | |
7c7 | |
< 0000000000003e20 t .fini_array | |
--- | |
> 0000000000003df0 t .fini_array | |
9c9 | |
< 0000000000003e18 t __frame_dummy_init_array_entry | |
--- | |
> 0000000000003de8 t __frame_dummy_init_array_entry | |
12,14c12,14 | |
< 0000000000003e18 t .init_array | |
< 0000000000003e20 t __init_array_end | |
< 0000000000003e18 t __init_array_start | |
--- | |
> 0000000000003de8 t .init_array | |
> 0000000000003df0 t __init_array_end | |
> 0000000000003de8 t __init_array_start | |
23c23 | |
< 0000000000001150 T unexported_api_a | |
--- | |
> 0000000000001150 T unexported_api_a() | |
diff nm-t-2.txt nm-t-3.txt | |
diff nm-t-3.txt nm-t-4.txt | |
1,23c1,19 | |
< 0000000000001140 T api_a | |
< 0000000000001080 t deregister_tm_clones | |
< 00000000000010f0 t __do_global_dtors_aux | |
< 0000000000003df0 t __do_global_dtors_aux_fini_array_entry | |
< 00000000000011c4 t .fini | |
< 00000000000011c4 T _fini | |
< 0000000000003df0 t .fini_array | |
< 0000000000001130 t frame_dummy | |
< 0000000000003de8 t __frame_dummy_init_array_entry | |
< 0000000000001000 t .init | |
< 0000000000001000 t _init | |
< 0000000000003de8 t .init_array | |
< 0000000000003df0 t __init_array_end | |
< 0000000000003de8 t __init_array_start | |
< 00000000000011c0 T __libc_csu_fini | |
< 0000000000001160 T __libc_csu_init | |
< 0000000000001040 T main | |
< 0000000000001020 t .plt | |
< 0000000000001030 t .plt.got | |
< 00000000000010b0 t register_tm_clones | |
< 0000000000001050 T _start | |
< 0000000000001040 t .text | |
< 0000000000001150 T unexported_api_a() | |
--- | |
> 0000000000000630 T api_a | |
> 0000000000002018 T __bss_start | |
> 0000000000000570 t deregister_tm_clones | |
> 00000000000005e0 t __do_global_dtors_aux | |
> 0000000000001da0 t __do_global_dtors_aux_fini_array_entry | |
> 0000000000002018 T _edata | |
> 0000000000002019 T _end | |
> 00000000000006c4 t _fini | |
> 0000000000000620 t frame_dummy | |
> 0000000000001da8 t __frame_dummy_init_array_entry | |
> 00000000000004f0 t _init | |
> 0000000000001db0 t __init_array_end | |
> 0000000000001da8 t __init_array_start | |
> 00000000000006c0 T __libc_csu_fini | |
> 0000000000000660 T __libc_csu_init | |
> 0000000000000530 T main | |
> 00000000000005a0 t register_tm_clones | |
> 0000000000000540 T _start | |
> 0000000000000640 T unexported_api_a() | |
diff nm-t-4.txt nm-t-5.txt | |
1c1 | |
< 0000000000000630 T api_a | |
--- | |
> 0000000000000630 t api_a | |
16c16 | |
< 0000000000000530 T main | |
--- | |
> 0000000000000530 t main | |
19c19 | |
< 0000000000000640 T unexported_api_a() | |
--- | |
> 0000000000000640 t unexported_api_a() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment