This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Fix assertion when two symbols at same addr have unwind info
ClosedPublic

Authored by int3 on Jul 20 2022, 3:36 PM.

Details

Summary

If there are multiple symbols at the same address, our unwind info
implementation assumes that we always register unwind entries to a
single canonical symbol.

This assumption was violated by the registerEhFrame code.

Fixes #56570.

Diff Detail

Event Timeline

int3 created this revision.Jul 20 2022, 3:36 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 20 2022, 3:36 PM
int3 requested review of this revision.Jul 20 2022, 3:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2022, 3:36 PM
int3 edited the summary of this revision. (Show Details)Jul 20 2022, 3:38 PM
oontvoo added inline comments.
lld/test/MachO/Inputs/double-unwind-info.yaml
2

would be great to have comment on how this yaml was created (ie., the .s file and/or any special flag?) in case we need to update it in the future

int3 marked an inline comment as done.Jul 20 2022, 4:37 PM
int3 added inline comments.
lld/test/MachO/Inputs/double-unwind-info.yaml
2

See the comments in double-unwind-info.s :)

thakis accepted this revision.Jul 21 2022, 5:50 AM
thakis added a subscriber: thakis.

Stamp, but:

lld/MachO/InputFiles.cpp
1536

We hit this assert in "normal" builds: https://bugs.chromium.org/p/chromium/issues/detail?id=1346125#c1

Do you want a repro file for that?

Anyways, addressing the assert quickly would be good :) (either revert if hitting this on a normal build is surprising and needs more investigation, or by landing this fix here)

This revision is now accepted and ready to land.Jul 21 2022, 5:50 AM
int3 marked an inline comment as done.Jul 21 2022, 6:39 AM
int3 added inline comments.
lld/MachO/InputFiles.cpp
1536

Just to confirm, are you sure the "normal" build doesn't pull in any 3rd-party lib that could've been passed through ld -r?

I wasn't able to generate it the problem via llvm-mc in my testing, but I could certainly have missed something. Repro file wouldn't really help to figure out the compiler flags that trigger it though...

It doesn't look like the assert triggers at all on chromium_framework at least, so I think it's safe to say that it's a fairly uncommon code path

int3 added inline comments.Jul 21 2022, 6:43 AM
lld/MachO/InputFiles.cpp
1536

It doesn't look like the assert triggers at all on chromium_framework at least, so I think it's safe to say that it's a fairly uncommon code path

More precisely, an assert(false) in this if branch doesn't get tripped while linking chromium_framework.

Landing this now, we can tweak the comment as needed later

abrachet added inline comments.
lld/MachO/InputFiles.cpp
1536

Hi this is crashing for us too I've uploaded a reproducer here https://drive.google.com/file/d/1tz3feLMfR-2N8SMxT5dqLqAN3dUVSGRQ/view?usp=sharing. Though it seems like not all input files correctly made it into the reproducer.
See https://ci.chromium.org/ui/p/fuchsia/builders/prod/clang-mac-xarm64/b8807891867843444577/overview which is an lto build of llvm. If it's helpful here's what funcSym looks like before the crash

(lldb) p *funcSym
(lld::macho::Defined) $9 = {
  lld::macho::Symbol = {
    gotIndex = 4294967295
    lazyBindOffset = 4294967295
    stubsHelperIndex = 4294967295
    stubsIndex = 4294967295
    symtabIndex = 4294967295
    symbolKind = DefinedKind
    nameData = 0x000000011986014f "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1B6v15000IDnEEPKc"
    file = 0x000000011a849a00
    nameSize = 82
    isUsedInRegularObj = true
    used = false
  }
  overridesWeakDef = false
  privateExtern = true
  includeInSymtab = true
  wasIdenticalCodeFolded = false
  thumb = false
  referencedDynamically = false
  noDeadStrip = false
  interposable = false
  weakDefCanBeHidden = false
  weakDef = true
  external = true
  isec = nullptr
  value = 0
  size = 0
  unwindEntry = nullptr
}
abrachet added inline comments.Jul 22 2022, 8:09 PM
lld/MachO/InputFiles.cpp
1536

Ignore the "too" in my comment. I incorrectly read @thakis's comment as him saying this was causing an assertion failure not fixing one.

int3 marked 2 inline comments as done.Jul 22 2022, 11:12 PM
int3 added inline comments.
lld/MachO/InputFiles.cpp
1536

whoops, guess it's bug whackamole season. Sorry about that. D130409 should fix.

Sorry for the slow turnaround – was at a conference last week, and don't build the iOS code all that often.

Here's a repro file: https://drive.google.com/file/d/1wMTTtgtLgrnXPZ--qpx1jUJs3spXeLmo/view?usp=sharing

The assertion used to fire for Users/thakis/src/chrome/src/out/gnios/obj/ios/chrome/browser/ui/omnibox/popup/popup_swift/omnibox_popup_view_provider.o. That .o file is created by compiling https://source.chromium.org/chromium/chromium/src/+/main:ios/chrome/browser/ui/omnibox/popup/omnibox_popup_view_provider.swift;l=1?q=omnibox_popup_view_provider.&sq= (I can get the exact compile command if it helps). It's a swift file, so maybe this is needed for all swift .o files? If so, this would probably slow down links of projects using swift a bit (?)

(For my own notes:

args.gn:

use_goma = true
dcheck_always_on = false
is_debug = false
symbol_level = 0
target_os = "ios"
target_cpu = "arm64"
ios_enable_code_signing = false

At chromium rev 3695eeb95bcf70bcbad32a4166c0d0748ed61d99.

Ran:

% time ninja -C out/gnios ios_chrome_unittests -j250     
% rm out/gnios/obj/ios/chrome/test/arm64/ios_chrome_unittests
% LLD_REPRODUCE=repro-ios.tar ninja -C out/gnios obj/ios/chrome/test/arm64/ios_chrome_unittests

)