summaryrefslogtreecommitdiffstats
path: root/courgette/disassembler_elf_32.cc
Commit message (Collapse)AuthorAgeFilesLines
* [Courgette] Add and use AddressTranslator::PointerToTargetRVA(); Update ↵huangs2016-03-231-2/+7
| | | | | | | | | | | | | | | | | | | comments. Addresses in Courgette (abs32 and rel32) are represented in these forms: (1) Location RVA. (2) Location FileOffset. (3) Pointer in image. (4) Target VA. (5) Target RVA. We already have (1) -> (2), (2) -> (1), (2) -> (3), (1) -> (3) for existing usage. Now we add (3) -> (5) and refactor accordingly (with helpers to do (4) -> (5) for PE files). PointerToTargetRVA() will be used again we apply LabelManager to save 25% peak RAM. Review URL: https://codereview.chromium.org/1807293003 Cr-Commit-Position: refs/heads/master@{#382920}
* [Courgette] Clean up Disassembler; fix ELF Memory leaks.huangs2016-03-141-179/+154
| | | | | | | | | | | | | | | | | | | | | Cleaning up code surrounding Disassembler: - Extract AddressTranslator interface to be used across subclasses. - Use FileOffset = size_t by context. - Detailed comments & TODOs in DisassemblerElf32ARM. - Fix DisassemblerElf32ARM memory leaks. - Lots of superficial stylistic changes. Except for AddressTranslator routines and unit tests, shying away from control flow and logic changes. BUG=579206 Committed: https://crrev.com/58b822d441f5c982e879e536fa3c1cbac8fd339a Cr-Commit-Position: refs/heads/master@{#380881} Review URL: https://codereview.chromium.org/1676683002 Cr-Commit-Position: refs/heads/master@{#380987}
* Revert of [Courgette] Clean up Disassembler; fix ELF Memory leaks. (patchset ↵scottmg2016-03-121-154/+179
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #15 id:270001 of https://codereview.chromium.org/1676683002/ ) Reason for revert: Regressed linux sizes (iostream maybe?) https://build.chromium.org/p/chromium/builders/Linux/builds/72899/steps/sizes/logs/stdio Original issue's description: > [Courgette] Clean up Disassembler; fix ELF Memory leaks. > > Cleaning up code surrounding Disassembler: > - Extract AddressTranslator interface to be used across subclasses. > - Use FileOffset = size_t by context. > - Detailed comments & TODOs in DisassemblerElf32ARM. > - Fix DisassemblerElf32ARM memory leaks. > - Lots of superficial stylistic changes. > > Except for AddressTranslator routines and unit tests, shying away > from control flow and logic changes. > > BUG=579206 > > Committed: https://crrev.com/58b822d441f5c982e879e536fa3c1cbac8fd339a > Cr-Commit-Position: refs/heads/master@{#380881} TBR=grt@chromium.org,wfh@chromium.org,chrisha@chromium.org,andrewhayden@chromium.org,huangs@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=579206 Review URL: https://codereview.chromium.org/1792603006 Cr-Commit-Position: refs/heads/master@{#380885}
* [Courgette] Clean up Disassembler; fix ELF Memory leaks.huangs2016-03-121-179/+154
| | | | | | | | | | | | | | | | | | Cleaning up code surrounding Disassembler: - Extract AddressTranslator interface to be used across subclasses. - Use FileOffset = size_t by context. - Detailed comments & TODOs in DisassemblerElf32ARM. - Fix DisassemblerElf32ARM memory leaks. - Lots of superficial stylistic changes. Except for AddressTranslator routines and unit tests, shying away from control flow and logic changes. BUG=579206 Review URL: https://codereview.chromium.org/1676683002 Cr-Commit-Position: refs/heads/master@{#380881}
* [Courgette] Fix AssemblyProgram parsing for ELF-ARM.huangs2016-02-041-16/+15
| | | | | | | | | | | | | | | | | | | This fixes two problems: (A) In DisassemblerElf32, RVAToFileOffset() used Program Segment Header, but FileOffsetToRVA() used Section Header. For consistency, both should use the same one. We choose the latter (for now). (B) Even if a section has sh_type=SHT_PROGBITS, it can still have sh_addr=0. Extracting Rel32 address from these sections would add overlapping RVA chaos, and so should be avoided. Also using elf-arm7 in a unit test. The test fails before the fix and passes after. BUG= 579206 Review URL: https://codereview.chromium.org/1658463002 Cr-Commit-Position: refs/heads/master@{#373639}
* [Courgette] Simplify EncodedProgram Label addition code; removed "1.01 x" ↵huangs2016-01-191-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | memory fix. This CL simplifies how Labels get flattened to a list of RVAs. In the past EncodedProgram used DefineAbs32Label() / DefineRel32Label(), which let callers add one Label at a time. Complexity arose from: - Function pointer usage to avoid duplicate code for abs32 and rel32. - Need for EncodedProgram to dynamically adjust size of RVA list. This led to inefficient array resizing, which was fixed by the "1.01 x" memory growth. Change: We now pass the collection of abs32 and rel32 Labels to EncodedProgram. This simplifies the interface, and allows EncodedProgram to find the max indexes and preallocated buffers. The trade-off is increased test code complexity, since we'd need to create Label collection. Other changes: - Update namespace{} for EncodedProgram and its tests. - Add more Label constructors (for testing). - Add LabelManager::GetIndexBound(), for LabelVector and RVAToLabel. - Add kUnassignedRVA in image_utils.h, with checks for its absence in images. Review URL: https://codereview.chromium.org/1571913003 Cr-Commit-Position: refs/heads/master@{#370200}
* Switch to standard integer types in courgette/.avi2015-12-211-7/+7
| | | | | | | | | | BUG=138542 TBR=wfh@chromium.org NOPRESUBMIT=true Review URL: https://codereview.chromium.org/1543643002 Cr-Commit-Position: refs/heads/master@{#366439}
* Robust ELF header parsing.halyavin2015-03-241-27/+27
| | | | | | | | | | | Check all out-of-bounds errors in ELF header parsing. BUG= none TEST= courgette_unittests Review URL: https://codereview.chromium.org/1031513002 Cr-Commit-Position: refs/heads/master@{#322003}
* Fix courgette ELF x86 dissemblerWill Harris2015-03-021-2/+3
| | | | | | | | | | | | | | | | | | | Courgette cannot parse files that have out of order NOBITS sections and instead will crash. The solution to this is to skip them and encode them as raw bytes. Also, courgette has a bug where it incorrectly emits ElfRelocationInstruction instructions even when there are no valid R_386_RELATIVE relocations in the file. Added a test file that exhibits both of these symptoms. BUG=424820,423925 TEST=courgette_unittests R=dgarrett@chromium.org, tommi@chromium.org Review URL: https://codereview.chromium.org/664803002 Cr-Commit-Position: refs/heads/master@{#318764}
* Fix more MSVC warnings, courgette/ edition.pkasting2014-10-031-7/+3
| | | | | | | | | | | | This is mostly about changing types and inserting casts so as to avoid implicit value truncations. BUG=81439 TEST=none Review URL: https://codereview.chromium.org/613893002 Cr-Commit-Position: refs/heads/master@{#298069}
* This patch uses single BytesInstruction Courgette ops to point to long ↵paulgazz@chromium.org2013-08-131-6/+6
| | | | | | | | | | stretches of the binary file, instead of using one ByteInstruction op, which copies one byte at a time. This reduces memory usages for very large files, since less data is copied, and fewer Instruction classes are constructed. BUG=266068 Review URL: https://chromiumcodereview.appspot.com/22728002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217138 0039d316-1c4b-4281-b951-d872f2087c98
* Support for ARM 32-bit ELF binaries in Courgettepaulgazz@chromium.org2013-08-011-2/+2
| | | | | | | | | | | | Notes for reviewers: dgarrett: courgette correctness, ARM benchan: style, correctness BUG=258640,258645,258653 Review URL: https://chromiumcodereview.appspot.com/20099004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214873 0039d316-1c4b-4281-b951-d872f2087c98
* Added a TypedRVA to track what kind of branch instruction is used forpaulgazz@chromium.org2013-07-231-21/+38
| | | | | | | | | | | | the jump and compute the target RVA accordingly. Also updated the unit test to use TypedRVA and check that only X86 RVAs are found by the X86 "disassembler". BUG=258645 Review URL: https://chromiumcodereview.appspot.com/18055007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213220 0039d316-1c4b-4281-b951-d872f2087c98
* Fixed Courgette to correctly regenerate the ELF relocation table forpaulgazz@chromium.org2013-07-181-1/+28
| | | | | | | | | | | | | | ARM binaries. Note for reviewers: Don: general courgette correctness Ben: style, correctness BUG=258648 Review URL: https://chromiumcodereview.appspot.com/19022007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212449 0039d316-1c4b-4281-b951-d872f2087c98
* Factored out common ELF processing into a common superclass, an x86 ↵paulgazz@chromium.org2013-06-201-0/+462
subclass, and an initial ARM subclass. Created a new disassembler virtual class, DisassemblerElf32, that implements the common functions for processing ELF 32-bit files. This class is defined in disassembler_elf_32.{h|cc}, and has nearly all of the methods and data that used to be in disassembler_elf_32_x86.{h|cc}. This class has two subclasses, one for x86 and one for arm, which implement the architecture-specific parts for generating courgette patches, namely extracting relative and absolute addresses. The ARM subclass is just a shell, but still yields correct courgette patches. The rest of the files add new enums for ARM and use the ARM subclasses for the courgette command-line tool. BUG= Review URL: https://chromiumcodereview.appspot.com/17325003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207388 0039d316-1c4b-4281-b951-d872f2087c98