Skip to content

[lld] Non-compact (DWARF) unwind data emission is broken on MacOS if LTO is in use #135888

Open
@duk-37

Description

@duk-37

As a quick reproducer, compiling this code with the following flags should work fine unless -flto is specified, in which case there should be termination due to an uncaught exception:

// clang -O2 test.cpp -fomit-frame-pointer -fuse-ld=lld

#include <cstdio>

// contrived magic function that uses traditional DWARF unwind data when combined with -fomit-frame-pointer on OSX
__attribute__((noinline)) int foo() {
  int offset[70000];
  asm volatile("":"+m"(offset)::);
  throw 4;
}

int main() {
  try {
    foo();
  } catch (...) {
    printf("got it");
    return 1;
  }

  return 4;
}

The actual bug was introduced in https://reviews.llvm.org/D136380 - the assignment of the file pointer in order to map symbols to the original object file instead of the temporary monolithic LTO file causes the checks here and here to always fail. The former case never seems to be hit during LTO (should be fixed anyway though!), but the latter one is and thus causes exception metadata to never be emitted for functions that don't use compact unwind metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LTOLink time optimization (regular/full LTO or ThinLTO)lld:MachOmiscompilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions