autc04 / Retro68

a gcc-based cross-compiler for classic 68K and PPC Macintoshes
GNU General Public License v3.0
537 stars 51 forks source link

-Wl,--gc-sections on 68k causes crashes when C++ exceptions are thrown #217

Open VyrCossont opened 8 months ago

VyrCossont commented 8 months ago

To repro:

  1. Start with the Samples/HelloWorld project
  2. Replace hello.c file with hello.cpp below
  3. Replace hello.c with hello.cpp in CMakeLists.txt
  4. Build for 68k
  5. Run resulting app in SheepShaver
  6. App crashes instead of waiting for the user to press Return
// hello.cpp

#include <stdio.h>
#include <stdexcept>

int main(int argc, char** argv)
{
    printf("Hello, world.\n");

    try {
        throw std::runtime_error("boom!");
    } catch (std::runtime_error &e) {
        printf("Exception caught: %s", e.what());
    }

    printf("\n(Press Return)\n");
    getchar();
    return 0;
}

App works normally when compiled for the host (gcc -o hello hello.cpp -lc++ && ./hello) or when built with Retro68's PPC target. App also works normally if -Wl,--gc-sections is removed from the 68k linker flags in HelloWorld's CMakeLists.txt.

VyrCossont commented 8 months ago

I'm not sure if this is related to #184, since -ffunction-sections is already present in CMakeLists.txt.