[PATCH 1/3] Kbuild: fix build issue with some toolchains

42 views
Skip to first unread message

Jörg Krause

unread,
Oct 18, 2015, 9:55:35 AM10/18/15
to swup...@googlegroups.com, Jörg Krause
Some toolchains used in Buildroot (x86-64 and mips64) [1] have a problem to
compile a set of object files into one object file as done for the
`builtin-target`. This targets collects all object files from each subdirectory
declared with `objs-dir`: core and handlers.

For this target the default emulation of ld is not the correct one resulting in
a relocation error:

/usr/bin/i686-pc-linux-gnu-ld: Relocatable linking with relocations from
format elf64-x86-64 (core/swupdate.o) to format elf32-i386 (core/built-in.o)
is not supported.

As there is no need to have `built-in.o` files for core and handlers we can
easily allow swupdate to be built with these toolchains by compiling the source
files in core and handlers with the `lib-target` target as it is done for the
other subdirectories.

The `lib-target` compiles a set of object files into an archive file. With this
target we avoid using the ld linker and use the ar archiver instead.

[1] http://autobuild.buildroot.net/results/d9e/d9e8298898da6355f6b46a032f951b4ca196d103/build-end.log

Signed-off-by: Jörg Krause <joerg....@embedded.rocks>
---
Makefile | 3 +--
core/Makefile | 2 +-
handlers/Makefile | 14 +++++++-------
3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 3d6a7b7..2dd8c03 100644
--- a/Makefile
+++ b/Makefile
@@ -339,8 +339,7 @@ include $(srctree)/Makefile.flags
# Defaults to vmlinux, but the arch makefile usually adds further targets
all: swupdate

-objs-y := core handlers
-libs-y := archival corelib ipc mongoose parser
+libs-y := archival core corelib handlers ipc mongoose parser

swupdate-dirs := $(objs-y) $(libs-y)
swupdate-objs := $(patsubst %,%/built-in.o, $(objs-y))
diff --git a/core/Makefile b/core/Makefile
index c48e3ee..6302da7 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -8,7 +8,7 @@
#
# Licensed under GPLv2, see file LICENSE in this source tree.

-obj-y += swupdate.o \
+lib-y += swupdate.o \
cpio_utils.o \
gpio.o \
notifier.o \
diff --git a/handlers/Makefile b/handlers/Makefile
index 2ea369c..8bd7ea1 100644
--- a/handlers/Makefile
+++ b/handlers/Makefile
@@ -3,10 +3,10 @@
# not drop the handler if it is not called.
# Handler can be called dinamically based
# on the received image type
-obj-$(CONFIG_CFI) += flash_handler.o
-obj-$(CONFIG_RAW) += raw_handler.o
-obj-$(CONFIG_UBIVOL) += ubivol_handler.o
-obj-$(CONFIG_LUASCRIPTHANDLER) += lua_scripthandler.o
-obj-$(CONFIG_SHELLSCRIPTHANDLER) += shell_scripthandler.o
-obj-$(CONFIG_RAW) += raw_handler.o
-obj-$(CONFIG_UBOOT) += uboot_handler.o fw_env.o
+lib-$(CONFIG_CFI) += flash_handler.o
+lib-$(CONFIG_RAW) += raw_handler.o
+lib-$(CONFIG_UBIVOL) += ubivol_handler.o
+lib-$(CONFIG_LUASCRIPTHANDLER) += lua_scripthandler.o
+lib-$(CONFIG_SHELLSCRIPTHANDLER) += shell_scripthandler.o
+lib-$(CONFIG_RAW) += raw_handler.o
+lib-$(CONFIG_UBOOT) += uboot_handler.o fw_env.o
--
2.6.1

Jörg Krause

unread,
Oct 18, 2015, 9:55:45 AM10/18/15
to swup...@googlegroups.com, Jörg Krause
CONFIG_UBOOT needs libz [1]. So CONFIG_UBOUT mustn't be available when
HAVE_ZLIB=n.

[1] https://github.com/sbabic/swupdate/commit/cf495e23ad117f4cae9c429e80714fe9c18f2d6a

Reported-by: Romain Naour <romain...@openwide.fr>


Signed-off-by: Jörg Krause <joerg....@embedded.rocks>
---

handlers/Config.in | 1 +
1 file changed, 1 insertion(+)

diff --git a/handlers/Config.in b/handlers/Config.in
index fb32c44..f5187a5 100644
--- a/handlers/Config.in
+++ b/handlers/Config.in
@@ -81,6 +81,7 @@ config HANDLER_IN_LUA

config UBOOT
bool "uboot"
+ depends on HAVE_ZLIB
default n
help
Enable it to change U-Boot environment
--
2.6.1

Jörg Krause

unread,
Oct 18, 2015, 9:55:52 AM10/18/15
to swup...@googlegroups.com, Jörg Krause
swupdate lacks dependency checking. The user has to figure out the necessary
dependencies itself.

Build systems like Buildroot handle dependencies for a package. When running
menuconfig for swupdate the user only sees the config options where dependencies
are met. This implies that config options may be hided by the user.

Fix this by adding a comment for unmet dependencies.

Signed-off-by: Jörg Krause <joerg....@embedded.rocks>
---

Kconfig | 9 +++++++++
archival/Config.in | 3 +++
handlers/Config.in | 6 ++++++
mongoose/Config.in | 4 ++++
parser/Config.in | 6 ++++++
5 files changed, 28 insertions(+)

diff --git a/Kconfig b/Kconfig
index 7a0f960..a91cb21 100644
--- a/Kconfig
+++ b/Kconfig
@@ -85,6 +85,9 @@ config MTD
help
Enable MTD support.

+comment "MTD support needs libmtd"
+ depends on !HAVE_LIBMTD
+
config LUA
bool "lua"
default y
@@ -92,6 +95,9 @@ config LUA
help
Enable LUA interpreter.

+comment "Lua support needs a Lua 5.2 interpreter"
+ depends on !HAVE_LUA
+
# These are auto-selected by other options

config FEATURE_SYSLOG
@@ -218,6 +224,9 @@ config DOWNLOAD
Enable update from image URL using libcurl. Files are downloaded
completely before installation begins.

+comment "Image downloading support needs libcurl"
+ depends on !HAVE_LIBCURL
+
config WEBSERVER
bool "Enable webserver"
default n
diff --git a/archival/Config.in b/archival/Config.in
index fe70d48..cf360dc 100644
--- a/archival/Config.in
+++ b/archival/Config.in
@@ -28,4 +28,7 @@ config GUNZIP
You can use the `-t' option to test the integrity of
an archive, without decompressing it.

+comment "gunzip support needs libz"
+ depends on !HAVE_ZLIB
+
endmenu
diff --git a/handlers/Config.in b/handlers/Config.in
index f5187a5..3677f3e 100644
--- a/handlers/Config.in
+++ b/handlers/Config.in
@@ -15,6 +15,9 @@ config UBIVOL
Say Y if you have NAND or you use UBI on
your system.

+comment "ubivol support needs libubi"
+ depends on !HAVE_LIBUBI
+
config UBIBLACKLIST
string "List of MTD devices to be excluded for UBI"
depends on UBIVOL
@@ -87,6 +90,9 @@ config UBOOT


Enable it to change U-Boot environment

during the installation process.

+comment "uboot support needs libz"
+ depends on !HAVE_ZLIB
+
config UBOOT_FWENV
string "U-Boot Environment Configuration file"
depends on UBOOT
diff --git a/mongoose/Config.in b/mongoose/Config.in
index 64f3b21..515ee3a 100644
--- a/mongoose/Config.in
+++ b/mongoose/Config.in
@@ -36,6 +36,10 @@ config MONGOOSESSL
depends on HAVE_LIBCRYPTO
help
It enables SSL support into mongoose
+
+comment "SSL support needs libcrypto, libssl"
+ depends on !HAVE_LIBSSL || !HAVE_LIBCRYPTO
+
endmenu

endmenu
diff --git a/parser/Config.in b/parser/Config.in
index e7b1cf7..f439111 100644
--- a/parser/Config.in
+++ b/parser/Config.in
@@ -8,6 +8,9 @@ config LIBCONFIG
Use libconfig to parse the configuration file.
This is the default parser.

+comment "Default config parser support needs libconfig"
+ depends on !HAVE_LIBCONFIG
+
config LIBCONFIGROOT
string "Name of root node"
depends on LIBCONFIG
@@ -23,6 +26,9 @@ config JSON
help
Use json-c to parse the configuration file.

+comment "JSON config parser support needs json-c"
+ depends on !HAVE_JSON_C
+
config LUAEXTERNAL
bool "lua"
depends on LUA
--
2.6.1

Stefano Babic

unread,
Oct 19, 2015, 10:00:54 AM10/19/15
to Jörg Krause, swup...@googlegroups.com
Hi Jorg,

On 18/10/2015 15:54, Jörg Krause wrote:
> Some toolchains used in Buildroot (x86-64 and mips64) [1] have a problem to
> compile a set of object files into one object file as done for the
> `builtin-target`. This targets collects all object files from each subdirectory
> declared with `objs-dir`: core and handlers.
>
> For this target the default emulation of ld is not the correct one resulting in
> a relocation error:
>
> /usr/bin/i686-pc-linux-gnu-ld: Relocatable linking with relocations from
> format elf64-x86-64 (core/swupdate.o) to format elf32-i386 (core/built-in.o)
> is not supported.
>
> As there is no need to have `built-in.o` files for core and handlers we can
> easily allow swupdate to be built with these toolchains by compiling the source
> files in core and handlers with the `lib-target` target as it is done for the
> other subdirectories.
>
> The `lib-target` compiles a set of object files into an archive file. With this
> target we avoid using the ld linker and use the ar archiver instead.
>
> [1] http://autobuild.buildroot.net/results/d9e/d9e8298898da6355f6b46a032f951b4ca196d103/build-end.log
>
> Signed-off-by: Jörg Krause <joerg....@embedded.rocks>
> ---

Applied to master, thanks !

Best regards,
Stefano Babic

--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Stefano Babic

unread,
Oct 19, 2015, 10:01:52 AM10/19/15
to Jörg Krause, swup...@googlegroups.com
On 18/10/2015 15:54, Jörg Krause wrote:

Stefano Babic

unread,
Oct 19, 2015, 10:02:29 AM10/19/15
to Jörg Krause, swup...@googlegroups.com
Hi Jörg,

On 18/10/2015 15:54, Jörg Krause wrote:
I have only dropped the version before applying as we can set the LUA
interpreter release with LUAVERSION.

Stefano Babic

unread,
Oct 23, 2015, 3:59:33 AM10/23/15
to Jörg Krause, swup...@googlegroups.com
Hi Jörg,

On 18/10/2015 15:54, Jörg Krause wrote:
> Some toolchains used in Buildroot (x86-64 and mips64) [1] have a problem to
> compile a set of object files into one object file as done for the
> `builtin-target`. This targets collects all object files from each subdirectory
> declared with `objs-dir`: core and handlers.
>
> For this target the default emulation of ld is not the correct one resulting in
> a relocation error:
>
> /usr/bin/i686-pc-linux-gnu-ld: Relocatable linking with relocations from
> format elf64-x86-64 (core/swupdate.o) to format elf32-i386 (core/built-in.o)
> is not supported.
>
> As there is no need to have `built-in.o` files for core and handlers we can
> easily allow swupdate to be built with these toolchains by compiling the source
> files in core and handlers with the `lib-target` target as it is done for the
> other subdirectories.
>
> The `lib-target` compiles a set of object files into an archive file. With this
> target we avoid using the ld linker and use the ar archiver instead.
>
> [1] http://autobuild.buildroot.net/results/d9e/d9e8298898da6355f6b46a032f951b4ca196d103/build-end.log
>

I tested again current TOT and this patch breaks the instantiation of
handlers. In fact, there is an implicit registration of the handlers
with __attribute__((constructor)). As the obj are linked, the
constructor is called and a new handler does not require an explicit
registration.

However, in a static library the linker drops code that is not
referenced. That means that no handler is registered at all.

Can you take a look ? I will tend to revert the patch and wait for a
long term solution.

bjorn....@gmail.com

unread,
Oct 24, 2015, 5:43:23 AM10/24/15
to swupdate, joerg....@embedded.rocks
søndag 18. oktober 2015 15.55.35 UTC+2 skrev Jörg Krause følgende:
> Some toolchains used in Buildroot (x86-64 and mips64) [1] have a problem to
> compile a set of object files into one object file as done for the
> `builtin-target`. This targets collects all object files from each subdirectory
> declared with `objs-dir`: core and handlers.

AFAICT, this patch has the unfortunate side-effect of breaking handler registration. It seems __attribute__ ((constructor)) no longer has any effect.

I tried to revert this patch (c3467290925b2a833, "Kbuild: fix build issue with some toolchains") and then the handlers appeared again.

Best regards,
Bjørn Forsman

bjorn....@gmail.com

unread,
Oct 24, 2015, 5:45:07 AM10/24/15
to swupdate, joerg....@embedded.rocks, bjorn....@gmail.com
Tested in Buildroot with ARM + uclibc and glibc toolchain, and also on my desktop system.

Stefano Babic

unread,
Oct 24, 2015, 6:59:26 AM10/24/15
to bjorn....@gmail.com, swupdate, joerg....@embedded.rocks
Hi Bjorn,
Yes, confirmed. The behavior is anyway well explained. We cannot use the
(constructor) in static libraries, because that code is dropped by the
linker why there is no code to reference to it.

I push the revert on TOT to make things working again.

Bjørn Forsman

unread,
Oct 24, 2015, 7:08:24 AM10/24/15
to Stefano Babic, swupdate, joerg....@embedded.rocks
On 24 October 2015 at 12:59, Stefano Babic <sba...@denx.de> wrote:
> [...]
> I push the revert on TOT to make things working again.

Thanks for the quick response. But what is TOT?
(I don't see the revert being pushed yet to
https://github.com/sbabic/swupdate.git)

- Bjørn

Stefano Babic

unread,
Oct 24, 2015, 7:28:37 AM10/24/15
to Bjørn Forsman, Stefano Babic, swupdate, joerg....@embedded.rocks
Hi Bjorn,

On 24/10/2015 13:08, Bjørn Forsman wrote:
> On 24 October 2015 at 12:59, Stefano Babic <sba...@denx.de> wrote:
>> [...]
>> I push the revert on TOT to make things working again.
>
> Thanks for the quick response. But what is TOT?

Top of Tree

> (I don't see the revert being pushed yet to
> https://github.com/sbabic/swupdate.git)

My response was quick, but I had to turn my working PC on. Now you
should see the revert on tree.

Bjørn Forsman

unread,
Oct 24, 2015, 7:39:34 AM10/24/15
to Stefano Babic, swupdate, joerg....@embedded.rocks
On 24 October 2015 at 13:28, Stefano Babic <sba...@denx.de> wrote:
> Hi Bjorn,
>
> On 24/10/2015 13:08, Bjørn Forsman wrote:
>> On 24 October 2015 at 12:59, Stefano Babic <sba...@denx.de> wrote:
>>> [...]
>>> I push the revert on TOT to make things working again.
>>
>> Thanks for the quick response. But what is TOT?
>
> Top of Tree
>
>> (I don't see the revert being pushed yet to
>> https://github.com/sbabic/swupdate.git)
>
> My response was quick, but I had to turn my working PC on. Now you
> should see the revert on tree.

Thanks!

Jörg: sorry for having to revert your patch, but hopefully you'll find
an alternative way to fix it for the troublesome toolchains.

- Bjørn

Jörg Krause

unread,
Oct 24, 2015, 3:50:03 PM10/24/15
to swupdate, bjorn....@gmail.com, joerg....@embedded.rocks, sba...@denx.de
Hi Stefano,


On Saturday, October 24, 2015 at 12:59:26 PM UTC+2, Stefano Babic wrote:
Hi Bjorn,

On 24/10/2015 11:45, bjorn....@gmail.com wrote:
> lørdag 24. oktober 2015 11.43.23 UTC+2 skrev bjorn....@gmail.com følgende:
>> søndag 18. oktober 2015 15.55.35 UTC+2 skrev Jörg Krause følgende:
>>> Some toolchains used in Buildroot (x86-64 and mips64) [1] have a problem to
>>> compile a set of object files into one object file as done for the
>>> `builtin-target`. This targets collects all object files from each subdirectory
>>> declared with `objs-dir`: core and handlers.
>>
>> AFAICT, this patch has the unfortunate side-effect of breaking handler registration. It seems __attribute__ ((constructor)) no longer has any effect.
>>
>> I tried to revert this patch (c3467290925b2a833, "Kbuild: fix build issue with some toolchains") and then the handlers appeared again.
>
> Tested in Buildroot with ARM + uclibc and glibc toolchain, and also on my desktop system.

Yes, confirmed. The behavior is anyway well explained. We cannot use the
(constructor) in static libraries, because that code is dropped by the
linker why there is no code to reference to it.

I push the revert on TOT to make things working again.


Damn, sorry for not testing carefully!

You're right, the constructor functions are dropped by the linker. I'll check for a better solution...

Best regards
Jörg Krause

Jörg Krause

unread,
Oct 26, 2015, 5:21:01 PM10/26/15
to swupdate, sba...@denx.de, joerg....@embedded.rocks
Hi Bjorn,
Hi Stefano,
I (hopefully) was able to fix the toolchain issue without touching swupdate's Makefile [1].

Thanks to Bjørn for reporting and sorry for any inconvenience!

Best regards
Jörg Krause

Reply all
Reply to author
Forward
0 new messages