Skip to content

Commit

Permalink
extras: tools: Patch libtool to force -lpthread when using -nostdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
chouquette authored and jbkempf committed Aug 10, 2021
1 parent 30d673b commit 1037d00
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions extras/tools/libtool-2.4.6-lpthread.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From 7151ed6928f66d8ecd5a57d9db2b08f4fcc8f647 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <[email protected]>
Date: Mon, 2 Aug 2021 17:42:38 +0200
Subject: [PATCH] Force -lpthread when -nostdlib is provided to the C++ Gnu
linker

-nostdlib will be provided, which makes -pthread not imply -lpthread by
design
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
---
build-aux/ltmain.in | 8 ++++++++
m4/libtool.m4 | 5 +++++
2 files changed, 13 insertions(+)

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 96b37003..9f3a3d6f 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5183,6 +5183,14 @@ func_mode_link ()
*" $arg "*) ;;
* ) func_append new_inherited_linker_flags " $arg" ;;
esac
+ case $arg in
+ -pthread|-pthreads)
+ if test -n "$hardcode_lpthread" &&
+ test yes = "$hardcode_lpthread"; then
+ func_append new_inherited_linker_flags " -lpthread"
+ fi
+ ;;
+ esac
continue
;;

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index f2d1f398..221ee689 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -6207,6 +6207,8 @@ _LT_TAGDECL([], [postlink_cmds], [2],
[Commands necessary for finishing linking programs])
_LT_TAGDECL([], [file_list_spec], [1],
[Specify filename containing input files])
+_LT_TAGDECL([], [hardcode_lpthread], [0],
+ [Force -lpthread even when -ptherad is specified])
dnl FIXME: Not yet implemented
dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
dnl [Compiler flag to generate thread safe objects])
@@ -6343,6 +6345,7 @@ _LT_TAGVAR(reload_cmds, $1)=$reload_cmds
_LT_TAGVAR(no_undefined_flag, $1)=
_LT_TAGVAR(whole_archive_flag_spec, $1)=
_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+_LT_TAGVAR(hardcode_lpthread, $1)=no

# Source file extension for C++ test sources.
ac_ext=cpp
@@ -6417,6 +6420,8 @@ if test yes != "$_lt_caught_CXX_error"; then
_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir'
_LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic'

+ _LT_TAGVAR(hardcode_lpthread, $1)='yes'
+
# If archive_cmds runs LD, not CC, wlarc should be empty
# XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
# investigate it a little bit more. (MM)
--
2.30.2

1 change: 1 addition & 0 deletions extras/tools/tools.mak
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ libtool: libtool-$(LIBTOOL_VERSION).tar.gz
$(APPLY) $(TOOLS)/libtool-2.4.6-san.patch
$(APPLY) $(TOOLS)/libtool-2.4.6-clang-libs.patch
$(APPLY) $(TOOLS)/libtool-2.4.6-response-files.patch
$(APPLY) $(TOOLS)/libtool-2.4.6-lpthread.patch
$(MOVE)

.buildlibtool: libtool .automake .help2man
Expand Down

0 comments on commit 1037d00

Please sign in to comment.