forked from OSchip/llvm-project
76e9110f3d
While writing code for input and output formats in llvm-objcopy it became apparent that there was a code health problem. This change attempts to solve that problem by refactoring the code to use Reader and Writer objects that can read in different objects in different formats, convert them to a single shared internal representation, and then write them to any other representation. New classes: Reader: the base class used to construct instances of the internal representation Writer: the base class used to write out instances of the internal representation ELFBuilder: a helper class for ELFWriter that takes an ELFFile and converts it to a Object SectionVisitor: it became necessary to remove writeSection from SectionBase because, under the new Reader/Writer scheme, it's possible to convert between ELF Types such as ELF32LE and ELF32BE. This isn't possible with writeSection because it (dynamically) depends on the underlying section type *and* (statically) depends on the ELF type. Bad things would happen if the underlying sections for ELF32LE were used for writing to ELF64BE. To avoid this code smell (which would have compiled, run, and output some nonsesnse) I decoupled writing of sections from a class. SectionWriter: This is just the ELFT templated implementation of SectionVisitor. Many classes now have this class as a friend so that the writing methods in this class can write out private data. ELFWriter: This is the Writer that outputs to ELF BinaryWriter: This is the Writer that outputs to Binary ElfType: Because the ELF Type is not a part of the Object anymore we need a way to construct the correct default Writer based on properties of the Reader. This enum just keeps track of the ELF type of the input so it can be used as the default output type as well. Object has correspondingly undergone some serious changes as well. It now has more generic methods for building and manipulating ELF binaries. This interface makes ELFBuilder easy enough to use and will make the BinaryReader/Builder easy to create as well. Most changes in this diff are cosmetic and deal with the fact that a method has been moved from one class to another or a change from a pointer to a reference. Almost no changes should result in a functional difference (this is after all a refactor). One minor functional change was made and the result can be seen in remove-shstrtab-error.test. The fact that it fails hasn't changed but the error message has changed because that failure is detected at a later point in the code now (because WriteSectionHeaders is a property of the ElfWriter *not* a property of the Object). I'd say roughly 80-90% of this code is cosmetically different, 10-19% is different but functionally the same, and 1-5% is functionally different despite not causing a change in tests. Differential Revision: https://reviews.llvm.org/D42222 llvm-svn: 323480 |
||
---|---|---|
.. | ||
Inputs | ||
abs-symbol.test | ||
add-gnu-debuglink.test | ||
add-section-remove.test | ||
add-section.test | ||
adjacent-segments.test | ||
basic-binary-copy.test | ||
basic-copy.test | ||
basic-keep.test | ||
basic-only-keep.test | ||
basic-relocations.test | ||
binary-first-seg-offset-zero.test | ||
binary-no-paddr.test | ||
binary-out-error.test | ||
binary-paddr.test | ||
binary-remove-all-but-one.test | ||
binary-remove-end.test | ||
binary-remove-middle.test | ||
binary-segment-layout.test | ||
cannot-delete-dest.test | ||
check-addr-offset-align-binary.test | ||
check-addr-offset-align.test | ||
common-symbol.test | ||
drawf-fission.test | ||
dump-section.test | ||
dynamic-relocations.test | ||
dynamic.test | ||
dynstr.test | ||
dynsym-error-remove-strtab.test | ||
dynsym.test | ||
elf32be.test | ||
elf32le.test | ||
elf64be.test | ||
empty-section.test | ||
explicit-keep-remove.test | ||
explicit-only-keep-remove.test | ||
fail-no-output-directory.test | ||
hexagon-unsupported-on-x86.test | ||
identical-segments.test | ||
keep-many.test | ||
keep-only-keep.test | ||
localize-hidden.test | ||
no-symbol-relocation.test | ||
only-keep-many.test | ||
only-keep-remove-strtab.test | ||
only-keep-strip-non-alloc.test | ||
overlap-chain.test | ||
parent-loop-check.test | ||
program-headers.test | ||
pt-phdr.test | ||
reloc-error-remove-symtab.test | ||
remove-multiple-sections.test | ||
remove-section-with-symbol.test | ||
remove-section.test | ||
remove-shstrtab-error.test | ||
remove-symtab.test | ||
section-index-unsupported.test | ||
sectionless-segment.test | ||
segment-shift-section-remove.test | ||
segment-shift.test | ||
segment-test-remove-section.test | ||
strip-all-gnu.test | ||
strip-all.test | ||
strip-debug.test | ||
strip-non-alloc.test | ||
strip-sections-keep.test | ||
strip-sections-only-keep.test | ||
strip-sections.test | ||
symbol-copy.test | ||
symtab-error-on-remove-strtab.test | ||
triple-overlap.test | ||
two-seg-remove-end.test | ||
two-seg-remove-first.test | ||
two-seg-remove-third-sec.test |