FS#73409 - [erlang] strips symbols in static archives with LTO compiled objects that result in linking errors

Attached to Project: Community Packages
Opened by Serge A (saleyn) - Tuesday, 18 January 2022, 14:39 GMT
Last edited by Alexander F. Rødseth (xyproto) - Wednesday, 26 January 2022, 11:27 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Alexander F. Rødseth (xyproto)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Description:

After the addition of mandatory stripping of symbols to makepkg in (https://lists.archlinux.org/pipermail/pacman-dev/2021-March/024911.html), the makepkg occasionally produces archives of LTO-compiled object files, in which the linker fails to resolve symbols.

This issue was encountered in the `erlang 24.2-1` package. When built manually without applying the strip command, the produced `libei.a` works fine, and when installing it from the Arch archive, linking with `libei.a` reports unresolved symbols.

See this thread, which discussed this issue: https://github.com/erlang/otp/issues/5609

Perhaps the solution would be to add an option to `makepkg` to exclude given libraries from stripping symbols?

Additional info:
* package version(s): erlang 24.2-1
* config and/or log files etc.

This illustrates that libei.a is stripped:

$ sudo pacman -U https://archive.archlinux.org/packages/e/erlang/erlang-24.2-1-x86_64.pkg.tar.zst
$ du -sb /usr/lib/erlang/usr/lib/libei*
74254 /usr/lib/erlang/usr/lib/libei.a
74254 /usr/lib/erlang/usr/lib/libei_st.a

Linking of a local project with it results in errors:

$ g++ c_src/ei++.o c_src/exec.o c_src/exec_impl.o -lcap -L"/usr/lib/erlang/lib/erl_interface-5.1/lib" -lei -o /home/serge/projects/erl-libs/erlexec/priv/x86_64-pc-linux-gnu/exec-port)
failed with return code 1 and the following output:
/usr/bin/ld: c_src/ei++.o: in function `ei::Serializer::print(std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/serge/projects/erl-libs/erlexec/c_src/ei++.cpp:62: undefined reference to `ei_s_print_term'
/usr/bin/ld: c_src/ei++.o: in function `ei::Serializer::read()':
/home/serge/projects/erl-libs/erlexec/c_src/ei++.cpp:145: undefined reference to `ei_decode_version'
/usr/bin/ld: c_src/exec.o: in function `ei::Serializer::decodeTupleSize()':

This works fine when fetching the previous version of the package which doesn't strip symbols from libei.a:

$ sudo pacman -U https://archive.archlinux.org/packages/e/erlang/erlang-24.1.7-1-x86_64.pkg.tar.zst
$ du -sb /usr/lib/erlang/usr/lib/libei*
282530 /usr/lib/erlang/usr/lib/libei.a
278736 /usr/lib/erlang/usr/lib/libei_st.a

* link to upstream bug report, if any

Steps to reproduce:

1. Install latest erlang package
2. Install rebar3:
$ cd /tmp
$ git clone https://github.com/erlang/rebar3.git
$ cd rebar3
$ ./bootstrap
$ PATH=/tmp/rebar3:$PATH

3. Try to build erlexec:
$ git clone https://github.com/saleyn/erlexec.git
$ make
This task depends upon

Closed by  Alexander F. Rødseth (xyproto)
Wednesday, 26 January 2022, 11:27 GMT
Reason for closing:  Fixed
Comment by Morten Linderud (Foxboron) - Tuesday, 18 January 2022, 14:45 GMT Comment by Serge A (saleyn) - Tuesday, 18 January 2022, 14:51 GMT
Looks like at its core, it's the same issue.
Comment by Allan McRae (Allan) - Tuesday, 18 January 2022, 22:40 GMT
Assigning to erlang packager. Not convinced we can or should do anything about this in makepkg.
Comment by Alexander F. Rødseth (xyproto) - Wednesday, 26 January 2022, 01:08 GMT
Thanks for reporting.

I'm able to reproduce the issue. When adding "!strip" to the PKGBUILD, the steps to reproduce works again.

The updated package will appear in [community] shortly.
Comment by Allan McRae (Allan) - Wednesday, 26 January 2022, 01:20 GMT
!strip is not an ideal solution... Either add !lto or CFLAGS+=" -ffat-lto-objects"
Comment by Serge A (saleyn) - Wednesday, 26 January 2022, 03:27 GMT
I'd like to confirm that adding the CFLAGS+=" -ffat-lto-objects" to build the erlang package works fine with stripping in my environment.
Comment by Alexander F. Rødseth (xyproto) - Wednesday, 26 January 2022, 10:56 GMT
OK. I'll add -ffat-lto-objects, test it locally and update the package in [community]. Thanks for testing.

Loading...