@@ -29,30 +29,27 @@ import("utils.progress")
29
29
-- It is not very accurate because some rules automatically
30
30
-- generate objectfiles and do not save the corresponding sourcefiles.
31
31
-- @see https://github.com/xmake-io/xmake/issues/5601
32
- function _get_sourcefile_from_objectfile (target , objectfile )
33
- local sourcefile
32
+ function _get_sourcefiles_map (target , sourcefiles_map )
34
33
for _ , sourcebatch in pairs (target :sourcebatches ()) do
35
- local sourcefiles = sourcebatch .sourcefiles
36
- if sourcefiles then
37
- for idx , obj in ipairs ( sourcebatch . objectfiles ) do
38
- if obj == objectfile then
39
- sourcefile = sourcefiles [ idx ]
40
- break
34
+ for idx , sourcefile in ipairs ( sourcebatch .sourcefiles ) do
35
+ local objectfiles = sourcebatch . objectfiles
36
+ if objectfiles then
37
+ local objectfile = objectfiles [ idx ]
38
+ if objectfile then
39
+ sourcefiles_map [ objectfile ] = sourcefile
41
40
end
42
41
end
43
42
end
44
43
end
45
- if not sourcefile then
46
- for _ , dep in ipairs (target :orderdeps ()) do
47
- if dep :is_object () then
48
- sourcefile = _get_sourcefile_from_objectfile (dep , objectfile )
49
- if sourcefile then
50
- break
51
- end
44
+ local plaindeps = target :get (" deps" )
45
+ if plaindeps then
46
+ for _ , depname in ipairs (plaindeps ) do
47
+ local dep = target :dep (depname )
48
+ if dep and dep :is_object () then
49
+ _get_sourcefiles_map (dep , sourcefiles_map )
52
50
end
53
51
end
54
52
end
55
- return sourcefile
56
53
end
57
54
58
55
-- use dumpbin to get all symbols from object files
@@ -61,13 +58,14 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
61
58
local allsymbols = hashset .new ()
62
59
local export_classes = opt .export_classes
63
60
local export_filter = opt .export_filter
61
+ local sourcefiles_map = {}
62
+ if export_filter then
63
+ _get_sourcefiles_map (target , sourcefiles_map )
64
+ end
64
65
for _ , objectfile in ipairs (target :objectfiles ()) do
65
66
local objectsymbols = try { function () return os .iorunv (dumpbin , {" /symbols" , " /nologo" , objectfile }) end }
66
67
if objectsymbols then
67
- local sourcefile
68
- if export_filter then
69
- sourcefile = _get_sourcefile_from_objectfile (target , objectfile )
70
- end
68
+ local sourcefile = sourcefiles_map [objectfile ]
71
69
for _ , line in ipairs (objectsymbols :split (' \n ' , {plain = true })) do
72
70
-- https://docs.microsoft.com/en-us/cpp/build/reference/symbols
73
71
-- 008 00000000 SECT3 notype () External | add
@@ -108,13 +106,14 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
108
106
local allsymbols = hashset .new ()
109
107
local export_classes = opt .export_classes
110
108
local export_filter = opt .export_filter
109
+ local sourcefiles_map = {}
110
+ if export_filter then
111
+ _get_sourcefiles_map (target , sourcefiles_map )
112
+ end
111
113
for _ , objectfile in ipairs (target :objectfiles ()) do
112
114
local objectsymbols = try { function () return os .iorunv (objdump , {" --syms" , objectfile }) end }
113
115
if objectsymbols then
114
- local sourcefile
115
- if export_filter then
116
- sourcefile = _get_sourcefile_from_objectfile (target , objectfile )
117
- end
116
+ local sourcefile = sourcefiles_map [objectfile ]
118
117
for _ , line in ipairs (objectsymbols :split (' \n ' , {plain = true })) do
119
118
if line :find (" (scl 2)" , 1 , true ) then
120
119
local splitinfo = line :split (" %s" )
0 commit comments