This is an archive of the discontinued LLVM Phabricator instance.

[ADT] [lld-macho] Check for end iterator deref in filter_iterator_base
ClosedPublic

Authored by BertalanD on Jun 21 2022, 11:20 AM.

Details

Summary

If ld64.lld was supplied an object file that had a __debug_abbrev or
__debug_str section, but didn't have any compile unit DIEs in
__debug_info, it would dereference an iterator pointing to the empty
array of DIEs. This underlying issue started causing segmentation faults
when parsing for __debug_info was addded in D128184. That commit was
reverted, and this one fixes the invalid dereference to allow relanding
it.

This commit adds an assertion to filter_iterator_base's dereference
operators to catch bugs like this one.

Ran check-llvm, check-clang and check-lld

Diff Detail

Event Timeline

BertalanD created this revision.Jun 21 2022, 11:20 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 21 2022, 11:20 AM
BertalanD requested review of this revision.Jun 21 2022, 11:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 11:20 AM
BertalanD edited the summary of this revision. (Show Details)Jun 21 2022, 11:22 AM
thakis accepted this revision.Jun 21 2022, 11:26 AM
thakis added a subscriber: thakis.

Nice!

This revision is now accepted and ready to land.Jun 21 2022, 11:26 AM
mstorsjo added inline comments.
lld/test/MachO/dwarf-no-compile-unit.yaml
1 ↗(On Diff #438772)

(driveby comment) I don't think you'd need the aarch64 target enabled, just for running yaml2obj on an aarch64 object file (unless the linker requires the aarch64 target for linking)?

int3 added a subscriber: int3.Jun 21 2022, 11:33 AM
int3 added inline comments.
lld/MachO/InputFiles.cpp
1016

parens unnecessary

lld/test/MachO/dwarf-no-compile-unit.yaml
3–4 ↗(On Diff #438772)

how was this generated?

llvm/include/llvm/ADT/STLExtras.h
447–456

this seems like it should be a separate commit

447–456

(but if thakis thinks it's fine then I guess it is)

int3 added inline comments.Jun 21 2022, 11:35 AM
lld/test/MachO/dwarf-no-compile-unit.yaml
3–4 ↗(On Diff #438772)

(and why can't we generate it directly from llvm-mc?)

BertalanD added inline comments.Jun 21 2022, 11:37 AM
lld/test/MachO/dwarf-no-compile-unit.yaml
3–4 ↗(On Diff #438772)

I guess we can. I'll update the patch in a sec.

thakis added inline comments.Jun 21 2022, 11:56 AM
llvm/include/llvm/ADT/STLExtras.h
447–456

(bertaland suggested making it a separate commit originally, but I thought it'd be nice to have assert and fix in one change (?))

Call llvm-mc directly and remove unnecessary parentheses.

BertalanD planned changes to this revision.Jun 21 2022, 12:02 PM

oops, no

missing a REQUIRES line

int3 accepted this revision.Jun 21 2022, 12:02 PM

much shorter test case, nice :)

lld/test/MachO/dwarf-no-compile-unit.s
6

could just be -o /dev/null

llvm/include/llvm/ADT/STLExtras.h
447–456

ah gotcha

oops, no

missing a REQUIRES line

Sorry about that - indeed, if switching back to llvm-mc, you'll need the REQUIRES.

Third time's the charm (hopefully)

added missing REQUIRES and switched to -o /dev/null

Thank you for all the suggestions.

This revision is now accepted and ready to land.Jun 21 2022, 12:11 PM
This revision was landed with ongoing or failed builds.Jun 21 2022, 12:50 PM
This revision was automatically updated to reflect the committed changes.