diff --git a/llvm-build/README.md b/llvm-build/README.md index fd76e9fcf7559f59ce802ea6c7e313fb0e4655e7..caedd116f21c88530e0e7d5e49f5377334c5c0d4 100644 --- a/llvm-build/README.md +++ b/llvm-build/README.md @@ -52,6 +52,7 @@ build.py options: --enable-assertions # enable assertion when compiling --build-name # specify release package name --debug # build debug version llvm toolchain +--strip # strip llvm toolchain binaries --no-build-arm # skip triplet arm --no-build-aarch64 # skip triplet arm64 --no-build-x86_64 # skip triplet x86_64 diff --git a/llvm-build/build.py b/llvm-build/build.py index 3d9cf09ffc2c6bab15f575e7d524eb3a57c1be4d..583583bd9ac94c2a33bc7849834730370fafbe50 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -37,6 +37,7 @@ class BuildConfig(): self.do_package = not args.skip_package self.build_name = args.build_name self.debug = args.debug + self.strip = args.strip self.no_lto = args.no_lto self.build_instrumented = args.build_instrumented self.xunit_xml_output = args.xunit_xml_output @@ -97,6 +98,12 @@ class BuildConfig(): default=False, help='Building Clang and LLVM Tools for Debugging (only affects stage2)') + parser.add_argument( + '--strip', + action='store_true', + default=False, + help='Strip final LLVM binaries.') + parser.add_argument( '--no-build-arm', action='store_true', @@ -533,7 +540,9 @@ class LlvmCore(BuildUtils): cflags = '-fstack-protector-strong -fPIE' if not self.host_is_darwin(): - ldflags += ' -Wl,-z,relro,-z,now -pie -s' + ldflags += ' -Wl,-z,relro,-z,now -pie' + if self.build_config.strip: + ldflags += ' -s' self.llvm_compile_llvm_defines(llvm_defines, llvm_cc, llvm_cxx, cflags, ldflags) @@ -832,7 +841,9 @@ class LlvmLibs(BuildUtils): '-stdlib=libc++', ] if not self.host_is_darwin(): - ldflag.append('-Wl,-z,relro,-z,now -s -pie') + ldflag.append('-Wl,-z,relro,-z,now -pie') + if self.build_config.strip: + ldflag.append('-s') ldflags.extend(ldflag) @@ -1461,7 +1472,9 @@ class LldbMi(BuildUtils): cflags = [] cxxflags =[] ldflags = ['-fuse-ld=lld', '-Wl,-rpath,%s' % '\$ORIGIN/../lib'] - ldflags.append('-Wl,-z,relro,-z,now -pie -s') + ldflags.append('-Wl,-z,relro,-z,now -pie') + if self.build_config.strip: + ldflags.append('-s') ldflags.append('-L%s' % os.path.join(llvm_path, 'lib')) cxxflags.append('-std=c++14') @@ -1697,7 +1710,7 @@ class LlvmPackage(BuildUtils): continue if bin_filename not in necessary_bin_files: os.remove(binary) - elif bin_filename not in script_bins: + elif bin_filename not in script_bins and self.build_config.strip: if bin_filename not in need_x_bins_darwin and self.host_is_darwin(): self.check_call(['strip', '-x', binary]) else: @@ -1707,7 +1720,7 @@ class LlvmPackage(BuildUtils): def strip_lldb_server(self, host, install_dir): clang_version_bin_dir = os.path.join(install_dir, 'lib', 'clang', self.build_config.CLANG_VERSION, 'bin') - if not host.startswith('linux') or not os.path.exists(clang_version_bin_dir): + if not host.startswith('linux') or not os.path.exists(clang_version_bin_dir) or not self.build_config.strip: return llvm_strip = os.path.join(install_dir, 'bin', 'llvm-strip') for llvm_triple_dir in os.listdir(clang_version_bin_dir):