Skip to content

Commit

Permalink
illumos: Treat absolute symbols specially
Browse files Browse the repository at this point in the history
illumos is a descendent of Solaris/OpenSolaris, and treats
symbols with shndx=SHN_ABS and st_value=0 specially, such that
they should be marked imported.  This change adds a special
case for this behavior, wrapped up in a function that #ifdef's
out on other platforms.  With this patch, executables linked
with mold on illumos run; without it, they do not.

The original behavior was spotted by Luqman Aden (@luqmana).
This also patches a small bogon in the third-party `mimalloc`
code.  I've sent that same fix upstream, but so far the
maintainer has not resonded, so replicate here.

Fixes #1183

Signed-off-by: Dan Cross <cross@oxidecomputer.com>
  • Loading branch information
dancrossnyc committed Feb 1, 2024
1 parent c36b83f commit bed5b17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,20 @@ void parse_symbol_version(Context<E> &ctx) {
});
}

namespace {
template <typename E>
inline bool should_import_absolute_sym(const Symbol<E> *sym) {
#ifdef __sun
// On illumos, symbols with shndx=SHN_ABS and st_value=0 are special
// and should be imported.
return sym->value == 0;
#else
(void)sym;
return false;
#endif
}
} // anonymous namespace

template <typename E>
void compute_import_export(Context<E> &ctx) {
Timer t(ctx, "compute_import_export");
Expand Down Expand Up @@ -1823,7 +1837,7 @@ void compute_import_export(Context<E> &ctx) {
for (Symbol<E> *sym : file->get_global_syms()) {
// If we are using a symbol in a DSO, we need to import it.
if (sym->file && sym->file->is_dso) {
if (!sym->is_absolute()) {
if (!sym->is_absolute() || should_import_absolute_sym(sym)) {
std::scoped_lock lock(sym->mu);
sym->is_imported = true;
}
Expand Down
2 changes: 1 addition & 1 deletion third-party/mimalloc/src/prim/unix/prim.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static void* unix_mmap(void* addr, size_t size, size_t try_alignment, int protec
#elif defined(__sun)
if (allow_large && _mi_os_use_large_page(size, try_alignment)) {
struct memcntl_mha cmd = {0};
cmd.mha_pagesize = large_os_page_size;
cmd.mha_pagesize = _mi_os_large_page_size();
cmd.mha_cmd = MHA_MAPSIZE_VA;
if (memcntl((caddr_t)p, size, MC_HAT_ADVISE, (caddr_t)&cmd, 0, 0) == 0) {
*is_large = true;
Expand Down

0 comments on commit bed5b17

Please sign in to comment.