@@ -57,8 +57,26 @@ func (s *Linker) Run(ctx *types.Context) error {
57
57
}
58
58
59
59
func link (ctx * types.Context , objectFiles paths.PathList , coreDotARelPath * paths.Path , coreArchiveFilePath * paths.Path , buildProperties * properties.Map ) error {
60
- quotedObjectFiles := utils .Map (objectFiles .AsStrings (), wrapWithDoubleQuotes )
61
- objectFileList := strings .Join (quotedObjectFiles , " " )
60
+ objectFileList := strings .Join (utils .Map (objectFiles .AsStrings (), wrapWithDoubleQuotes ), " " )
61
+
62
+ // If command line length is too big (> 30000 chars), try to collect the object files into an archive
63
+ // and use that archive to complete the build.
64
+ if len (objectFileList ) > 30000 {
65
+ objectFilesArchive := ctx .BuildPath .Join ("object_files.a" )
66
+ // Recreate the archive at every build
67
+ _ = objectFilesArchive .Remove ()
68
+ properties := buildProperties .Clone ()
69
+ properties .Set ("archive_file" , objectFilesArchive .Base ())
70
+ properties .SetPath ("archive_file_path" , objectFilesArchive )
71
+ for _ , objFile := range objectFiles {
72
+ properties .SetPath ("object_file" , objFile )
73
+ _ , _ , err := builder_utils .ExecRecipe (ctx , properties , constants .RECIPE_AR_PATTERN , false , utils .ShowIfVerbose /* stdout */ , utils .Show /* stderr */ )
74
+ if err != nil {
75
+ return err
76
+ }
77
+ }
78
+ objectFileList = "-Wl,--whole-archive " + wrapWithDoubleQuotes (objectFilesArchive .String ()) + " -Wl,--no-whole-archive"
79
+ }
62
80
63
81
properties := buildProperties .Clone ()
64
82
properties .Set (constants .BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS , properties .Get (constants .BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS ))
0 commit comments