Skip to content

Commit f20c72e

Browse files
committed
Create an archive file if the number of object files is too big
This should fix the command line too big issue on Windows.
1 parent 56fc6b7 commit f20c72e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Diff for: legacy/builder/phases/linker.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,26 @@ func (s *Linker) Run(ctx *types.Context) error {
5757
}
5858

5959
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+
}
6280

6381
properties := buildProperties.Clone()
6482
properties.Set(constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS))

0 commit comments

Comments
 (0)