Bug 7286

Summary: systemd 215 doesn't build
Product: buildroot Reporter: philn
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: buildroot
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Attachments: build log
buildroot config
Workaround by disabling link time optimization

Description philn 2014-07-31 08:12:34 UTC
Created attachment 5540 [details]
build log

I'm trying to build Systemd for a Raspberry Pi. Attaching the build log. Please let me know if you need more infos about my buildroot config.
Comment 1 philn 2014-07-31 08:14:04 UTC
Tried a recent git snapshot too (2b49732c3d511007ae2c413997e56c40f678d79a) and had the same error.
Comment 2 philn 2014-07-31 08:20:41 UTC
Created attachment 5546 [details]
buildroot config
Comment 3 nroach44 2014-07-31 10:37:55 UTC
Testing using the defconfig: Setting glibc and systemd and then -O{1,2,3} (not -O{s,1}), I get build errors very similar (probably the same but jumbled due to multithreading).
Comment 4 nroach44 2014-07-31 10:39:03 UTC
Testing using the defconfig: Setting glibc and systemd and then -O{1,2,3} (not -O{s,1}), I get build errors very similar (probably the same but jumbled due to multithreading).(In reply to comment #3)
> Testing using the defconfig: Setting glibc and systemd and then -O{1,2,3} (not
> -O{s,1}), I get build errors very similar (probably the same but jumbled due to
> multithreading).

that should be "not -O{s,0}"
Comment 5 Eric Le Bihan 2014-07-31 17:38:29 UTC
The build fails because systemd is configured with the --enable-compat-libs option.
This option has been added because since systemd 209, some libraries have been merged into libsystemd.so:

 - libsystemd-daemon.so
 - libsystemd-id128.so
 - libsystemd-journal.so
 - libsystemd-login.so

When this option is enabled, the deprecated libraries will be built, so external programs, which depend on them and have not yet migrated to libsystemd, can still compile. But these libs will refer to the parts used to build libsystemd.

For example, if we look at libsystemd-journal.so, we can see that is built from libsystemd-journal.c. This file is generated from:

- src/compat-libs/linkwarning.h
- src/compat-libs/libsystemd-journal.sym

Via some macros in linkwarning.h the symbols will be compiled as an unallocated section and linking to them will cause a warning to be printed.

From the build log, we can see that GCC complains the symbol is being defined twice:

{{
/tmp/ccEK7EwW.ltrans13.ltrans.o: In function `sd_journal_reliable_fd':
ccEK7EwW.ltrans13.o:(.text+0x784): multiple definition of `sd_journal_reliable_fd'
libsystemd_journal_internal_la-sd-journal.o (symbol from plugin):(.text+0x0): first defined here
}}

In the attached Buildroot config file, we have "BR2_OPTIMIZE_2=y", which adds "-Wp,-D_FORTIFY_SOURCE=2" to CPPFLAGS and "-flto -ffat-lto-objects" to CFLAGS.

I tried the attached configuration with ccache disabled and "BR2_OPTIMIZE_S=y", which cause the aforementioned options to be dropped, and the build is successful.

In the configure script, there is a check for these options, but it seems to only print a warning message...
Comment 6 philn 2014-08-04 07:01:44 UTC
So what would be the approach to fix this issue then? Ensuring the CPPFLAGS and CFLAGS don't contain these options when building systemd?
Comment 7 Eric Le Bihan 2014-08-04 08:25:22 UTC
Created attachment 5552 [details]
Workaround by disabling link time optimization

Here is a workaround which disable link time optimization for systemd.
Comment 8 Thomas De Schampheleire 2014-08-09 15:19:01 UTC
Eric, is this the fix we should apply for 2014.08 or should something else be done? In the first case, could you send the patch to the list? In the second case, could you give more details about what you think should be done?

Thanks, Thomas
Comment 9 Eric Le Bihan 2014-08-12 20:41:51 UTC
The bug was reported upstream (https://bugs.freedesktop.org/show_bug.cgi?id=78923) but has been marked as rejected, as it is likely to be a compiler/linker issue (though the last comment says the issue is not raised when using GCC 4.8.3, which is the version precisely used in our case!). 

Comments in another bug report (https://bugzilla.redhat.com/show_bug.cgi?id=1067245#c13) suggest testing with GCC 4.9.

Anyway, the patch is now in patchwork: http://patchwork.ozlabs.org/patch/379472/. I suggest applying it.
Comment 10 Thomas Petazzoni 2014-08-15 20:32:21 UTC
Fixed by http://git.buildroot.net/buildroot/commit/?id=d9054017cfc25c8f89225e1d18c71f112d25f9a0. Closing bug. Thanks!