@@ -53,24 +53,32 @@ func (b *Builder) link() error {
53
53
// it may happen that a subdir/spi.o inside the archive may be overwritten by a anotherdir/spi.o
54
54
// because thery are both named spi.o.
55
55
56
- archives := paths .NewPathList ()
56
+ // Put all the existing archives apart from the other object files
57
+ existingArchives := objectFiles .Clone ()
58
+ existingArchives .FilterSuffix (".a" )
59
+ objectFiles .FilterOutSuffix (".a" )
60
+
61
+ // Generate archive for each directory from the remianing object files
62
+ newArchives := paths .NewPathList ()
57
63
for _ , object := range objectFiles {
58
64
archive := object .Parent ().Join ("objs.a" )
59
- archives .AddIfMissing (archive )
65
+ newArchives .AddIfMissing (archive )
60
66
}
61
-
62
- // Generate archive for each directory
63
- for _ , archive := range archives {
67
+ for _ , archive := range newArchives {
64
68
archiveDir := archive .Parent ()
65
69
relatedObjectFiles := objectFiles .Clone ()
70
+ relatedObjectFiles .FilterOutSuffix (".a" )
66
71
relatedObjectFiles .Filter (func (object * paths.Path ) bool {
67
72
// extract all the object files that are in the same directory of the archive
68
73
return object .Parent ().EquivalentTo (archiveDir )
69
74
})
70
75
b .archiveCompiledFiles (archive .Parent (), paths .New (archive .Base ()), relatedObjectFiles )
71
76
}
72
77
73
- objectFileList = strings .Join (f .Map (archives .AsStrings (), wrapWithDoubleQuotes ), " " )
78
+ // Put everything together
79
+ allArchives := existingArchives .Clone ()
80
+ allArchives .AddAll (newArchives )
81
+ objectFileList = strings .Join (f .Map (allArchives .AsStrings (), wrapWithDoubleQuotes ), " " )
74
82
objectFileList = "-Wl,--whole-archive " + objectFileList + " -Wl,--no-whole-archive"
75
83
}
76
84
0 commit comments