LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 48389 - ld64.lld.darwinnew unwind info is incorrect
Summary: ld64.lld.darwinnew unwind info is incorrect
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: MachO (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Jez Ng
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-04 10:06 PST by Nico Weber
Modified: 2021-02-23 19:19 PST (History)
4 users (show)

See Also:
Fixed By Commit(s): rG4a5e111aea7ac78190211a2549f8d0d53ee2f01d


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nico Weber 2020-12-04 10:06:20 PST
…or at least subtly different from ld64.

Repro:
1. Download https://drive.google.com/file/d/1Gjrg4bQCv3uD9Ucqt4ZtroHrz5v0iCJX/view?resourcekey=0-f53UMW57gtrPlSis2sTjKg and unzip it

2. ~/src/llvm-project/out/gn/bin/ld64.lld.darwinnew @response.txt

3. ./base_unittests --gtest_filter='*Exception*'


Expected: All 3 tests pass

Actual: CallWithEHFrameTest.CatchExceptionHigher crashes.

If you remove --color-diagnostics from response.txt and link with regular `ld`, it passes.


The source of the test is here: https://source.chromium.org/chromium/chromium/src/+/master:base/mac/call_with_eh_frame_unittest.mm;l=25?q=CatchExceptionHigher&ss=chromium

The implementation of CallWithEHFrame is here: https://source.chromium.org/chromium/chromium/src/+/master:base/mac/call_with_eh_frame_asm.S;bpv=1;bpt=0 It's assembly with a custom personality routine, so it's possible things are wrong in the code -- but it's been working for 5 years and it works with ld64. https://codereview.chromium.org/1212093002 has the motivation for that code.
Comment 1 Nico Weber 2021-01-10 10:09:48 PST
This is not a subtle bug after all. Exceptions just don't work at all:

% cat throw.cc
int main() {
  try {
    throw 0;
  } catch (int i) {
    return i;
  }
}
% out/gn/bin/clang++ throw.cc -fuse-ld=lld.darwinnew
lld: warning: Option `-no_deduplicate' is not yet implemented. Stay tuned...
% ./a.out ; echo $?
libc++abi.dylib: terminating with uncaught exception of type int
zsh: abort      ./a.out
134

Works fine with ld64.
Comment 2 Nico Weber 2021-01-10 10:13:32 PST
ObjC exceptions also don't work:

% cat throw.m
int main() {
  @try {
    @throw (void*)0;
  } @catch (id i) {
    return i;
  }
}
% out/gn/bin/clang++ throw.m -framework Foundation -fuse-ld=lld.darwinnew
throw.m:5:12: warning: incompatible pointer to integer conversion returning 'id' from a function with result type 'int' [-Wint-conversion]
    return i;
           ^
1 warning generated.
lld: warning: Option `-no_deduplicate' is not yet implemented. Stay tuned...
% ./a.out
2021-01-10 13:09:10.871 a.out[73775:15821192] *** Terminating app due to uncaught exception of class 'nil'
libc++abi.dylib: terminating with uncaught exception of type nil
zsh: abort      ./a.out


(Also fine with ld64.)
Comment 3 Jez Ng 2021-01-10 15:48:47 PST
Yeah, the `__eh_frame` support is not done yet (I was just asking gkm about it yesterday).
Comment 4 Nico Weber 2021-02-08 16:35:12 PST
I see some LSDA / personality stuff landed. Is this expected to work now, or not yet?
Comment 5 Jez Ng 2021-02-09 10:28:32 PST
The simple examples work, but the CallWithEHFrameTest still fails. To be precise, when linking, we hit the "too many personalities for compact unwind to encode" error. Just to see what would happen, I turned that error into a warning, and then ran the resulting binary -- CatchExceptionHigher passes, but CatchExceptionLower fails. So we're not quite there yet.
Comment 6 Jez Ng 2021-02-22 18:57:34 PST
Figured it out :) https://reviews.llvm.org/D97245