I guess it's about time we addressed the issue with libunwind.

libunwind is involved in stack traces and exception handling.

it is a separate library on linux and on MacOSX < 10.7.

As of 10.7, libunwind was rolled into libSystem.

Jeremy set up a libunwind port years ago to support older systems < 10.7.

Unfortunately the (old) libunwind library and headers have been installed on 
all newer systems ever since.

The libunwind installed by the libunwind port suits 10.6 and less just fine, 
but has no role being installed on 10.7+.

A PR to have it not install anything (just be a dummy port exactly like libcxx 
is for libc++ is here:

https://github.com/macports/macports-ports/pull/27319


Once libunwind is a dummy port on 10.7, there will be breakage. Some things 
will be unbroken just by revbumping.

Whether all the ports that enable stack unwinding, etc, are smart enough to 
know they should just use libSystem instead of libunwind on MacOS is unknown... 
probably, lots of them don't know to do that.

There is a much newer libunwind currently installed with the clang ports. It 
would be similar to what is being used in modern MacOS systems.

We could consider installing that into ${prefix} and let it be found, but that 
just seems like a bad idea to be doing that. Perhaps it could work out. It 
would satisfy builds that are looking for the libunwind library to enable stack 
unwinding.

I would suggest we don't install that new libunwind into ${prefix}, we let 
libunwind be a dummy port and install nothing on 10.7+, and then start the 
project of fixing ports that benefit from the functionality of libunwind but 
don't know enough to use libSystem on newer MacOS -- that is what they should 
be doing anyway.

There will be wreckage from this.

Ken



Here is a small C application that chatgpt spewed up to demonstrate that 
libunwind is in libSystem on MacOS and works:


===========

#include <libunwind.h>
#include <stdio.h>

void print_stack_trace() {
    unw_cursor_t cursor;   // Stack cursor
    unw_context_t context; // Current machine state

    // Initialize the context and cursor
    unw_getcontext(&context);
    unw_init_local(&cursor, &context);

    printf("Stack trace:\n");
    while (unw_step(&cursor) > 0) {
        char func_name[256];
        unw_word_t offset, pc;

        unw_get_reg(&cursor, UNW_REG_IP, &pc);
        if (unw_get_proc_name(&cursor, func_name, sizeof(func_name), &offset) 
== 0) {
            printf("  %p: %s+0x%lx\n", (void*)pc, func_name, offset);
        } else {
            printf("  %p: -- unknown function --\n", (void*)pc);
        }
    }
}

void dummy_function() {
    print_stack_trace();
}

int main() {
    dummy_function();
    return 0;
}
=============

Reply via email to