Skip to contentSkip to conversation

pkg-autotools: generic configure fix for powerpc64

RFC PATCH Superseded Sam Bobroff 4 participants 9 messages Nov 17, 2016 – Nov 18, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

Many (100+) packages supported by buildroot contain old configure scripts (or build them from old versions of autotools) that are unable to determine how to link shared libraries on powerpc64 and powerpc64le. This causes that test to erroneously fail on toolchains that are not "bi-endian" (which is the case for toolchains built by buildroot), which causes configure to build static libraries instead of dynamic ones. Although these builds succeed, they tend to cause linker failures in binaries later linked against them.

Because affected configure files can be discovered automatically, this patch introduces a hook (enabled only when building for powerpc64 and powerpc64le) that uses a script to scan and fix each package.

This applies only to packages built for the target.

---
Hi Buildroot,

See the patch commit message for a description of the issue I'm trying to fix. This is an RFC and here are some things to consider:

I took the approach of automatically patching packages. This presumably slows the build down a little bit, but only on the affacted architectures (the code is not enabled otherwise) and has the advantage of automatically picking up new packages as they are added.

I've added a minimum of code to pkg-autotools.mk to add a PRE_CONFIGURE hook to the end of the existing hooks. It's important that it be after the AUTO_RECONFIGURE handling, which may regenerate configure.

The actual patching work is done in a support script.

The script is fairly simple: affected configure scripts all contain a unique pattern, so files are selected based on that, and "patch" is used to correct them. The location of the patch moves around a lot but there are lots of constant lines of context around them so patch always succeeds.

The input files used to generate configure are not patched, because doing so triggers some packages to regenerate configure, and that step fails for some packages, breaking their build.

It does not handle host packages. I'm not sure how to detect the host arch correctly, and although libraries may be being built incorrectly there at the moment, it's not causing any link failures so it seems unnecessary to fix them at the moment.

Does this seem a reasonable solution?

Would it be better to generalize it in some way? Could we solve some other problems at the same time?

Should the code go somewhere else?

Would a flag per package be better than checking every package? (It's not hard to do.)

Cheers,
Sam.

 package/pkg-autotools.mk                   | 17 ++++++++++
 support/scripts/fix-configure-powerpc64.sh | 53 ++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100755 support/scripts/fix-configure-powerpc64.sh
package/pkg-autotools.mk +17 -0
index d1cdb89..9e6a061 100644
@@ -79,6 +79,15 @@ define LIBTOOL_PATCH_HOOK
 endef
 
 #
+# Hook to patch common issue with configure on powerpc64{,le} failing
+# to detect shared library support:
+#
+define CONFIGURE_FIX_POWERPC64_HOOK
+	@$(call MESSAGE,"Checking configure (powerpc64/powerpc64le)")
+	support/scripts/fix-configure-powerpc64.sh $($(PKG)_DIR)
+endef
+
+#
 # Hook to gettextize the package if needed
 #
 define GETTEXTIZE_HOOK
@@ -255,6 +264,14 @@ endif
 
 endif
 
+# Must be added after other pre-configure hooks that might regenerate the
+# configure script and overwrite the changes made here.
+ifeq ($(4),target)
+ifeq ($(BR2_powerpc64)$(BR2_powerpc64le),y)
+$(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK
+endif
+endif
+
 #
 # Build step. Only define it if not already defined by the package .mk
 # file.
support/scripts/fix-configure-powerpc64.sh new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.10.0.297.gf6727b0
#1 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

Am Thu, 17 Nov 2016 15:15:23 +1100 schrieb Sam Bobroff:

Quoted 3 lines

Because affected configure files can be discovered automatically, this patch introduces a hook (enabled only when building for powerpc64 and powerpc64le) that uses a script to scan and fix each package.

Hi,

good work! The minidlna package is fixed by your patch, but the libsidplay2 package needs some fixing:

Quoted 1 line
Quoted 1 line
Quoted 1 line

libsidplay2 2.1.1 Checking configure (powerpc64/powerpc64le)

support/scripts/fix-configure-powerpc64.sh /home/bernd/buildroot/br2/ output/build/libsidplay2-2.1.1
patching file /home/bernd/buildroot/br2/output/build/libsidplay2-2.1.1/./ libsidplay/configure
Hunk #1 succeeded at 4176 with fuzz 1 (offset 2874 lines). patching file /home/bernd/buildroot/br2/output/build/libsidplay2-2.1.1/./ resid/configure
Hunk #1 succeeded at 4978 with fuzz 1 (offset 3676 lines). patching file /home/bernd/buildroot/br2/output/build/libsidplay2-2.1.1/./ builders/resid-builder/configure
Hunk #1 succeeded at 4187 with fuzz 1 (offset 2885 lines). patching file /home/bernd/buildroot/br2/output/build/libsidplay2-2.1.1/./ builders/hardsid-builder/configure
Hunk #1 succeeded at 4181 with fuzz 1 (offset 2879 lines). patching file /home/bernd/buildroot/br2/output/build/libsidplay2-2.1.1/./ libsidutils/configure
Hunk #1 succeeded at 4180 with fuzz 1 (offset 2878 lines).

[...]

checking whether the /home/bernd/buildroot/br2/output/host/usr/bin/ powerpc64le-linux-gcc linker (/home/bernd/buildroot/br2/output/host/opt/ ext-toolchain/powerpc64le-buildroot-linux-gnu/bin/ld -m elf64ppc) supports shared libraries... no
checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
checking whether to build static libraries... yes

which leads to

/home/bernd/buildroot/br2/output/host/opt/ext-toolchain/bin/../lib/gcc/ powerpc64le-buildroot-linux-gnu/5.4.0/../../../../powerpc64le-buildroot- linux-gnu/bin/ld: /home/bernd/buildroot/br2/output/build/ libsidplay2-2.1.1/libsidplay/src/.libs/libsidplay2.a(player.o): In function `.LTHUNK4':
player.cpp:(.text._ZN12__sidplay2__6Player12interruptIRQEb [_ZN12__sidplay2__6Player12interruptIRQEb]+0x58): call to `__sidplay2__::Player::fakeIRQ()' lacks nop, can't restore toc; recompile with -fPIC /home/bernd/buildroot/br2/output/host/opt/ext-toolchain/bin/../lib/gcc/ powerpc64le-buildroot-linux-gnu/5.4.0/../../../../powerpc64le-buildroot- linux-gnu/bin/ld: final link failed: Bad value

because configure is re-created during the build phase. The quote from configure comes from the second run of it.

I used this defconfig: http://autobuild.buildroot.net/
results/5d6/5d60bccbe024db240630845e15a3f15e8ddf0f01/defconfig

Regards, Bernd

#2 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

Hello,

Quoted 1 line · Bernd Kuhls

good work! The minidlna package is fixed by your patch, but the

How can minidlna be fixed by Sam's patch? I don't see the offending hunk in minidlna's configure script. Am I missing something:

$ grep powerpc minidlna-1.1.5/configure
$ 
Quoted 2 lines

because configure is re-created during the build phase. The quote from configure comes from the second run of it.

It's not good to have configure re-created during the build phase. We shouldn't find out why, and fix it.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#3 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

Quoted 10 lines · Thomas Petazzoni

Hello,

Quoted 1 line · Bernd Kuhls

good work! The minidlna package is fixed by your patch, but the

How can minidlna be fixed by Sam's patch? I don't see the offending hunk in minidlna's configure script. Am I missing something:

$ grep powerpc minidlna-1.1.5/configure

Yes ;-)

Almost all the breakages due to this problem are of this type: old configure scripts cause libraries to be built statically, but successfully, and then packages that use them fail to link due to undefined symbols.

In this case it's probally libid3tag or libexif, both of which are affected by the patch.

Quoted 7 lines
Quoted 2 lines

because configure is re-created during the build phase. The quote from configure comes from the second run of it.

It's not good to have configure re-created during the build phase. We shouldn't find out why, and fix it.

Thomas

Some packages seem to do it based on dependency rules: I found that if I patched the libtool input files, "make" would trigger a re-autoconfigure but I haven't really investigated it.

Cheers,
Sam.

#4 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

In reply to Sam Bobroff

Hello,

Quoted 9 lines · Sam Bobroff

Many (100+) packages supported by buildroot contain old configure scripts (or build them from old versions of autotools) that are unable to determine how to link shared libraries on powerpc64 and powerpc64le. This causes that test to erroneously fail on toolchains that are not "bi-endian" (which is the case for toolchains built by buildroot), which causes configure to build static libraries instead of dynamic ones. Although these builds succeed, they tend to cause linker failures in binaries later linked against them.

Quoted 7 lines

Because affected configure files can be discovered automatically, this patch introduces a hook (enabled only when building for powerpc64 and powerpc64le) that uses a script to scan and fix each package.

This applies only to packages built for the target.

I think I like this approach. Yes, it looks a bit hackish, but we already patch libtool files in a fairly similar way, and this is actually fixing the real problem.

support/scripts/fix-configure-powerpc64.sh line 22

Quoted 8 lines
support/scripts/fix-configure-powerpc64.sh new file +8 -0
+set -e
+
+if [ $# -ne 1 ]; then
+	echo "Usage: $0 <package build directory>"
+	exit 2
+fi
+
+pkg="$1"

It's not really pkg (which we normally use for the package name), but the package source directory. Maybe just:

srcdir="$1"

Quoted 1 line

+files=$(cd "$pkg" && find . -name configure -exec grep -qF 'Generated by GNU Autoconf' {} \; -exec grep -qF 'ppc*-*linux*|powerpc*-*linux*)' {} \; -print)

This line is a bit too long, can you split it? Also, why do you cd into the source directory, you can just as well do find ${srcdir}, right?

Quoted 1 line

+suffix=.powerpc64.orig

Do we really want to keep the original files?

Quoted 13 lines
support/scripts/fix-configure-powerpc64.sh new file +13 -0
+*** a/configure	2016-11-07 14:04:47.444117880 +1100
+--- b/configure	2016-11-07 14:05:03.652181547 +1100
+***************
+*** 1302,1308 ****
+  	  x86_64-*linux*)
+  	    LD="${LD-ld} -m elf_x86_64"
+  	    ;;
+! 	  ppc*-*linux*|powerpc*-*linux*)
+  	    LD="${LD-ld} -m elf64ppc"
+  	    ;;
+  	  s390*-*linux*|s390*-*tpf*)
+--- 1302,1311 ----
+  	  x86_64-*linux*)

