package/openblas: fix build failure due to forced FFLAGS
PATCH 1/3 package/openblas: fix build failure due to forced FFLAGS
From: Thomas De Schampheleire <[email protected]>
Buildroot specifies a value for FFLAGS on the make command-line. While the openblas makefiles allowed this principle for the most part by using 'override FFLAGS += ....', the make.inc file generated for the shipped 'lapack' sources just used a 'FFLAGS = ...' statement, whose value is then eclipsed by the command-line FFLAGS.
This meant that -fPIC may be passed to the link step but not to all relevant source files, causing relocation failures.
--- ...port-for-passing-FFLAGS-on-the-make-.patch | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch
As the openblas patch is fixing a generic problem, I will attempt to upstream it.
package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch new file +47 -0
@@ -0,0 +1,47 @@ +From 4d3829fa52240c2b7e48770ab19584db33ba7863 Mon Sep 17 00:00:00 2001 +From: Thomas De Schampheleire <[email protected]> +Date: Fri, 5 Mar 2021 11:17:59 +0100 +Subject: [PATCH 2/2] Makefile: fix support for passing FFLAGS on the make + command line + +When openblas is build while passing FFLAGS on the make command line, the +compilation of lapack objects will not contain the flags specified in +Makefile but _only_ those passed in FFLAGS. + +This can lead to build failure, e.g. because -fPIC is not passed to the +compilation of most lapack objects, but is given to the link command: + +.../buildroot/output/host/bin/x86_64-linux-gcc -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -O2 -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DNO_WARMUP -DMAX_CPU_NUMBER=4 -DMAX_PARALLEL_NUMBER=1 -DVERSION=\"0.3.9\" -DASMNAME= -DASMFNAME=_ -DNAME=_ -DCNAME= -DCHAR_NAME=\"_\" -DCHAR_CNAME=\"\" -DNO_AFFINITY -I.. -shared -o ../libopenblas_nehalem-r0.3.9.so \ +-Wl,--whole-archive ../libopenblas_nehalem-r0.3.9.a -Wl,--no-whole-archive \ +-Wl,-soname,libopenblas.so.0 -lm -lgfortran -lm -lgfortran +.../buildroot/output/host/opt/ext-toolchain/bin/../lib/gcc/x86_64-buildroot-linux-musl/9.3.0/../../../../x86_64-buildroot-linux-musl/bin/ld: ../libopenblas_nehalem-r0.3.9.a(sbdsvdx.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC + +In the initial support for this principle, added in commit +d0e731e8b825e7a554f245aa8f1118dcec9e2728, the flags specified in the +makefile were appended to the flags specified on the command-line. + +Fix this situation by using 'override' for 'FFLAGS' in +lapack-netlib/make.inc. The flags passed on the command-line are already +part of the LAPACK_FFLAGS variable, so no '+=' is needed here. + +Signed-off-by: Thomas De Schampheleire <[email protected]> +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index fc5fe3f5..8ae1ff47 100644 +--- a/Makefile ++++ b/Makefile +@@ -248,7 +248,7 @@ prof_lapack : lapack_prebuild + lapack_prebuild : + ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN))) + - at echo "FC = $(FC)" > $(NETLIB_LAPACK_DIR)/make.inc +- - at echo "FFLAGS = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc ++ - at echo "override FFLAGS = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc + - at echo "POPTS = $(LAPACK_FPFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc + - at echo "FFLAGS_NOOPT = -O0 $(LAPACK_NOOPT)" >> $(NETLIB_LAPACK_DIR)/make.inc + - at echo "PNOOPT = $(LAPACK_FPFLAGS) -O0" >> $(NETLIB_LAPACK_DIR)/make.inc +-- +2.26.2 +
Signature · 1 line
2.26.2
PATCH 2/3 package/openblas: strip any optimization flag where needed
From: Thomas De Schampheleire <[email protected]>
openblas strips off -O1-O3 for certain source files, but forgets to handle -Os, -Og and -O. This means that the intended effect of 'no optimization' is not always reached.
--- ...nsider-Os-when-determining-LAPACK_NO.patch | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patch
As the openblas patch is fixing a generic problem, I will attempt to upstream it.
package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patch new file +31 -0
@@ -0,0 +1,31 @@ +From ced08de1ad74811bc23d74121751537bfd8e9556 Mon Sep 17 00:00:00 2001 +From: Thomas De Schampheleire <[email protected]> +Date: Fri, 5 Mar 2021 11:15:52 +0100 +Subject: [PATCH 1/2] Makefile: also consider -O, -Og and -Os when stripping flags + +gcc also supports -O, -Og and -Os as optimization flags. +They may be given on the make command-line by users. + +For the calculation of LAPACK_NOOPT, all such flags should be considered. + +Signed-off-by: Thomas De Schampheleire <[email protected]> +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index a22e16ba..fc5fe3f5 100644 +--- a/Makefile ++++ b/Makefile +@@ -32,7 +32,7 @@ export NOFORTRAN + export NO_LAPACK + endif + +-LAPACK_NOOPT := $(filter-out -O0 -O1 -O2 -O3 -Ofast,$(LAPACK_FFLAGS)) ++LAPACK_NOOPT := $(filter-out -O0 -O1 -O2 -O3 -Ofast -O -Og -Os,$(LAPACK_FFLAGS)) + + SUBDIRS_ALL = $(SUBDIRS) test ctest utest exports benchmark ../laswp ../bench cpp_thread_test + +-- +2.26.2 +
Signature · 1 line
2.26.2
PATCH 2/3 package/openblas: strip any optimization flag where needed
Quoted 24 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas De Schampheleire <[email protected]> writes:
From: Thomas De Schampheleire <[email protected]> openblas strips off -O1-O3 for certain source files, but forgets to handle -Os, -Og and -O. This means that the intended effect of 'no optimization' is not always reached.
Signed-off-by Thomas De Schampheleire <[email protected]>--- ...nsider-Os-when-determining-LAPACK_NO.patch | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644
package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patchAs the openblas patch is fixing a generic problem, I will attempt to upstream it.
diff --git
a/package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patchb/package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patchnew file mode 100644
index 0000000000..0ff9051ae4
package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patch line 4
Quoted 4 lines
package/openblas/0003-Makefile-also-consider-Os-when-determining-LAPACK_NO.patch new file +4
-0@@ -0,0 +1,31 @@ +From ced08de1ad74811bc23d74121751537bfd8e9556 Mon Sep 17 00:00:00 2001 +From: Thomas De Schampheleire <[email protected]> +Date: Fri, 5 Mar 2021 11:15:52 +0100 +Subject: [PATCH 1/2] Makefile: also consider -O, -Og and -Os when stripping flags
Same comment about -N. Committed with that fixed, thanks.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 2/3 package/openblas: strip any optimization flag where needed
In reply to Thomas De SchampheleireQuoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas De Schampheleire <[email protected]> writes:
From: Thomas De Schampheleire <[email protected]> openblas strips off -O1-O3 for certain source files, but forgets to handle -Os, -Og and -O. This means that the intended effect of 'no optimization' is not always reached.
Signed-off-by Thomas De Schampheleire <[email protected]>
Committed to 2020.11.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 3/3 package/openblas: respect the optimization level specified by Buildroot
In reply to Thomas De SchampheleireFrom: Thomas De Schampheleire <[email protected]>
openblas internally sets -O2, after the flags being passed by Buildroot (e.g. -Os).
Patch openblas to let the Buildroot-specified flag survives.
--- ...don-t-specify-optimization-level-bui.patch | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 package/openblas/0004-Makefile.system-don-t-specify-optimization-level-bui.patch
As this openblas patch is quite specific to Buildroot (the problem is hard to handle generically as you don't really know which flags the user may manipulate on the command-line), I don't think this can be upstreamed.
package/openblas/0004-Makefile.system-don-t-specify-optimization-level-bui.patch new file +40 -0
@@ -0,0 +1,40 @@ +From 6d1c1350977d74fb2239f765bd92a5763cd3bb73 Mon Sep 17 00:00:00 2001 +From: Thomas De Schampheleire <[email protected]> +Date: Fri, 5 Mar 2021 14:09:23 +0100 +Subject: [PATCH] Makefile.system: don't specify optimization level + [buildroot-specific] + +Buildroot will pass an optimization level, but it is ignored because the +openblas makefiles _append_ to the flags passed on the command-line. + +The CFLAGS/FFLAGS would e.g. contain '-Os -O2' in which -O2 survives. + +Remove the optimization level specified in openblas itself. + +Signed-off-by: Thomas De Schampheleire <[email protected]> + +--- + Makefile.system | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/Makefile.system b/Makefile.system +index 1e30d05a..04b0be16 100644 +--- a/Makefile.system ++++ b/Makefile.system +@@ -1216,11 +1216,11 @@ FCOMMON_OPT += -g + endif + + ifndef COMMON_OPT +-COMMON_OPT = -O2 ++COMMON_OPT = + endif + + ifndef FCOMMON_OPT +-FCOMMON_OPT = -O2 -frecursive ++FCOMMON_OPT = -frecursive + endif + + override CFLAGS += $(COMMON_OPT) $(CCOMMON_OPT) -I$(TOPDIR) +-- +2.26.2 +
Signature · 1 line
2.26.2
PATCH 3/3 package/openblas: respect the optimization level specified by Buildroot
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas De Schampheleire <[email protected]> writes:
From: Thomas De Schampheleire <[email protected]> openblas internally sets -O2, after the flags being passed by Buildroot (e.g. -Os).
Patch openblas to let the Buildroot-specified flag survives.
Signed-off-by Thomas De Schampheleire <[email protected]>
Committed, thanks.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 3/3 package/openblas: respect the optimization level specified by Buildroot
In reply to Thomas De SchampheleireQuoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas De Schampheleire <[email protected]> writes:
From: Thomas De Schampheleire <[email protected]> openblas internally sets -O2, after the flags being passed by Buildroot (e.g. -Os).
Patch openblas to let the Buildroot-specified flag survives.
Signed-off-by Thomas De Schampheleire <[email protected]>
Committed to 2020.11.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 1/3 package/openblas: fix build failure due to forced FFLAGS
In reply to Thomas De SchampheleireQuoted 31 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas De Schampheleire <[email protected]> writes:
From: Thomas De Schampheleire <[email protected]> Buildroot specifies a value for FFLAGS on the make command-line. While the openblas makefiles allowed this principle for the most part by using 'override FFLAGS += ....', the make.inc file generated for the shipped 'lapack' sources just used a 'FFLAGS = ...' statement, whose value is then eclipsed by the command-line FFLAGS.
This meant that -fPIC may be passed to the link step but not to all relevant source files, causing relocation failures.
Signed-off-by Thomas De Schampheleire <[email protected]>--- ...port-for-passing-FFLAGS-on-the-make-.patch | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644
package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patchAs the openblas patch is fixing a generic problem, I will attempt to upstream it.
diff --git
a/package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patchb/package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patchnew file mode 100644
index 0000000000..c6c73bb0fd
package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch line 5
Quoted 5 lines
package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch new file +5
-0@@ -0,0 +1,47 @@ +From 4d3829fa52240c2b7e48770ab19584db33ba7863 Mon Sep 17 00:00:00 2001 +From: Thomas De Schampheleire <[email protected]> +Date: Fri, 5 Mar 2021 11:17:59 +0100 +Subject: [PATCH 2/2] Makefile: fix support for passing FFLAGS on the make + command line
NIT: Use the -N option for git format-patch to get rid of the 2/2 as pointed out by ./utils/check-package:
Applying: package/openblas: fix build failure due to forced FFLAGS package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch:4:
generate your patches with 'git format-patch -N'
package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch line 7
Quoted 2 lines
package/openblas/0002-Makefile-fix-support-for-passing-FFLAGS-on-the-make-.patch new file +2
-0+ +When openblas is build while passing FFLAGS on the make command line, the
s/build/built/
Committed with these minor fixes, thanks.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 1/3 package/openblas: fix build failure due to forced FFLAGS
In reply to Thomas De SchampheleireQuoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Thomas" == Thomas De Schampheleire <[email protected]> writes:
From: Thomas De Schampheleire <[email protected]> Buildroot specifies a value for FFLAGS on the make command-line. While the openblas makefiles allowed this principle for the most part by using 'override FFLAGS += ....', the make.inc file generated for the shipped 'lapack' sources just used a 'FFLAGS = ...' statement, whose value is then eclipsed by the command-line FFLAGS.
Quoted 5 lines
This meant that -fPIC may be passed to the link step but not to all relevant source files, causing relocation failures.
Committed to 2020.11.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard