Forum

Build error for x86_64 with 8.8.1

Fisiu
14 March 2013, 19:25
I tried to build rpm for openSUSE with openSUSE Build Service.
Here is a %build part I used:

export LDFLAGS="%{optflags} -pie"

mkdir build
cd build
cmake .. \
-DCMAKE_C_FLAGS="%{optflags} -fpie -fPIC" \
-DCMAKE_INSTALL_PREFIX="/usr" \
-DCMAKE_INSTALL_BINDIR="/usr/bin" \
-DCMAKE_INSTALL_SBINDIR="/usr/sbin" \
-DCMAKE_INSTALL_SYSCONFDIR="/etc/hiawatha" \
-DCMAKE_INSTALL_LIBDIR=%{_libdir} \
-DCONFIG_DIR="/etc/hiawatha" \
-DLOG_DIR="/var/log/hiawatha" \
-DWORK_DIR="/var/lib/hiawatha" \
-DWEBROOT_DIR="%{webroot}/%{name}/htdocs" \
-DENABLE_SSL=On \
-DENABLE_ZLIB_SUPPORT=On \
-DENABLE_MONITOR=On \
-DENABLE_TOMAHAWK=On

make %{?_smp_mflags}

For i586 rpm is build fine but for x86_64 it fails while linking:
6s] Linking C shared library libpolarssl.so
[ 6s] /usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/polarssl.dir/x509parse.c.o: relocation R_X86_64_PC32 against symbol `load_file' can not be used when making a shared object; recompile with -fPIC
[ 6s] /usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: final link failed: Bad value
[ 6s] collect2: error: ld returned 1 exit status
[ 6s] make[2]: *** [polarssl/library/libpolarssl.so.1.2.5] Error 1
[ 6s] make[1]: *** [polarssl/library/CMakeFiles/polarssl.dir/all] Error 2
[ 6s] make: *** [all] Error 2

Full build log can be foung in obs: https://build.opensuse.org/package/show?package=hiawatha&project=home%3AFisiu%3Abranches%3Aserver%3Ahttp

Hiawatha version: 8.8.1
Operating System: openSUSE 12.1, 12.2, Factory
Hugo Leisink
15 March 2013, 12:07
It looks like the cause of the problem lies in PolarSSL. So, you better contact the PolarSSL developer about this.
Fisiu
16 March 2013, 17:19
I also built polarssl shared library as separate package. Can I link hiawatha against external polarssl?
Hugo Leisink
16 March 2013, 18:43
It is not supported, but you can always give it a try. The reason why I don't support it is because Hiawatha often requires the latest PolarSSL version, which is shipped with Hiawatha.
Kalileo
17 March 2013, 00:34
Hi Hugo and Fisiu,

I think the problem is not in PolarSSL, but that the polarssl/CMakeLists.txt used in hiawatha to compile PolarSSL does not set the CMAKE flag for position independent code (PIC).
That was not required when compiling for OpenSUSE 12.1, but starting with 12.2 that is strongly requested, as it makes the code more secure.

In my build I have simply ignored the complaint of the OpenSUSE Build service, because I did not want to change anything in the hiawatha code.

Fisiu has set
export LDFLAGS="%{optflags} -pie"
and
-DCMAKE_C_FLAGS="%{optflags} -fpie -fPIC" \
which seem to produce the position independent code for hiawatha, but not for the included polarssl.

The solution could be as simple as adding
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
to
polarssl/CMakeLists.txt

Regards,
Kalileo





Kalileo
17 March 2013, 00:55
Hi Fisiu,

Starting with CMake 2.8.9 you can also set the global variable

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

to make all following targets position independent.

I simply don't know how to set that in the spec file (or anywhere else) in teh OpenSUSE Build service. I understand that, if set, it would then affect both the cmake settings for Hiawatha and for PolarSSL, which would solve the problem without touching the Hiawatha source package.

Regards,
Kalileo
Hugo Leisink
17 March 2013, 16:09
Can any of you provide me with a make_rpm_package script, just like the other make_*_package scripts in the directory 'extra'?
Kalileo
18 March 2013, 07:57
Hi Hugo,

unfortunately not, because the procedure we use to build an RPM is a little different.

There is some software in OpenSUSE which creates RPMs, and the main issue is to create a "spec" file, which is something like such a "make_rpm_package script", and includes the cmake settings for compiling the project. You can access such a spec file at
https://build.opensuse.org/package/show?package=hiawatha&project=home%3AFisiu%3Abranches%3Aserver%3Ahttp
- it is the file hiawatha.spec

Then it is very convenient to not create the rpm on your own system, but to use the OpenSUSE Build Service. There you just
- upload the spec file and the ini scripts (plus may be some other configuration files), then you
- point it to the hiawatha download link,
- then you select the OpenSUSE versions you want it built for, plus Red Hat, Centos, Mandriva, if you like
and then it builds the RPMs for all selected versions (takes 10 minutes to 1 hour).
After any change you make to any config file it automatically rebuilds it.

This way you can cover all current OpenSUSE versions without having to have them installed.

in the case of Hiawatha and starting with OpenSUSE 12.2 (and I assume with other Linux distros too) the position independent code became an issue. The setting in the spec file, which Fisiu applied, does take effect for hiawatha but apparently not for the included PolarSSL.

I think setting the environment variable "set(CMAKE_POSITION_INDEPENDENT_CODE ON)" would take effect also for the included PolarSSL, I simply don't know how to include it in the spec file. Possibly "export CMAKE_POSITION_INDEPENDENT_CODE=ON" will do it, I'll test it sooner or later (latest with your next release ) . The beauty of that would be that you would not have to change anything in the hiawatha package.
This topic has been closed.