support/scripts/fix-configure-powerpc64.sh line 52

Quoted 10 lines
support/scripts/fix-configure-powerpc64.sh new file +10 -0
+  	    LD="${LD-ld} -m elf_x86_64"
+  	    ;;
+! 	  powerpcle-*linux*)
+! 	    LD="${LD-ld} -m elf64lppc"
+! 	    ;;
+! 	  powerpc-*linux*)
+  	    LD="${LD-ld} -m elf64ppc"
+  	    ;;
+  	  s390*-*linux*|s390*-*tpf*)
+EOF

Is there any reason to use this diff format? You seem to be using it all the time. Please use unified diffs instead (diff -u).

I'm hesitating between this patch approach (with significant offsets) when applying, and an approach using a awk script. Here is an awk script that does the job:

/^\s*ppc\*-\*linux\*|powerpc\*-\*linux\*)$/ {
    infix = 1;
    print "         powerpcle-*linux*)";
    print "           LD=\"${LD-ld} -m elf64lppc\"";
    print "           ;;";
    print "         powerpc-*linux*)";
    print "           LD=\"${LD-ld} -m elf64ppc\"";
    print "           ;;";
}
/^\s*;;$/ {
    if (infix) {
	infix = 0;
	next;
    }
}
// {
    if (infix)
	next;
    print;
}

I'm not sure which of the two solutions is the most appropriate. The awk solution can probably be applied without doing the grep for the ppc*-*linux line, because the awk script only does the replacement if this line is found anyway.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#5 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

Quoted 2 lines · Thomas Petazzoni

Hello,

[snip]

Quoted 5 lines

I'm hesitating between this patch approach (with significant offsets) when applying, and an approach using a awk script. Here is an awk script that does the job:

/^\s*ppc\*-\*linux\*|powerpc\*-\*linux\*)$/ {

How sure are you that no configure script will contain this line somewhere else
than in the shared library test? You *have* to match the context as well - in particular the LD="${LD-ld} -m elf64ppc" part. This is possible with awk, but the patch approach is a lot simpler IMHO, and anyway easier to read.

Regards,
Arnout

Quoted 29 lines
    infix = 1;
    print "         powerpcle-*linux*)";
    print "           LD=\"${LD-ld} -m elf64lppc\"";
    print "           ;;";
    print "         powerpc-*linux*)";
    print "           LD=\"${LD-ld} -m elf64ppc\"";
    print "           ;;";
}
/^\s*;;$/ {
    if (infix) {
	infix = 0;
	next;
    }
}
// {
    if (infix)
	next;
    print;
}

I'm not sure which of the two solutions is the most appropriate. The awk solution can probably be applied without doing the grep for the ppc*-*linux line, because the awk script only does the replacement if this line is found anyway.

Thomas

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#6 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

Hello,

Quoted 6 lines · Arnout Vandecappelle
Quoted 1 line

