@@ -31,6 +31,7 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
31
31
opt = opt or {}
32
32
local allsymbols = hashset .new ()
33
33
local export_classes = opt .export_classes
34
+ local export_filter = opt .export_filter
34
35
for _ , objectfile in ipairs (target :objectfiles ()) do
35
36
local objectsymbols = try { function () return os .iorunv (dumpbin , {" /symbols" , " /nologo" , objectfile }) end }
36
37
if objectsymbols then
@@ -41,7 +42,11 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
41
42
local symbol = line :match (" .*External%s+| (.*)" )
42
43
if symbol then
43
44
symbol = symbol :split (' %s' )[1 ]
44
- if not symbol :startswith (" __" ) then
45
+ if export_filter then
46
+ if export_filter (symbol ) then
47
+ allsymbols :insert (symbol )
48
+ end
49
+ elseif not symbol :startswith (" __" ) then
45
50
-- we need ignore DllMain, https://github.com/xmake-io/xmake/issues/3992
46
51
if target :is_arch (" x86" ) and symbol :startswith (" _" ) and not symbol :startswith (" _DllMain@" ) then
47
52
symbol = symbol :sub (2 )
@@ -69,6 +74,7 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
69
74
opt = opt or {}
70
75
local allsymbols = hashset .new ()
71
76
local export_classes = opt .export_classes
77
+ local export_filter = opt .export_filter
72
78
for _ , objectfile in ipairs (target :objectfiles ()) do
73
79
local objectsymbols = try { function () return os .iorunv (objdump , {" --syms" , objectfile }) end }
74
80
if objectsymbols then
@@ -77,7 +83,11 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
77
83
local splitinfo = line :split (" %s" )
78
84
local symbol = splitinfo [# splitinfo ]
79
85
if symbol then
80
- if not symbol :startswith (" __" ) then
86
+ if export_filter then
87
+ if export_filter (symbol ) then
88
+ allsymbols :insert (symbol )
89
+ end
90
+ elseif not symbol :startswith (" __" ) then
81
91
-- we need ignore DllMain, https://github.com/xmake-io/xmake/issues/3992
82
92
if target :is_arch (" x86" ) and symbol :startswith (" _" ) and not symbol :startswith (" _DllMain@" ) then
83
93
symbol = symbol :sub (2 )
@@ -120,15 +130,22 @@ function main(target, opt)
120
130
-- export c++ class?
121
131
local export_classes = target :extraconf (" rules" , " utils.symbols.export_all" , " export_classes" )
122
132
133
+ -- the export filter
134
+ local export_filter = target :extraconf (" rules" , " utils.symbols.export_all" , " export_filter" )
135
+
123
136
-- get all symbols
124
137
local allsymbols
125
138
local msvc = toolchain .load (" msvc" , {plat = target :plat (), arch = target :arch ()})
126
139
if msvc :check () then
127
140
local dumpbin = assert (find_tool (" dumpbin" , {envs = msvc :runenvs ()}), " dumpbin not found!" )
128
- allsymbols = _get_allsymbols_by_dumpbin (target , dumpbin .program , {export_classes = export_classes })
141
+ allsymbols = _get_allsymbols_by_dumpbin (target , dumpbin .program , {
142
+ export_classes = export_classes ,
143
+ export_filter = export_filter })
129
144
elseif target :has_tool (" cc" , " clang" , " clang_cl" , " clangxx" , " gcc" , " gxx" ) then
130
145
local objdump = assert (find_tool (" llvm-objdump" ) or find_tool (" objdump" ), " objdump not found!" )
131
- allsymbols = _get_allsymbols_by_objdump (target , objdump .program , {export_classes = export_classes })
146
+ allsymbols = _get_allsymbols_by_objdump (target , objdump .program , {
147
+ export_classes = export_classes ,
148
+ export_filter = export_filter })
132
149
end
133
150
134
151
-- export all symbols
0 commit comments