Bug 257948

Summary: */*: Fails to package on i386: pkg-static: archive_write_open_filename(*): Cannot allocate memory
Product: Base System Reporter: Cy Schubert <cy>
Component: kernAssignee: freebsd-pkg (Nobody) <pkg>
Status: Closed Not Accepted    
Severity: Affects Many People CC: dgr, emaste, kde, kib, mw, pkg
Priority: --- Keywords: needs-qa
Version: CURRENT   
Hardware: i386   
OS: Any   

Description Cy Schubert freebsd_committer freebsd_triage 2021-08-19 17:24:16 UTC
The following error is encountered when building cmake in an i386 poudriere jail running on amd64, an i386 chroot running on amd64, and on an i386 machine booted an i386 kernel. All three "machines" are running recent 14-CURRENT.

Only i386 poudriere output shown.

=======================<phase: package        >============================
===>  Building package for cmake-3.21.0
pkg-static: archive_write_open_filename(/wrkdirs/usr/ports/devel/cmake/work/pkg/cmake-3.21.0.pkg): Cannot allocate memory
*** Error code 1

Stop.
make: stopped in /usr/ports/devel/cmake
Comment 1 Cy Schubert freebsd_committer freebsd_triage 2021-08-22 16:04:56 UTC
=======================<phase: package        >============================
===>  Building package for python27-2.7.18_1
pkg-static: archive_write_open_filename(/wrkdirs/usr/ports/lang/python27/work/pkg/python27-2.7.18_1.pkg): Cannot allocate memory
*** Error code 1

Stop.
make: stopped in /usr/ports/lang/python27
=>> Cleaning up wrkdir
Comment 2 Cy Schubert freebsd_committer freebsd_triage 2021-08-22 16:05:34 UTC
=======================<phase: package        >============================
===>  Building package for terminfo-db-20210816
pkg-static: archive_write_open_filename(/wrkdirs/usr/ports/misc/terminfo-db/work/pkg/terminfo-db-20210816.pkg): Cannot allocate memory
*** Error code 1

Stop.
make: stopped in /usr/ports/misc/terminfo-db
=>> Cleaning up wrkdir
Comment 3 Baptiste Daroussin freebsd_committer freebsd_triage 2021-08-23 14:14:58 UTC
how much memory is used available for your build jails?
Comment 4 Cy Schubert freebsd_committer freebsd_triage 2021-08-23 14:38:54 UTC
Default: none. No limit.

The machine has 8 GB physical RAM. 250 MB swap was used. PARALLEL_JOBS is default. There are 4 cores in the machine.

Note that this machine is running AMD64 but building i386 packages. I have an identical machine, also running AMD64, building amd64 packages instead which does not experience this problem.
Comment 5 Cy Schubert freebsd_committer freebsd_triage 2021-08-23 17:23:43 UTC
Also note: This problem is reproducible in an i386 chroot (not jail, chroot) when building by hand.

It is also reproducible when booting and running under an i386 kernel on the same machine (booted from an i386 partition on the same machine).

This is not a poudriere problem. Nor is it a jail problem.

All testing was performed on a recent 14-CURRENT. All running the same level of 14-CURRENT kernel.
Comment 6 Cy Schubert freebsd_committer freebsd_triage 2021-09-14 00:10:23 UTC
This is not a pkg problem. The work around: disable ELF32 ASLR:

kern.elf32.aslr.enable=0
kern.elf32.aslr.pie_enable=0
Comment 7 Dawid Gorecki 2021-09-14 10:36:11 UTC
The implementation of ASLR in FreeBSD often exhausts the available address space on 32-bit ABIs for memory intensive processes. In fact, when I last tested this, armv7 and i386 couldn't even build world, not just ports. This is not a problem on 64-bit - everything should work fine there. But for now the only workaround on 32-bit (including 32-bit compatibility layer on 64-bit architectures) is disabling the ASLR entirely.

I haven't tested architectures other than i386 and armv7 but I'm pretty sure that this applies to 32-bit PPC and MIPS too.
Comment 8 Cy Schubert freebsd_committer freebsd_triage 2021-09-14 16:47:40 UTC
(In reply to Dawid Gorecki from comment #7)

Should we close this PR? I'm ok with that, unless you feel it's worth the effort.

I test on i386 and amd64. Multiple slices/partitions are relatively easy to maintain, though, 32-bit is well past its best before date.
Comment 9 Dawid Gorecki 2021-09-15 08:10:32 UTC
(In reply to Cy Schubert from comment #8)
Yeah, I personally don't think that it is worth the effort to try and debug the problem for 32-bit platforms. I'm also ok with closing this PR.

The usefulness of ASLR on 32 bits is limited anyway. We also don't build the system on 32-bit architectures with PIE enabled by default for this reason.
Comment 10 Cy Schubert freebsd_committer freebsd_triage 2021-09-15 15:41:07 UTC
32-bit platforms do not have the memory to properly support ASLR. Users are advised not to enable ASLR or PIE on 32-bit platforms such as i386.