/^\s*ppc\*-\*linux\*|powerpc\*-\*linux\*)$/ {

How sure are you that no configure script will contain this line somewhere else
than in the shared library test? You *have* to match the context as well - in particular the LD="${LD-ld} -m elf64ppc" part. This is possible with awk, but the patch approach is a lot simpler IMHO, and anyway easier to read.

Fine with me. I was also unsure the awk idea was better.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#7 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

In reply to Thomas Petazzoni
Quoted 36 lines · Thomas Petazzoni

Hello,

Quoted 9 lines · Sam Bobroff

Many (100+) packages supported by buildroot contain old configure scripts (or build them from old versions of autotools) that are unable to determine how to link shared libraries on powerpc64 and powerpc64le. This causes that test to erroneously fail on toolchains that are not "bi-endian" (which is the case for toolchains built by buildroot), which causes configure to build static libraries instead of dynamic ones. Although these builds succeed, they tend to cause linker failures in binaries later linked against them.

Quoted 7 lines

Because affected configure files can be discovered automatically, this patch introduces a hook (enabled only when building for powerpc64 and powerpc64le) that uses a script to scan and fix each package.

This applies only to packages built for the target.

I think I like this approach. Yes, it looks a bit hackish, but we already patch libtool files in a fairly similar way, and this is actually fixing the real problem.

support/scripts/fix-configure-powerpc64.sh line 22

Quoted 8 lines
support/scripts/fix-configure-powerpc64.sh new file +8 -0
+set -e
+
+if [ $# -ne 1 ]; then
+	echo "Usage: $0 <package build directory>"
+	exit 2
+fi
+
+pkg="$1"

It's not really pkg (which we normally use for the package name), but the package source directory. Maybe just:

Quoted 1 line

srcdir="$1"

Good idea, will do.

Quoted 4 lines
Quoted 1 line

+files=$(cd "$pkg" && find . -name configure -exec grep -qF 'Generated by GNU Autoconf' {} \; -exec grep -qF 'ppc*-*linux*|powerpc*-*linux*)' {} \; -print)

This line is a bit too long, can you split it? Also, why do you cd into the source directory, you can just as well do find ${srcdir}, right?

I'll split it. Doing the cd first means that the output in the build log is more readable, since it's then relative to the srcdir (without it you get the full absolute path). Which do you prefer?

Quoted 4 lines
Quoted 2 lines

+suffix=.powerpc64.orig

Do we really want to keep the original files?

Well, no, but now that you mention it, what about this idea:

Use the patch backup file as a way to see if the patch has been applied already and if it has been, skip patching.

At the moment, if you interrupt the configure process (which is quite long) and then re-run the build, it will fail because the patching fails.

Quoted 18 lines
Quoted 18 lines
support/scripts/fix-configure-powerpc64.sh new file +18 -0
+*** a/configure	2016-11-07 14:04:47.444117880 +1100
+--- b/configure	2016-11-07 14:05:03.652181547 +1100
+***************
+*** 1302,1308 ****
+  	  x86_64-*linux*)
+  	    LD="${LD-ld} -m elf_x86_64"
+  	    ;;
+! 	  ppc*-*linux*|powerpc*-*linux*)
+  	    LD="${LD-ld} -m elf64ppc"
+  	    ;;
+  	  s390*-*linux*|s390*-*tpf*)
+--- 1302,1311 ----
+  	  x86_64-*linux*)
+  	    LD="${LD-ld} -m elf_x86_64"
+  	    ;;
+! 	  powerpcle-*linux*)
+! 	    LD="${LD-ld} -m elf64lppc"
+! 	    ;;
Quoted 8 lines

support/scripts/fix-configure-powerpc64.sh line 52

Quoted 5 lines

+! powerpc-*linux*)

support/scripts/fix-configure-powerpc64.sh new file +4 -0
+  	    LD="${LD-ld} -m elf64ppc"
+  	    ;;
+  	  s390*-*linux*|s390*-*tpf*)
+EOF

Is there any reason to use this diff format? You seem to be using it all the time. Please use unified diffs instead (diff -u).

Oops, will fix!

Quoted 27 lines

I'm hesitating between this patch approach (with significant offsets) when applying, and an approach using a awk script. Here is an awk script that does the job:

/^\s*ppc\*-\*linux\*|powerpc\*-\*linux\*)$/ {
    infix = 1;
    print "         powerpcle-*linux*)";
    print "           LD=\"${LD-ld} -m elf64lppc\"";
    print "           ;;";
    print "         powerpc-*linux*)";
    print "           LD=\"${LD-ld} -m elf64ppc\"";
    print "           ;;";
}
/^\s*;;$/ {
    if (infix) {
	infix = 0;
	next;
    }
}
// {
    if (infix)
	next;
    print;
}
Quoted 6 lines

I'm not sure which of the two solutions is the most appropriate. The awk solution can probably be applied without doing the grep for the ppc*-*linux line, because the awk script only does the replacement if this line is found anyway.

Thomas

From the other thread, it seems like you're happy to keep using patch.

I'll post a v2.

Cheers,
Sam.

#8 lore raw

RFC PATCH 1/1 pkg-autotools: generic configure fix for powerpc64

[snip]

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+suffix=.powerpc64.orig

Do we really want to keep the original files?

Quoted 8 lines

Well, no, but now that you mention it, what about this idea:

Use the patch backup file as a way to see if the patch has been applied already and if it has been, skip patching.

At the moment, if you interrupt the configure process (which is quite long) and then re-run the build, it will fail because the patching fails.

^--- I've realised that this is wrong, and I should just remove the backup file. If configure is already patched, it isn't detected as needing a patch so this problem doesn't happen!

Cheers,
Sam.