Skip to content

[build-script] Add an option to force the linker used. #79329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ def create_argument_parser():
'`bootstrapping-with-hostlibs`, `crosscompile`, and '
'`crosscompile-with-hostlibs`')

option('--use-linker', store('use_linker'),
choices=['gold', 'lld'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer versions of the GNU bfd linker works on newer platforms now too and IIRC gold is going away so I don't think we should block using it anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that bfd doesn't have a specific name... so people will just get it by not setting the flag.

default=None,
metavar='USE_LINKER',
help='Choose the default linker to use when compiling LLVM/Swift')

# -------------------------------------------------------------------------
in_group('Host and cross-compilation targets')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ def test_option_swift_compiler_version(self):
with self.assertRaises(ParserError):
self.parse_default_args([option_string, '0.0.0.1'])

def test_option_use_linker(self):
option_string = '--use-linker'

self.parse_default_args([option_string, 'lld'])
self.parse_default_args([option_string, 'gold'])

with self.assertRaises(ParserError):
self.parse_default_args([option_string, 'foo'])

def test_option_swift_user_visible_version(self):
option_string = '--swift-user-visible-version'

Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
'xros_all': False,
'llvm_install_components': defaults.llvm_install_components(),
'clean_install_destdir': False,
'use_linker': None,
}


Expand Down Expand Up @@ -894,4 +895,5 @@ class BuildScriptImplOption(_BaseOption):
IgnoreOption('--xros-all'),

StrOption('--llvm-install-components'),
ChoicesOption('--use-linker', dest='use_linker', choices=['gold', 'lld']),
]
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
# Add the cmake options for compiler version information.
self.cmake_options.extend(self._version_flags)

# Add linker flags if specified
self.cmake_options.extend(self._use_linker)

@classmethod
def is_build_script_impl_product(cls):
"""is_build_script_impl_product -> bool
Expand Down Expand Up @@ -83,6 +86,12 @@ def _version_flags(self):
"clang-{}".format(self.args.clang_compiler_version))
return result

@property
def _use_linker(self):
if self.args.use_linker is None:
return []
return [('CLANG_DEFAULT_LINKER', self.args.use_linker)]

@classmethod
def get_dependencies(cls):
return [cmark.CMark]
Expand Down
35 changes: 34 additions & 1 deletion utils/swift_build_support/tests/products/test_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def setUp(self):
compiler_vendor='none',
clang_compiler_version=None,
clang_user_visible_version=None,
darwin_deployment_version_osx='10.9')
darwin_deployment_version_osx='10.9',
use_linker=None)

# Setup shell
shell.dry_run = True
Expand Down Expand Up @@ -154,3 +155,35 @@ def test_version_flags(self):
'-DCLANG_REPOSITORY_STRING=clang-2.2.3',
llvm.cmake_options
)

def test_use_linker(self):
self.args.use_linker = None
llvm = LLVM(
args=self.args,
toolchain=self.toolchain,
source_dir='/path/to/src',
build_dir='/path/to/build')
for s in llvm.cmake_options:
self.assertFalse('CLANG_DEFAULT_LINKER' in s)

self.args.use_linker = 'gold'
llvm = LLVM(
args=self.args,
toolchain=self.toolchain,
source_dir='/path/to/src',
build_dir='/path/to/build')
self.assertIn(
'-DCLANG_DEFAULT_LINKER=gold',
llvm.cmake_options
)

self.args.use_linker = 'lld'
llvm = LLVM(
args=self.args,
toolchain=self.toolchain,
source_dir='/path/to/src',
build_dir='/path/to/build')
self.assertIn(
'-DCLANG_DEFAULT_LINKER=lld',
llvm.cmake_options
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def setUp(self):
clang_compiler_version=None,
clang_user_visible_version=None,
cross_compile_hosts='linux-aarch64',
cross_compile_deps_path='sysroot'
cross_compile_deps_path='sysroot',
use_linker=None
)

# Setup shell
Expand Down