[yaml2obj] - Introduce a 10 Mb limit of the output by default and a --max-size option.
authorGeorgii Rymar <grimar@accesssoftek.com>
Fri, 5 Jun 2020 12:50:59 +0000 (15:50 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Wed, 10 Jun 2020 12:23:59 +0000 (15:23 +0300)
commit3c123acf57cb21faed327d7f36a1146875c67319
tree4bccdee4e1c516508c6b43730fe7e1920e1c17e5
parent01a0c3b49aa2030d0da789e71e8ecf880284b89a
[yaml2obj] - Introduce a 10 Mb limit of the output by default and a --max-size option.

Multiple times we faced an issue of huge outputs due to unexpected behavior
or incorrect test cases. The last one was https://reviews.llvm.org/D80629#2073066.

This patch limits the output to 10 Mb for ELF and introduces the --max-size to change this
limit.

I've tried to keep the implementation non-intrusive.

The current logic we have is that we prepare section content in a buffer first and write
it to the output later. This patch checks the available limit on each writing attempt to this buffer
and stops writing when the limit is reached and raises the internal error flag.
Later, this flag is is checked before the actual writing to a file happens and
an error is reported.

Differential revision: https://reviews.llvm.org/D81258
llvm/include/llvm/ObjectYAML/yaml2obj.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/yaml2obj.cpp
llvm/test/tools/yaml2obj/ELF/output-limit.yaml [new file with mode: 0644]
llvm/tools/yaml2obj/yaml2obj.cpp