summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Prichard <rprichard@google.com>2018-04-05 16:28:55 -0700
committerRyan Prichard <rprichard@google.com>2018-04-05 17:27:27 -0700
commit2485f18b02e8a6d2173314daa570d81f580607c3 (patch)
tree15d9cf774ffc73a9011d19c3b69318e61954a452
parentb415c49e4c4b8fcddc1f5551bb1e357a8fe93ad7 (diff)
downloadbinutils-2485f18b02e8a6d2173314daa570d81f580607c3.tar.gz
Copy libwinpthread-1.dll alongside the binutils executables on Windows. The install_winpthreads function is copied from llvm_android: https://android.googlesource.com/toolchain/llvm_android/+/bd22d9779676661ae9571972dcd744c42c70ffd0/build.py#1063 Most C++ MinGW programs need libpthread, because even libstdc++'s "operator new" pulls in EH code, which calls into libpthread. Currently, the ld.gold.exe and dwp.exe binaries need libwinpthread-1.dll, which is not generally in the PATH, so the binaries don't run. Previously, the Android GCC build of binutils linked ld.gold.exe and dwp.exe with -static, which selected the static libpthread.a. Packaging libwinpthread-1.dll alongside the binaries ensures that ld.gold.exe and the LLVMgold plugin use the same copy of the winpthreads runtime, which might be important. Test: ./toolchain/binutils/build.py --arch arm64 --host win64 Test: ./toolchain/binutils/build.py --arch arm64 --host win Test: ./toolchain/binutils/build.py --arch arm64 --host linux Test: ./toolchain/binutils/build.py --arch x86 --host win64 Bug: none Change-Id: I5fc2d38b67c72fa4760be1c2688ef88479759160
-rwxr-xr-xbuild.py38
1 files changed, 30 insertions, 8 deletions
diff --git a/build.py b/build.py
index 4a4f0981..f22e8218 100755
--- a/build.py
+++ b/build.py
@@ -60,6 +60,12 @@ def chdir(path):
os.chdir(path)
+def install_file(src, dst):
+ """shutil.copy2 with logging."""
+ logger().info('copy %s %s', src, dst)
+ shutil.copy2(src, dst)
+
+
def check_call(cmd, *args, **kwargs):
"""subprocess.check_call with logging."""
logger().info('check_call %s', subprocess.list2cmdline(cmd))
@@ -84,6 +90,7 @@ def configure(arch, host, install_dir, src_dir):
'--host={}'.format(configure_host),
'--enable-initfini-array',
'--enable-plugins',
+ '--enable-threads',
'--disable-nls',
'--with-sysroot={}'.format(sysroot),
'--prefix={}'.format(install_dir),
@@ -97,12 +104,6 @@ def configure(arch, host, install_dir, src_dir):
# https://issuetracker.google.com/70838247
configure_args.append('--enable-gold=default')
- if not is_windows:
- # Multithreaded linking is implemented with pthreads, which we
- # historically couldn't use on Windows.
- # TODO: Try enabling this now that we have winpthreads in mingw.
- configure_args.append('--enable-threads')
-
env = {}
m32 = False
@@ -158,10 +159,31 @@ def build(jobs):
check_call(['make', '-j', str(jobs)])
-def install(jobs):
+def install_winpthreads(is_windows32, install_dir):
+ """Installs the winpthreads runtime to the Windows bin directory."""
+ lib_name = 'libwinpthread-1.dll'
+ mingw_dir = ndk.paths.android_path(
+ 'prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8',
+ 'x86_64-w64-mingw32')
+ # Yes, this indeed may be found in bin/ because the executables are the
+ # 64-bit version by default.
+ pthread_dir = 'lib32' if is_windows32 else 'bin'
+ lib_path = os.path.join(mingw_dir, pthread_dir, lib_name)
+
+ lib_install = os.path.join(install_dir, 'bin', lib_name)
+ install_file(lib_path, lib_install)
+
+
+def install(jobs, arch, host, install_dir):
"""Installs binutils."""
check_call(['make', 'install-strip', '-j', str(jobs)])
+ if host in ('win', 'win64'):
+ arch_install_dir = os.path.join(
+ install_dir, ndk.abis.arch_to_triple(arch))
+ install_winpthreads(host == 'win', install_dir)
+ install_winpthreads(host == 'win', arch_install_dir)
+
def dist(dist_dir, base_dir, package_name):
"""Packages binutils for distribution."""
@@ -237,7 +259,7 @@ def main():
install_timer = ndk.timer.Timer()
with install_timer:
- install(args.jobs)
+ install(args.jobs, args.arch, args.host, install_dir)
finally:
chdir(orig_dir)