Skip to content

OpenBSD 6.6: cannot allocate memory #4803

Closed

Description

@mikdusan
[in case someone else runs into similar issue]

When building binaries (seemingly when they are large) a value in ELF section OPENBSD_RANDOM exceeds a kernel limit. According to attached report it is a clang bug and it makes zig0 fail to execute:

cannot allocate memory: zig0

The same error is produced running any llvm-10/bin/ executables if you roll your own for zig.

http://openbsd-archive.7691.n7.nabble.com/execve-1-errno-12-Cannot-allocate-memory-td376879.html

I'm too lazy to put in the work upgrading to OpenBSD -current so I'll just wait for the next expected release ~April/2020.

Activity

  1. added
    os-openbsd
    upstream
    on Mar 25, 2020
  2. mikdusan commented on Mar 25, 2020

    @mikdusan
    MemberAuthor

    incidentally, simple patch to get zig0 building:

    diff --git a/src/os.cpp b/src/os.cpp
    index 351b61cd6..102f80408 100644
    --- a/src/os.cpp
    +++ b/src/os.cpp
    @@ -52,7 +52,7 @@ typedef SSIZE_T ssize_t;
     
     #endif
     
    -#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
    +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_OPENBSD) || defined(ZIG_OS_DRAGONFLY)
     #include <link.h>
     #endif
     
    @@ -1818,7 +1818,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
     #endif
     }
     
    -#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
    +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_OPENBSD) || defined(ZIG_OS_DRAGONFLY)
     static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {
         ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);
         if (info->dlpi_name[0] == '/') {
    @@ -1829,7 +1829,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,
     #endif
     
     Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {
    -#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
    +#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_OPENBSD) || defined(ZIG_OS_DRAGONFLY)
         paths.resize(0);
         dl_iterate_phdr(self_exe_shared_libs_callback, &paths);
         return ErrorNone;
    diff --git a/src/os.hpp b/src/os.hpp
    index e73e5e3aa..f65376811 100644
    --- a/src/os.hpp
    +++ b/src/os.hpp
    @@ -27,6 +27,8 @@
     #define ZIG_OS_FREEBSD
     #elif defined(__NetBSD__)
     #define ZIG_OS_NETBSD
    +#elif defined(__OpenBSD__)
    +#define ZIG_OS_OPENBSD
     #elif defined(__DragonFly__)
     #define ZIG_OS_DRAGONFLY
     #else
  3. mikdusan commented on Mar 25, 2020

    @mikdusan
    MemberAuthor

    so sysupgrade -s to snapshot, rebuilding llvm10 and zig fixes that issue...

    but now another problem: OpenBSD is just about the only OS that does not support getting absolute path of current-process' executable. grrr....

  4. jreut commented on Mar 26, 2020

    @jreut

    so sysupgrade -s to snapshot, rebuilding llvm10 and zig fixes that issue...

    Out of curiosity, how did you go about building LLVM 10? Did you apply any patches? If I'm looking in the right place, it seems the latest LLVM in ports is version 8.

  5. mikdusan commented on Mar 26, 2020

    @mikdusan
    MemberAuthor

    Out of curiosity, how did you go about building LLVM 10? Did you apply any patches? If I'm looking in the right place, it seems the latest LLVM in ports is version 8.

    Rolled my own build from llvm's github repository and install to some random location like /opt/llvm-10.0.0 and point zig's cmake setup to that location.

    I posted the scripts I used in this tiny repo https://github.com/mikdusan/zig.llvm10 and in its readme there is currently a gdrive link for binary tarballs. Weird that openbsd binaries are so much larger, but I haven't had time to find out why.

  6. added this to the 0.7.0 milestone on Mar 28, 2020
  7. jreut commented on Mar 28, 2020

    @jreut

    I posted the scripts I used in this tiny repo

    Thanks so much for the link to your script. For posterity: I'm also on -current and I was able to build after installing the libexecinfo port and prepending CPATH=/usr/local/include and LIBRARY_PATH=/usr/local/lib.

  8. modified the milestones: 0.7.0, 0.8.0 on Oct 4, 2020
  9. modified the milestones: 0.8.0, 0.9.0 on Nov 6, 2020
  10. mikdusan commented on Mar 22, 2021

    @mikdusan
    MemberAuthor

    solved:

    This is either directly related to openbsd default ulimit settings or something else was fixed in OpenBSD 6.8 .

    To get zig building on OpenBSD 6.8, bring-your-own LLVM and set ulimit for 10 GB memory and maybe more stack for zig stage1 to be able to build zig1.o and run larger tests. The default on openbsd is very low, around 1.5 GB.

  11. modified the milestones: 0.9.0, 0.8.0 on Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    os-openbsdupstream

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions