【运维案例】supermin软件包编译报错依赖库需用-fPIC参数重编

版本:openEuler 20.03-LTS-SP3

组件:supermin ocaml

分类:构建

【背景及现象描述】

在部署OBS环境后编译openEuler-20.03-LTS-SP3软件包,supermin编译报错,如下为编译日志

[  157s] make[3]: Leaving directory '/home/abuild/rpmbuild/BUILD/supermin-5.1.19/src'
[  157s] make[3]: Entering directory '/home/abuild/rpmbuild/BUILD/supermin-5.1.19/src'
[  157s] ./supermin-link.sh ocamlfind opt -warn-error CDEFLMPSUVXYZ-3  -package unix,str ext2fs.cmx fnmatch.cmx glob.cmx realpath.cmx librpm.cmx config.cmx utils.cmx types.cmx os_release.cmx package_handler.cmx ph_rpm.cmx ph_dpkg.cmx ph_pacman.cmx mode_prepare.cmx format_chroot.cmx format_ext2_init.cmx format_ext2_initrd.cmx format_ext2_kernel.cmx format_ext2.cmx mode_build.cmx supermin.cmx -cclib "-pie -Wl,-z,now" -o supermin supermin-ext2fs-c.o supermin-format-ext2-init-c.o supermin-fnmatch-c.o supermin-glob-c.o supermin-librpm-c.o supermin-realpath-c.o  ../lib/libgnu.a 
[  157s] /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(fail.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `stderr@@GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
[  157s] /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(fail.o)(.text+0x318): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `stderr@@GLIBC_2.17'
[  157s] /usr/bin/ld: final link failed: bad value
[  157s] collect2: error: ld returned 1 exit status
[  157s] File "caml_startup", line 1:
[  157s] Error: Error during linking
[  157s] make[3]: *** [Makefile:1170: supermin] Error 2
[  157s] make[3]: Leaving directory '/home/abuild/rpmbuild/BUILD/supermin-5.1.19/src'
[  157s] make[2]: *** [Makefile:1088: all] Error 2
[  157s] make[1]: *** [Makefile:1046: all-recursive] Error 1
[  157s] make: *** [Makefile:987: all] Error 2
[  157s] error: Bad exit status from /var/tmp/rpm-tmp.cR5SU4 (%build)
[  157s] 
[  157s] 
[  157s] RPM build errors:
[  157s]     Bad exit status from /var/tmp/rpm-tmp.cR5SU4 (%build)

【原因分析】

根据编译日志报错,是usr/lib64/ocaml/libasmrun.a库需要使用 -fPIC参数重新编译,在opEneuler obs环境未复现该问题

在本地安装openEuler-20.03-LTS-SP3 docker后尝试复现

进入docker,下载ocaml的src.rpm包,使用yum-builddep spec文件安装编译依赖,安装rpmdevtools(本地rpm编译组件),在本地使用rpmbuild -ba ocaml.spec文件编译,将编译成功的ocaml包安装到docker中

再下载supermin的src.rpm包,安装除ocaml外的编译依赖,使用rpmbuild -ba supermin.spec编译可复现出该报错

再给ocaml加-fPIC参数编译,通过查看ocaml源码中的configure文件,只需要在执行configure时添加-fPIC或–fPIC参数即可使用-fPIC参数编译,修改ocaml.spec文件加上-fPIC参数,再次编译安装ocaml后,supermin编译成功

%build
CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" \
./configure \
    -bindir %{_bindir} \
    -libdir %{_libdir}/ocaml \
    -x11lib %{_libdir} \
    -x11include %{_includedir} \
    -mandir %{_mandir}/man1 \
    -no-curses -fPIC

【解决方法】

给ocaml.spec文件%build阶段加上-fPIC参数,使supermin依赖新编出的ocaml编译后未出现报错

也可安装gcc_secure 软件包,给gcc增加安全编译选项参数

1 个赞