This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: do not hang linker on infinite nested INCLUDE command.
AbandonedPublic

Authored by grimar on Sep 4 2017, 8:25 AM.

Details

Reviewers
ruiu
rafael
Summary

It was easy to hang LLD when INCLUDE command including the same file.

Documentation says that nesting up to 10 levels is allowed:

INCLUDE filename
Include the linker script filename at this point. The file will be searched for in
the current directory, and in any directory specified with the ‘-L’ option. You
can nest calls to INCLUDE up to 10 levels deep.

Patch stores nesting level for each MemoryBufferRef we create,
so it is possible to error out when limit of 10 levels is reached.

Diff Detail

Event Timeline

grimar created this revision.Sep 4 2017, 8:25 AM
grimar edited the summary of this revision. (Show Details)Sep 4 2017, 8:26 AM

Looks like a useful error message. I've checked that ld.bfd matches its documentation and has a maximum limit of 10. I've spotted one typo in the error message, and have made a minor stylistic suggestion but don't have a strong opinion on it.

ELF/ScriptLexer.cpp
93

typo: I think you meant "up to" instead of "up do". It may also be worth expressing the error explicitly, at the moment the user has to imply that they have exceeded the maximum limit. Perhaps something like "Maximum include nesting level of 10 exceeded."

ELF/ScriptLexer.h
49–50

getCurrentMB() is now returning <MemoryBuffer, depth> pair. In each of the cases where it is called only one of the two fields of the pair is used. Would it be better to have getCurrentMB() return first, and add a new function getCurrentMBDepth() that returns the second. That should allow the .firsts and .second from the calling code.

grimar updated this revision to Diff 113824.Sep 5 2017, 3:24 AM

Thanks for comments, Peter !
I applied both your suggestions.

ruiu edited edge metadata.Sep 5 2017, 10:58 AM

Something's not right in this patch. I don't think you need to add code there. Instead, you could add code to ScriptParser::readInclude.

grimar updated this revision to Diff 113982.Sep 6 2017, 3:35 AM
  • Addressed review comments.
ruiu added a comment.Sep 6 2017, 10:47 AM

This is still too clever and too complicated for a safety measure. We need more simple-minded one. I'll write it up and send it to you.

grimar abandoned this revision.Sep 7 2017, 2:31 AM

If favor of committed D37524.