Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just fixing an old TODO, no dramatic behavior change. Differential Revision: https://reviews.llvm.org/D102843
- Loading branch information
Showing
6 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This file defines a template for using .export files. | ||
# | ||
# Parameters: | ||
# exports_file (required) | ||
# Path of the .exports file to use. | ||
# | ||
# Example use: | ||
# symbol_exports("my_exports") { | ||
# exports_file = "//foo/bar/my.exports" | ||
# } | ||
# ... | ||
# shared_library("my_target") { | ||
# deps = [ ":my_exports" ] # Adds correct ldflags. | ||
# ... | ||
# } | ||
|
||
# Corresponds to add_llvm_symbol_exports() in the CMake build. | ||
template("symbol_exports") { | ||
# Create a platform-appropriate name for the temporary file. | ||
linker_file = get_path_info(invoker.exports_file, "name") | ||
if (current_os == "mac") { | ||
linker_file = linker_file + "_symbols.txt" | ||
} else if (current_os == "win") { | ||
linker_file = linker_file + ".def" | ||
} else { | ||
linker_file = linker_file + ".script" | ||
} | ||
linker_file = "$target_gen_dir/$linker_file" | ||
rebased_linker_file = rebase_path(linker_file, root_build_dir) | ||
|
||
config_name = "${target_name}_config" | ||
config(config_name) { | ||
# FIXME: With this setup, targets are not relinked automatically | ||
# when the input exports file is touched but nothing else changes. | ||
# https://groups.google.com/a/chromium.org/g/gn-dev/c/sN09GYS1ufE | ||
visibility = [ ":$target_name" ] | ||
if (current_os == "mac") { | ||
ldflags = [ "-Wl,-exported_symbols_list,$rebased_linker_file" ] | ||
} else if (current_os == "win") { | ||
ldflags = [ "/DEF:$rebased_linker_file" ] | ||
} else { | ||
ldflags = [ "-Wl,--version-script,$rebased_linker_file" ] | ||
} | ||
} | ||
|
||
action(target_name) { | ||
script = "//llvm/utils/gn/build/symbol_exports.py" | ||
inputs = [ invoker.exports_file ] | ||
outputs = [ linker_file ] | ||
args = [ | ||
"--format=" + current_os, | ||
rebase_path(inputs[0], root_build_dir), | ||
rebased_linker_file, | ||
] | ||
|
||
# Let targets depending on this receive the right ldflags. | ||
public_configs = [ ":$config_name" ] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Converts a .exports file to a format consumable by linkers. | ||
An .exports file is a file with one exported symbol per line. | ||
This script converts a .exports file into a format that linkers | ||
can understand: | ||
- It prepends a `_` to each line for use with -exported_symbols_list for Darwin | ||
- It writes a .def file for use with /DEF: for Windows | ||
- It writes a linker script for use with --version-script elsewhere | ||
""" | ||
|
||
import argparse | ||
import sys | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument('--format', required=True, | ||
choices=('linux','mac','win')) | ||
parser.add_argument('source') | ||
parser.add_argument('output') | ||
args = parser.parse_args() | ||
|
||
symbols = open(args.source).readlines() | ||
|
||
if args.format == 'linux': | ||
output_lines = (['FOO {\n', | ||
' global:\n',] + | ||
[' %s;\n' % s.rstrip() for s in symbols] + | ||
[' local: *;\n', | ||
'}\n']) | ||
elif args.format == 'mac': | ||
output_lines = ['_' + s for s in symbols] | ||
else: | ||
assert args.format == 'win' | ||
output_lines = ['EXPORTS\n'] + [' ' + s for s in symbols] | ||
|
||
open(args.output, 'w').writelines(output_lines) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters