Skip to content

Commit

Permalink
Meta: Use response file for linking shared libraries in GN build
Browse files Browse the repository at this point in the history
Linking liblagom-web.so produces a ~132K long command line. Ninja
passes the whole command line as a single arg to `sh -c <arg>`,
and the limit for single arguments (`MAX_ARG_STRLEN`) on Linux
is `PAGE_SIZE * 32` == 128K.

A response file passes the list of files in a file on disk, which
lets us sidestep this problem. Ninja writes response files before
invoking commands, and deletes them after (unless `-d keeprsp` is
passed to ninja, then it keeps them on disk).
  • Loading branch information
nico committed Dec 22, 2024
1 parent fadd346 commit 2f65e3d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Meta/gn/build/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ template("unix_toolchain") {

tool("solink") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
rspfile = outfile + ".rsp"
rspfile_content = "{{inputs}}"
if (current_os == "ios" || current_os == "mac") {
command = "$ld -shared {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}} -Wl,-install_name,@rpath/{{target_output_name}}{{output_extension}}"
command = "$ld -shared {{ldflags}} -o $outfile @\"$rspfile\" {{libs}} {{frameworks}} -Wl,-install_name,@rpath/{{target_output_name}}{{output_extension}}"
default_output_extension = ".dylib"
} else {
command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -Wl,-rpath,\\\$ORIGIN -o $outfile {{inputs}} {{libs}}"
command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -Wl,-rpath,\\\$ORIGIN -o $outfile @\"$rspfile\" {{libs}}"
default_output_extension = ".so"
}
description = "SOLINK $outfile"
Expand Down

0 comments on commit 2f65e3d

Please sign in to comment.