elf-loader: avoid module self-referencing on local symbols resolution

Function object::resolve_pltgot() should never put "this" to
_used_by_resolve_plt_got collection. Otherwise module locks itself
in memory forever.

This problem makes native applications fail in different ways
on multiple consequtive executions because .bss sections are
not zeroed between main() invocations.

In particular iperf fails to parse command line arguments because its
corresponding code heavily relies on global variables.

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
run-elf: cancel alarms after native program execution

Native program may leave alarm pending on exit,
cancel it before module unload.

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
xen: comment out HYPERVISOR_poll()

Has a call to get_system_time(), which doesn't exist, so the link fails with
mode=debug.  Exposed by 98fc8c187cf76a1e ("build: Use -O0 for debug build
instead of -Og").

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu: avoid allocation in allocate_intermediate_level()

An allocation causes recursion with the debug allocator.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
x64: switch stacks in general_protection

If we abort() (which is likely), we'll print a backtrace, which will
call safe_load(), which is likely to generate an exception.  Switch stacks
so it generates the exception on a new stack, preserving the old one
for a developer to examine.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Add defer() utility

Following go, add a way to defer a cleanup function until we exit the scope
in any way (return, exceptio, or break):

  FILE* fp = fopen(...);
  auto cleanup = defer([&] { fclose(fp); });

  ...

  // do things with fp in the knowledge that it will be closed when going
  // out of scope.

A deferred operation can be cancelled:

  if (everything_is_good) {
      cleanup.cancel();
      return fp;
  }

Of course, use RAII types where available in preference to defers.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mempool: protect debug allocator against recursion

Sometimes we need to allocate memory during a free (for example when
we clean up page tables, we use rcu_defer(), which allocates memory).

Prevent this recursion with a flag.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
external: add aarch64 submodules

openjdk.bin
gcc.bin
misc.bin

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: add gcc sysroot for cross builds

Cross-builds of shared objects need a libc to link against (even though it
won't be used at runtime) and startup files.  Provide them in the gcc.bin
external repository for cross builds.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Update gcc.bin for glibc sysroot

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
build: relax naming of boost libraries

The aarch64 boost libraries have dropped the -mt suffix; so adapt the build
process to accept libraries with or without the suffix.  When the change
also arrives to x64 we can drop this hack.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
libc: define max_align_t

Needed by newer libstdc++.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
runtime: define __stack_chk_guard

Needed by newer libstdc++.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Switch to newer gcc

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge branch 'master' of https://github.com/cloudius-systems/osv