This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Emit diagnostic for invalid size directive
Needs ReviewPublic

Authored by bcain on Apr 22 2021, 7:35 AM.

Details

Reviewers
MaskRay
Summary

If a .size directive which uses an expression to calculate the size has a typo
in a label reference or references a label from another section, it is invalid.
Emit an error instead of a fatal error, and if there's a way to hint at the
cause, emit relevant diagnostic notes.

Diff Detail

Event Timeline

bcain created this revision.Apr 22 2021, 7:35 AM
bcain requested review of this revision.Apr 22 2021, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2021, 7:35 AM

Is it overkill to add a spell corrector? .size is usually generated by the compiler, so this can only be useful for hand-written assembly. Though I wonder how many times this can be useful.

bcain added a comment.Apr 26 2021, 8:00 AM

Is it overkill to add a spell corrector? .size is usually generated by the compiler, so this can only be useful for hand-written assembly. Though I wonder how many times this can be useful.

For whatever reason, many hexagon developers frequently use the .size directive to set the function size correctly when hand-writing assembly. There may be / may have been some developer scripts that expected/relied on this being set.

This particular patch is inspired by developer bug reports - including one that had a .size referencing a label incorrectly - with a single-character error: differing only in case.

If you think the "did you mean..." is overkill, I am happy to remove it.

bcain added a subscriber: hexhexd.Apr 26 2021, 8:00 AM

Yeah, I kinda feel like we are not making good use of the 50 lines of code. .size is too minor a feature that I'd waste 50 lines, adding MCAssembler &Asm, in various places to make this work.
To make good use of the 50 lines, this should be something generic (think as a utility similar to evaluateAsRelocatable), so that every other directive which has similar usage to .size can benefit from this.

bcain added a comment.Apr 27 2021, 7:45 AM

Yeah, I kinda feel like we are not making good use of the 50 lines of code. .size is too minor a feature that I'd waste 50 lines, adding MCAssembler &Asm, in various places to make this work.
To make good use of the 50 lines, this should be something generic (think as a utility similar to evaluateAsRelocatable), so that every other directive which has similar usage to .size can benefit from this.

Hmm. Removing the spell check portion of NoteUndef only saves around ~9 lines. So it sounds like that's not sufficient? You prefer either not accepting any of this patch or expanding its scope to include other directives? I will explore the latter.

Yeah, I kinda feel like we are not making good use of the 50 lines of code. .size is too minor a feature that I'd waste 50 lines, adding MCAssembler &Asm, in various places to make this work.
To make good use of the 50 lines, this should be something generic (think as a utility similar to evaluateAsRelocatable), so that every other directive which has similar usage to .size can benefit from this.

Hmm. Removing the spell check portion of NoteUndef only saves around ~9 lines. So it sounds like that's not sufficient? You prefer either not accepting any of this patch or expanding its scope to include other directives? I will explore the latter.

Yes, reusing this in more places can improve its value... I am also a bit unsure about did you mean to refer suggesting more than one symbol.