Page MenuHomePhabricator

[lld][mach-o] Avoid segfaulting when handling an empty section list.
ClosedPublic

Authored by mattd on Sep 18 2019, 2:57 PM.

Details

Summary

The following patch avoids segfaulting if the section list is empty when writing a mach-o MH_OBJECT. I ran into this case from a more complicated example trying to dead_strip while using '-r' in lld.

I'm not sure if having empty sections is a legal mach-o, but it does seem that other llvm-binutils tools can ingest such a boring object with out issue. Would it be better to emit an error, emit a warning, or do nothing? It seems that adding a warning diagnostic might be helpful to users, as I did not expect to have a section-less object when the linker was done.

Diff Detail

Event Timeline

mattd created this revision.Sep 18 2019, 2:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2019, 2:58 PM
mattd retitled this revision from [lld][mach-o] Avoid segfaulting when handling an empty segment list. to [lld][mach-o] Avoid segfaulting when handling an empty section list..Sep 18 2019, 2:59 PM
ruiu added a comment.Sep 25 2019, 3:25 AM

LGTM

I don't have a strong preference over silently accepting or reporting an error on an empty YAML, so this change seems fine. Thank you for doing htis.

mattd added a comment.Sep 25 2019, 8:13 AM

LGTM

I don't have a strong preference over silently accepting or reporting an error on an empty YAML, so this change seems fine. Thank you for doing htis.

Thanks @ruiu! Would you mind accepting this patch so that I can land it, or should I wait for others to accept it?

ruiu accepted this revision.Sep 26 2019, 2:14 AM

Apologies, I didn't choose "accept" in the previous comment. Doing it now. Feel free to commit (but please run all unit tests before commiting.)

This revision is now accepted and ready to land.Sep 26 2019, 2:14 AM
This revision was automatically updated to reflect the committed changes.