[m-rev.] for review: Fix --link-object <archive> with --restricted-command-line.

Julien Fischer jfischer at opturion.com
Wed Aug 6 12:58:35 AEST 2014


Hi Peter,

On Wed, 6 Aug 2014, Peter Wang wrote:

> Branches: master, 14.01
>
> When --restricted-command-line is enabled, we try to shorten the link
> command by creating a temporary archive of object files, including files
> specified with --link-object.  --link-object can also be used to specify
> archives (.a) to link with,

The documentation for --link-object says nothing about using it with
archives, although the first example of its use in the user's guide is
with an archive.

If it is intended that --link-object be used with archives, then I think
the documentation should explicitly say that.

> which results in nested archives in the
> temporary archive.  The linker does not look for object files in nested
> archives so it does not work as intended.
>
> compiler/compile_target_code.m:
> 	Create the temporary archive for --restricted-command-line
> 	consisting of only the file names in ObjectsList with known
> 	object file extensions.  Pass any other names in ObjectsList
> 	to the link command directly.
>
> diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
> index db24324..99cadac 100644
> --- a/compiler/compile_target_code.m
> +++ b/compiler/compile_target_code.m
> @@ -2076,15 +2076,19 @@ link_exe_or_shared_lib(Globals, ErrorStream, LinkTargetType, ModuleName,
>             % that following link command will call sub-commands itself
>             % and thus overflow the command line, so in this case
>             % we first create an archive of all of the object files.
> -            %
>             RestrictedCommandLine = yes,
>             io.make_temp(TmpFile, !IO),
>             globals.lookup_string_option(Globals, library_extension, LibExt),
>             TmpArchive = TmpFile ++ LibExt,
> -            create_archive(Globals, ErrorStream, TmpArchive, yes, ObjectsList,
> -                ArchiveSucceeded, !IO),
> +            % Only include actual object files into the temporary archive,

s/into/in/

> +            % not other files such as other archives.
> +            filter_object_files(Globals, ObjectsList,
> +                ProperObjectFiles, NonObjectFiles),
> +            create_archive(Globals, ErrorStream, TmpArchive, yes,
> +                ProperObjectFiles, ArchiveSucceeded, !IO),
>             MaybeDeleteTmpArchive = yes(TmpArchive),
> -            Objects = TmpArchive
> +            join_quoted_string_list([TmpArchive | NonObjectFiles],
> +                "", "", " ", Objects)
>         ;
>             RestrictedCommandLine = no,
>             ArchiveSucceeded = yes,

The change is fine otherwise.

Cheers,
Julien.



More information about the reviews mailing list