Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS
@ 2017-08-20 13:34 Thomas Petazzoni
  2017-08-20 13:34 ` [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking Thomas Petazzoni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2017-08-20 13:34 UTC (permalink / raw)
  To: buildroot

Just like -lpthread was passed in LIBS, -latomic should also be passed
in LIBS. In order for this to work, we however need to first fix
cc-tool's Makefile.am so that it does not overwrite LIBS.

This is the first part of fixing the build of cc-tool in a static
linking scenario on SPARC, i.e to fix:

  http://autobuild.buildroot.net/results/ed9f2524d0ccef318ff1bc99e5dea980111de989/

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
Note: I believe that the -lpthread conditionally added to LIBS when
static linking is useless now. Indeed, the two C libraries that
support static linking (musl and uclibc) now have a single libc
library, so -lpthread is not needed. Glibc does not support static
linking.

This can be cleaned up in next.
---
 .../0003-Makefile.am-do-not-overwrite-LIBS.patch   | 49 ++++++++++++++++++++++
 package/cc-tool/cc-tool.mk                         |  5 ++-
 2 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100644 package/cc-tool/0003-Makefile.am-do-not-overwrite-LIBS.patch

diff --git a/package/cc-tool/0003-Makefile.am-do-not-overwrite-LIBS.patch b/package/cc-tool/0003-Makefile.am-do-not-overwrite-LIBS.patch
new file mode 100644
index 0000000..db62d97
--- /dev/null
+++ b/package/cc-tool/0003-Makefile.am-do-not-overwrite-LIBS.patch
@@ -0,0 +1,49 @@
+From af3098e05535ddb93bb065770d87738e46089efc Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+Date: Sun, 20 Aug 2017 15:06:01 +0200
+Subject: [PATCH] Makefile.am: do not overwrite LIBS
+
+LIBS is meant to be passed on the command line with additional
+libraries, it should not be overwritten by Makefile.am.
+
+Instead:
+
+ - Use LDADD to link with external libraries
+
+ - Use <target>_LDFLAGS for additional, non-libraries, linker flags
+
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+---
+ Makefile.am | 8 +++-----
+ 1 file changed, 3 insertions(+), 5 deletions(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index e79e47b..ed83d91 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -10,14 +10,12 @@ AM_LDFLAGS = \
+ 
+ #	$(BOOST_THREADS_LDFLAGS)
+       
+-LDADD = $(LIBUSB_LIBS) 
+-
+-LIBS = -s \
++LDADD = $(LIBUSB_LIBS) \
+ 	$(BOOST_FILESYSTEM_LIBS) \
+ 	$(BOOST_REGEX_LIBS) \
+ 	$(BOOST_SYSTEM_LIBS) \
+ 	$(BOOST_PROGRAM_OPTIONS_LIBS)
+-   
++
+ #	$(BOOST_THREADS_LIBS)
+ 
+ bin_PROGRAMS=cc-tool
+@@ -30,4 +28,4 @@ cc_tool_SOURCES=src/main.cpp src/application/cc_flasher.cpp src/application/cc_b
+ 		src/programmer/cc_253x_254x.cpp src/programmer/cc_251x_111x.cpp \
+ 		src/programmer/cc_243x.cpp src/programmer/cc_programmer.cpp \
+ 		src/programmer/cc_unit_driver.cpp src/programmer/cc_unit_info.cpp
+-
++cc_tool_LDFLAGS=-s
+-- 
+2.9.4
+
diff --git a/package/cc-tool/cc-tool.mk b/package/cc-tool/cc-tool.mk
index 37ac57e..e170e06 100644
--- a/package/cc-tool/cc-tool.mk
+++ b/package/cc-tool/cc-tool.mk
@@ -16,15 +16,16 @@ CC_TOOL_AUTORECONF = YES
 
 # Configure script "discovers" boost in /usr/local if not given explicitly
 CC_TOOL_CONF_OPTS = --with-boost=$(STAGING_DIR)/usr
+CC_TOOL_CONF_ENV = LIBS="$(CC_TOOL_LIBS)"
 
 # Help boost.m4 find the Boost Regex library, which needs the pthread
 # library, but isn't detected using a modern (pkg-config) mechanism.
 ifeq ($(BR2_STATIC_LIBS),y)
-CC_TOOL_CONF_ENV += LIBS="-lpthread"
+CC_TOOL_LIBS += -lpthread
 endif
 
 ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
-CC_TOOL_CONF_ENV += CXXFLAGS="$(TARGET_CXXFLAGS) -latomic"
+CC_TOOL_LIBS += -latomic
 endif
 
 $(eval $(autotools-package))
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking
  2017-08-20 13:34 [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
@ 2017-08-20 13:34 ` Thomas Petazzoni
  2017-08-20 13:54   ` Thomas Petazzoni
  2017-08-20 13:54 ` [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
  2017-08-23 21:24 ` Thomas Petazzoni
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas Petazzoni @ 2017-08-20 13:34 UTC (permalink / raw)
  To: buildroot

This commit adds a patch to cc-tool that fixes the boost.m4 logic used
to detect the linker rpath option so that it works properly with
static linking and additional libraries passed in LIBS.

This is the second step to fix static linking of cc-tool on
architectures like SPARC that need to link against libatomic:

  http://autobuild.buildroot.net/results/ed9f2524d0ccef318ff1bc99e5dea980111de989/

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 ...-fix-rpath-option-check-for-static-linkin.patch | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 package/cc-tool/0004-m4-boost.m4-fix-rpath-option-check-for-static-linkin.patch

diff --git a/package/cc-tool/0004-m4-boost.m4-fix-rpath-option-check-for-static-linkin.patch b/package/cc-tool/0004-m4-boost.m4-fix-rpath-option-check-for-static-linkin.patch
new file mode 100644
index 0000000..acff107
--- /dev/null
+++ b/package/cc-tool/0004-m4-boost.m4-fix-rpath-option-check-for-static-linkin.patch
@@ -0,0 +1,44 @@
+From 5e74a15ce1e093b4d8e83cdade60a43b09d698de Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+Date: Sun, 20 Aug 2017 15:25:06 +0200
+Subject: [PATCH] m4/boost.m4: fix rpath option check for static linking
+
+When statically linking, the order in which -l options are passed is
+important. The contents of the LIBS option passed to the configure
+environment should be passed *after* other -l options used internally
+by the package.
+
+For example, libboost_program_options may used symbols from the
+libatomic library, and in this case, one need to pass LIBS="-latomic"
+to cc-tool's configure script. When using dynamic linking, this works
+fine, because the rpath test does "-latomic
+-lboost_program_options". However, when statically linking, this
+doesn't work because libboost_program_options uses symbols from
+libatomic, so -latomic must be passed *after* -lboost_program_options.
+
+Therefore, this commit inverts the list of variables used to construct
+LIBS before doing the _BOOST_AC_LINK_IFELSE() test detecting the rpath
+option to be used. Indeed, $boost_save_LIBS contains the previously
+saved LIBS variable, and should be passed after $Boost_lib_LIBS.
+
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
+---
+ m4/boost.m4 | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/m4/boost.m4 b/m4/boost.m4
+index be470a7..f1825ba 100644
+--- a/m4/boost.m4
++++ b/m4/boost.m4
+@@ -479,7 +479,7 @@ dnl generated only once above (before we start the for loops).
+            *)
+             for boost_cv_rpath_link_ldflag in -Wl,-R, -Wl,-rpath,; do
+               LDFLAGS="$boost_save_LDFLAGS -L$boost_ldpath $boost_cv_rpath_link_ldflag$boost_ldpath"
+-              LIBS="$boost_save_LIBS $Boost_lib_LIBS"
++              LIBS="$Boost_lib_LIBS $boost_save_LIBS"
+               _BOOST_AC_LINK_IFELSE([],
+                 [boost_rpath_link_ldflag_found=yes
+                 break],
+-- 
+2.9.4
+
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS
  2017-08-20 13:34 [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
  2017-08-20 13:34 ` [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking Thomas Petazzoni
@ 2017-08-20 13:54 ` Thomas Petazzoni
  2017-08-23 21:24 ` Thomas Petazzoni
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2017-08-20 13:54 UTC (permalink / raw)
  To: buildroot

Hello,

On Sun, 20 Aug 2017 15:34:15 +0200, Thomas Petazzoni wrote:

>  .../0003-Makefile.am-do-not-overwrite-LIBS.patch   | 49 ++++++++++++++++++++++

This patch has been submitted to some "upstream" at
https://github.com/dashesy/cc-tool/pull/4. The real upstream at
SourceForge seems to be dead, while this repo has seen commits last
year.

While at it, I also submitted another patch we had on cc-tool:
https://github.com/dashesy/cc-tool/pull/5.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking
  2017-08-20 13:34 ` [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking Thomas Petazzoni
@ 2017-08-20 13:54   ` Thomas Petazzoni
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2017-08-20 13:54 UTC (permalink / raw)
  To: buildroot

Hello,

On Sun, 20 Aug 2017 15:34:16 +0200, Thomas Petazzoni wrote:

>  ...-fix-rpath-option-check-for-static-linkin.patch | 44 ++++++++++++++++++++++

This patch was submitted upstream, but not in cc-tool since in fact
boost.m4 comes from a dedicated project, and gets duplicated in
cc-tool. So I've submitted to the official boost.m4 project,
https://github.com/tsuna/boost.m4/pull/103.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS
  2017-08-20 13:34 [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
  2017-08-20 13:34 ` [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking Thomas Petazzoni
  2017-08-20 13:54 ` [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
@ 2017-08-23 21:24 ` Thomas Petazzoni
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2017-08-23 21:24 UTC (permalink / raw)
  To: buildroot

Hello,

On Sun, 20 Aug 2017 15:34:15 +0200, Thomas Petazzoni wrote:
> Just like -lpthread was passed in LIBS, -latomic should also be passed
> in LIBS. In order for this to work, we however need to first fix
> cc-tool's Makefile.am so that it does not overwrite LIBS.
> 
> This is the first part of fixing the build of cc-tool in a static
> linking scenario on SPARC, i.e to fix:
> 
>   http://autobuild.buildroot.net/results/ed9f2524d0ccef318ff1bc99e5dea980111de989/
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
> Note: I believe that the -lpthread conditionally added to LIBS when
> static linking is useless now. Indeed, the two C libraries that
> support static linking (musl and uclibc) now have a single libc
> library, so -lpthread is not needed. Glibc does not support static
> linking.

I've applied both patches to master. The cc-tool patch has been merged
upstream already (so I adjusted the patch description). No feedback from
upstream on the boost.m4 patch though.

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-23 21:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-20 13:34 [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
2017-08-20 13:34 ` [Buildroot] [PATCH 2/2] cc-tool: add patch fixing boost.m4 logic for static linking Thomas Petazzoni
2017-08-20 13:54   ` Thomas Petazzoni
2017-08-20 13:54 ` [Buildroot] [PATCH 1/2] cc-tool: pass -latomic in LIBS Thomas Petazzoni
2017-08-23 21:24 ` Thomas Petazzoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox