summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object
Commit message (Collapse)AuthorAgeFilesLines
* Inline function into only use.Rafael Espindola2015-07-081-12/+6
| | | | llvm-svn: 241692
* Add a helper function to reduce a bit of code duplication.Rafael Espindola2015-07-081-25/+22
| | | | llvm-svn: 241691
* Use a range loop. NFC.Rafael Espindola2015-07-081-8/+6
| | | | llvm-svn: 241685
* Delete UnknownAddress. It is a perfectly valid symbol value.Rafael Espindola2015-07-073-11/+12
| | | | | | | | | | | getSymbolValue now returns a value that in convenient for most callers: * 0 for undefined * symbol size for common symbols * offset/address for symbols the rest Code that needs something more specific can check getSymbolFlags. llvm-svn: 241605
* Common symbols don't have a value.Rafael Espindola2015-07-071-3/+2
| | | | | | | | | | | | | At least not in the interface exposed by ObjectFile. This matches what ELF and COFF implement. Adjust existing code that was expecting them to have values. No overall functionality change intended. Another option would be to change the interface and the ELF and COFF implementations to say that the value of a common symbol is its size. llvm-svn: 241593
* Common symbols are not undefined, at least for ObjectFile.Rafael Espindola2015-07-071-3/+2
| | | | | | | | | They are implemented like that in some object formats, but for the interface provided by lib/Object, SF_Undefined and SF_Common are different things. This matches the ELF and COFF implementation and fixes llvm-nm for MachO. llvm-svn: 241587
* Simplify, NFC.Rafael Espindola2015-07-071-3/+2
| | | | | | | | In these two contexts we really just want the raw n_value. No need to use getSymbolValue which checks for special cases where, semantically, the symbol has no value. llvm-svn: 241584
* Remove getRelocationAddress.Rafael Espindola2015-07-063-20/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally added in r139314. Back then it didn't actually get the address, it got whatever value the relocation used: address or offset. The values in different object formats are: * MachO: Always an offset. * COFF: Always an address, but when talking about the virtual address of sections it says: "for simplicity, compilers should set this to zero". * ELF: An offset for .o files and and address for .so files. In the case of the .so, the relocation in not linked to any section (sh_info is 0). We can't really compute an offset. Some API mappings would be: * Use getAddress for everything. It would be quite cumbersome. To compute the address elf has to follow sh_info, which can be corrupted and therefore the method has to return an ErrorOr. The address of the section is also the same for every relocation in a section, so we shouldn't have to check the error and fetch the value for every relocation. * Use a getValue and make it up to the user to know what it is getting. * Use a getOffset and: * Assert for dynamic ELF objects. That is a very peculiar case and it is probably fair to ask any tool that wants to support it to use ELF.h. The only tool we have that reads those (llvm-readobj) already does that. The only other use case I can think of is a dynamic linker. * Check that COFF .obj files have sections with zero virtual address spaces. If it turns out that some assembler/compiler produces these, we can change COFFObjectFile::getRelocationOffset to subtract it. Given COFF format, this can be done without the need for ErrorOr. The getRelocationAddress method was never implemented for COFF. It also had exactly one use in a very peculiar case: a shortcut for adding the section value to a pcrel reloc on MachO. Given that, I don't expect that there is any use out there of the C API. If that is not the case, let me know and I will add it back with the implementation inlined and do a proper deprecation. llvm-svn: 241450
* Check that COFF .obj files have sections with zero virtual address spaces.Rafael Espindola2015-07-061-0/+2
| | | | | | | | | | | | | When talking about the virtual address of sections the coff spec says: ... for simplicity, compilers should set this to zero. Otherwise, it is an arbitrary value that is subtracted from offsets during relocation. We don't currently subtract it, so check that it is zero. If some producer does create such files, we can change getRelocationOffset instead. llvm-svn: 241447
* Object/COFF: Do not rely on VirtualSize being 0 in object files.Rui Ueyama2015-07-041-8/+4
| | | | llvm-svn: 241387
* [ELFYAML] Fix handling SHT_NOBITS sections by obj2yaml/yaml2obj toolsSimon Atanasyan2015-07-031-0/+10
| | | | | | | | | | SHT_NOBITS sections do not have content in an object file. Now the yaml2obj tool does not accept `Content` field for such sections, and the obj2yaml tool does not attempt to read the section content from a file. Restore r241350 and r241352. llvm-svn: 241377
* Return ErrorOr from getSymbolAddress.Rafael Espindola2015-07-033-13/+10
| | | | | | | It can fail trying to get the section on ELF and COFF. This makes sure the error is handled. llvm-svn: 241366
* Use getValue instead of getAddress in a few MachO only cases.Rafael Espindola2015-07-031-5/+2
| | | | | | | In MachO the value of the symbol is always the address, so we can use the simpler function. llvm-svn: 241364
* This reverts commit r241350 and r241352.Rafael Espindola2015-07-031-10/+0
| | | | | | | | | | | r241350 broke lld tests. r241352 depends on r241350. Original messages: "[ELFYAML] Fix handling SHT_NOBITS sections by obj2yaml/yaml2obj tools" "[ELFYAML] Make the Size field for .bss section optional" llvm-svn: 241354
* [ELFYAML] Make the Size field for .bss section optionalSimon Atanasyan2015-07-031-1/+1
| | | | | | It's a common case to have a zero-size .bss section in an object file. llvm-svn: 241352
* [ELFYAML] Fix handling SHT_NOBITS sections by obj2yaml/yaml2obj toolsSimon Atanasyan2015-07-031-0/+10
| | | | | | | | SHT_NOBITS sections do not have content in an object file. Now yaml2obj tool does not accept `Content` field for such sections, and obj2yaml tool does not attempt to read the section content from a file. llvm-svn: 241350
* Return ErrorOr from SymbolRef::getName.Rafael Espindola2015-07-024-14/+15
| | | | | | | | | | | | This function can really fail since the string table offset can be out of bounds. Using ErrorOr makes sure the error is checked. Hopefully a lot of the boilerplate code in tools/* can go away once we have a diagnostic manager in Object. llvm-svn: 241297
* Return ErrorOr from getSection.Rafael Espindola2015-07-011-0/+2
| | | | | | | | | | | | | | This also improves the logic of what is an error: * getSection(uint_32): only return an error if the index is out of bounds. The index 0 corresponds to a perfectly valid entry. * getSection(Elf_Sym): Returns null for symbols that normally don't have sections and error for out of bound indexes. In many places this just moves the report_fatal_error up the stack, but those can then be fixed in smaller patches. llvm-svn: 241156
* Use ErrorOr in getRelocationAdress.Rafael Espindola2015-06-303-10/+7
| | | | | | | We can probably do better in this method, but this is an improvement and enables further ErrorOr cleanups. llvm-svn: 241114
* Implement containsSymbol with other lower level methods.Rafael Espindola2015-06-303-23/+7
| | | | llvm-svn: 241112
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-303-11/+5
| | | | llvm-svn: 241042
* Move function to the only file that uses it.Rafael Espindola2015-06-301-24/+0
| | | | llvm-svn: 241040
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-301-7/+5
| | | | llvm-svn: 241039
* Don't return error_code from a function that doesn't fail.Rafael Espindola2015-06-303-18/+8
| | | | llvm-svn: 241033
* Object/COFF: Define coff_symbol_generic.Rui Ueyama2015-06-301-6/+10
| | | | | | | | | | | | | | If you only need Name and Value fields in the COFF symbol, you don't need to distinguish 32 bit and 64 bit COFF symbols. These fields start at the same offsets and have the same size. This data strucutre is one pointer smaller than COFFSymbolRef thus slightly efficient. I'll use this class in LLD as we create millions of LLD symbol objects that currently contain COFFSymbolRef. Shaving off 8 byte (or 4 byte on 32 bit) from that class actually matters becasue of the number of objects we create in LLD. llvm-svn: 241024
* Don't return error_code from function that never fails.Rafael Espindola2015-06-293-18/+6
| | | | llvm-svn: 241021
* [SymbolSize] Skip sorting by index, just assign by index.Benjamin Kramer2015-06-291-7/+3
| | | | | | No functional change intended. llvm-svn: 240961
* Factor out the checking of string tables.Rafael Espindola2015-06-291-0/+2
| | | | | | | | | | This moves the error checking for string tables to getStringTable which returns an ErrorOr<StringRef>. This improves error checking, makes it uniform across all string tables and makes it possible to check them once instead of once per name. llvm-svn: 240950
* Simplify getSymbolType.Rafael Espindola2015-06-262-43/+26
| | | | | | | | This is still a really odd function. Most calls are in object format specific contexts and should probably be replaced with a more direct query, but at least now this is not too obnoxious to use. llvm-svn: 240777
* Add an ELFSymbolRef type.Rafael Espindola2015-06-251-2/+2
| | | | | | | This allows user code to say Sym.getSize() instead of having to manually fetch the object. llvm-svn: 240708
* Use computeSymbolSizes in llvm-symbolize.Rafael Espindola2015-06-251-1/+4
| | | | llvm-svn: 240646
* libObject/COFF: Add a function to get pointers to relocation entries.Rui Ueyama2015-06-251-0/+10
| | | | llvm-svn: 240610
* Make computeSymbolSizes never fail.Rafael Espindola2015-06-243-15/+45
| | | | | | | | | | | On ELF that was already the case since getting the size of a symbol never fails. On MachO and COFF we could fail trying to get the section of a symbol. But we don't really need the section, just the section number to know if two symbols are in the same section or not. llvm-svn: 240580
* Use Symbol::getValue to simplify object::computeSymbolSizes. NFC.Rafael Espindola2015-06-241-4/+2
| | | | llvm-svn: 240575
* Add a SymbolRef::getValue.Rafael Espindola2015-06-242-17/+24
| | | | | | | | | This returns either the symbol offset or address. Since it is not defined which one, it never has to lookup the section and so never fails. I will add users in the next commit. llvm-svn: 240569
* Refactor duplicated code. NFC.Rafael Espindola2015-06-241-27/+19
| | | | llvm-svn: 240563
* Simplify the logic, NFC.Rafael Espindola2015-06-241-12/+8
| | | | llvm-svn: 240554
* Change how symbol sizes are handled in lib/Object.Rafael Espindola2015-06-244-20/+13
| | | | | | | | | | | | | | COFF and MachO only define symbol sizes for common symbols. Reflect that in the class hierarchy by having a method for common symbols only in the base and a general one in ELF. This avoids the need of using a magic value for the size, which had a few problems * Most callers didn't check for it. * The ones that did could not tell the magic value from a file actually having that value. llvm-svn: 240529
* Revert "[FaultMaps] Move FaultMapParser to Object/"Sanjoy Das2015-06-232-62/+0
| | | | | | | This reverts commit r240364 (git c49542e5bb186). The issue r240364 was trying to fix was fixed independently in r240362. llvm-svn: 240448
* Make helper functions static. NFC.Benjamin Kramer2015-06-231-1/+1
| | | | llvm-svn: 240416
* Simplify the Mangler interface now that DataLayout is mandatory.Rafael Espindola2015-06-231-3/+1
| | | | | | | We only need to pass in a DataLayout when mangling a raw string, not when constructing the mangler. llvm-svn: 240405
* Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC)Alexander Kornienko2015-06-233-6/+6
| | | | | | Apparently, the style needs to be agreed upon first. llvm-svn: 240390
* Handle multiple symbols having the same address.Rafael Espindola2015-06-231-1/+9
| | | | | | I will add an explicit test in a second, but this fixes the bots. llvm-svn: 240372
* Extract an utility for computing symbol sizes on MachO and COFF.Rafael Espindola2015-06-232-0/+89
| | | | | | I will add a second user in the next commit. llvm-svn: 240366
* [FaultMaps] Move FaultMapParser to Object/Sanjoy Das2015-06-232-0/+62
| | | | | | | | | | | | | | | | | | Summary: That way llvm-objdump can rely on it without adding an extra dependency on CodeGen. This change duplicates the FaultKind enum and the code that serializes it to a string. I could not figure out a way to get around this without adding a new dependency to Object Reviewers: rafael, ab Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10619 llvm-svn: 240364
* [Object] Search for architecures by name in ↵Frederic Riss2015-06-221-16/+4
| | | | | | | | | | | | | | | | | | | | | | | | MachOUniversalBinary::getObjectForArch() The reason we need to search by name rather than by Triple::ArchType is to handle subarchitecture correclty. There is no different ArchType for the x86_64h architecture (it identifies itself as x86_64), or for the various ARM subarches. The only way to get to the subarch slice in an universal binary is to search by name. This issue led to hard to debug and transient symbolication failures in Asan tests (it mostly works, because the files are very similar). This also affects the Profiling infrastucture as it is the other user of that API. Reviewers: samsonov, bogner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10604 llvm-svn: 240339
* Make getRelocationSection MachO only.Rafael Espindola2015-06-191-13/+0
| | | | | | | | | | | | | | There are 3 types of relocations on MachO * Scattered * Section based * Symbol based On ELF and COFF relocations are symbol based. We were in the strange situation that we abstracted over two of them. This makes section based relocations MachO only. llvm-svn: 240149
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-193-6/+6
| | | | | | | | | | | | | The patch is generated using this command: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ llvm/lib/ Thanks to Eugene Kosov for the original patch! llvm-svn: 240137
* Fix the build.Rafael Espindola2015-06-191-1/+1
| | | | | | Sorry, I have no idea how grep failed to find this. llvm-svn: 240133
* Improve the --expand-relocs handling of MachO.Rafael Espindola2015-06-181-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In a relocation target can take 3 basic forms * A r_value in scattered relocations. * A symbol in external relocations. * A section is non-external relocations. Have the dump reflect that. With this change we go from CHECK-NEXT: Extern: 0 CHECK-NEXT: Type: X86_64_RELOC_SUBTRACTOR (5) CHECK-NEXT: Symbol: 0x2 CHECK-NEXT: Scattered: 0 To just // CHECK-NEXT: Type: X86_64_RELOC_SUBTRACTOR (5) // CHECK-NEXT: Section: __data (2) Since the relocation is with a section, we print the seciton name and don't need to say that it is not scattered or external. Someone motivated can add further special cases for things like ARM64_RELOC_ADDEND and ARM_RELOC_PAIR. llvm-svn: 240073
OpenPOWER on IntegriCloud