Commit Graph

648 Commits

Author SHA1 Message Date
Rafael Espindola
df3edb6d36 Return ErrorOr from getSection.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241156 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 12:56:27 +00:00
Rafael Espindola
28a83187a2 Use ErrorOr in getRelocationAdress.
We can probably do better in this method, but this is an improvement and
enables further ErrorOr cleanups.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241114 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 20:32:26 +00:00
Rafael Espindola
d231306ba8 Implement containsSymbol with other lower level methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241112 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 20:18:49 +00:00
Rafael Espindola
4a04da337e Remove Elf_Shdr_Iter. Diagnose files with invalid section header sizes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241109 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 19:58:10 +00:00
Rafael Espindola
28bec63a7e Fix the name of the iterator functions to match the coding standards.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241074 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 15:33:44 +00:00
Rafael Espindola
e8ff062325 Report an error on invalid sh_entsize.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241070 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 14:59:20 +00:00
NAKAMURA Takumi
d6751a82b3 ELF.h: Prune obsolete comments removed in r240996. [-Wdocumentation]
FIXME: Should they be moved onto Elf_Sym_Impl::getNmae()?

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241044 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 05:59:13 +00:00
Rafael Espindola
f8a35ff558 Don't return error_code from a function that doesn't fail.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241042 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 04:08:37 +00:00
Rafael Espindola
09912eb9ec Move function to the only file that uses it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241040 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 03:41:26 +00:00
Rafael Espindola
9f2f3bba2b Don't return error_code from a function that doesn't fail.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241039 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 03:33:18 +00:00
Rafael Espindola
7ede9649c1 Don't return error_code from a function that doesn't fail.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241033 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 01:53:01 +00:00
Rafael Espindola
de4d844704 Cleanup getRelocationAddend.
Realistically, this will be returning ErrorOr for some time as refactoring the
user code to check once per section will take some time.

Given that, use it for checking if a relocation has addend or not.

While at it, add ELFRelocationRef to simplify the users.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241028 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 00:33:59 +00:00
Rui Ueyama
13b58ec74a Object/COFF: Define coff_symbol_generic.
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.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241024 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 00:03:56 +00:00
Rafael Espindola
2edab1ac31 Use asserts for checks that should never fail.
If a section is not SHT_REL or SHT_RELA, we never create a valid iterator,
so the getRelocation* methods should always see a section with the correct type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241023 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 23:55:05 +00:00
Rafael Espindola
ff67629985 Don't return error_code from function that never fails.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241021 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 23:29:12 +00:00
Rafael Espindola
3d176ae165 Convert obj->getSymbolName to sym->getName.
I doesn't depend on the object anymore.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240996 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 21:24:55 +00:00
Rafael Espindola
9a6c902332 Factor out the checking of string tables.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240950 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 14:39:25 +00:00
Rafael Espindola
db89b93b44 Convert an assert that can fail into error checking.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240944 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 14:02:24 +00:00
Rafael Espindola
e8f07a7eb3 Remove Elf_Sym_Iter.
It was a fairly broken concept for an ELF only class.

An ELF file can have two symbol tables, but they have exactly the same
format. There is no concept of a dynamic or a static symbol. Storing this
on the iterator also makes us do more work per symbol than necessary. To fetch
a name we would:

* Find if we had a static or a dynamic symbol.
* Look at the corresponding symbol table and find the string table section.
* Look at the string table section to fetch its contents.
* Compute the name as a substring of the string table.

All but the last step can be done per symbol table instead of per symbol. This
is a step in that direction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240939 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 12:38:31 +00:00
Lang Hames
63f4054f8e [StackMaps] Add a lightweight parser for stackmap version 1 sections.
The parser provides a convenient interface for reading llvm stackmap v1 sections
in object files.

This patch also includes a new option for llvm-readobj, '-stackmap', which uses
the parser to pretty-print stackmap sections for debugging/testing purposes.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240860 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 23:56:53 +00:00
Rafael Espindola
aaaa38cb95 Fix error handling in getString and simplify callers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240810 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 18:42:17 +00:00
Rafael Espindola
b82800d00e Delete dead code. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240807 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 18:32:53 +00:00
Rafael Espindola
b65669cdde ELF: Simplify the rel/rela implementation.
Now the rela class inherits from rel and just adds the addend.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240790 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 15:27:04 +00:00
Rafael Espindola
ea767137b6 Rename getObjectFile to getObject for consistency.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240785 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 14:51:16 +00:00
Rafael Espindola
37c948ae79 Implement elf_section_iterator and getELFType().
And with those, simplify getSymbolNMTypeChar.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240780 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 13:11:15 +00:00
Rafael Espindola
5add4ddba8 Expose getFlags via ELFSectionRef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240779 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 12:44:10 +00:00
Rafael Espindola
db7a9f12bc Add a ELFSectionRef class and use it to expose getSectionType.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240778 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 12:33:37 +00:00
Rafael Espindola
50bea40e8e Simplify getSymbolType.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240777 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 12:18:49 +00:00
Rafael Espindola
3e750a4ebf Make getOther ELF only.
No other format has this field.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240774 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 11:39:57 +00:00
Michael J. Spencer
d1ceba0333 [ELF] Move ELF{32,64}{L,B}E typedefs to llvm.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240731 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 23:41:23 +00:00
Michael J. Spencer
7358cbc837 [ELF] Add some accessors for lld.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240730 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 23:40:41 +00:00
Rafael Espindola
b24bbb73a7 Add an ELFSymbolRef type.
This allows user code to say Sym.getSize() instead of having to manually fetch
the object.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240708 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 22:10:04 +00:00
Michael J. Spencer
4cbb2db3ab [Object][ELF] Add support for dumping dynamic relocations when sections are stripped.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240703 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 21:47:32 +00:00
Rafael Espindola
0999c2c69c llvm-nm: Don't print mapping symbols.
This matches the behavior of gnu nm. Fixes pr23930.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240695 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 21:00:51 +00:00
Rafael Espindola
7a0f58b7f0 Use range loop. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240645 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 15:00:38 +00:00
Rafael Espindola
ca30411d98 Modernize getELFDynamicSymbolIterators.
* Have it return a iterator_range.
* Remove the global function.
* Rename to getDynamicSymbolIterators.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240644 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 14:39:35 +00:00
Rui Ueyama
7d6e44bde8 libObject/COFF: Add a function to get pointers to relocation entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240610 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 00:07:39 +00:00
Rafael Espindola
a3af347f38 Make computeSymbolSizes never fail.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240580 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-24 19:57:32 +00:00
Rafael Espindola
9fa0ab3335 Add a SymbolRef::getValue.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240569 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-24 19:11:10 +00:00
Rafael Espindola
262e948d2a Refactor duplicated code. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240563 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-24 18:14:41 +00:00
Rafael Espindola
1e6b8f552c Don't get confused with sections whose section number is reserved.
It is perfectly possible for SHNDX to contain indexes that have the same value
as reserved st_shndx values.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240544 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-24 14:48:54 +00:00
Rafael Espindola
821b06f3a8 Change how symbol sizes are handled in lib/Object.
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240529 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-24 10:20:30 +00:00
Rafael Espindola
9073b8fb67 Don't repeat name in comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240516 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-24 03:19:35 +00:00
Sanjoy Das
ef42e1115f Revert "[FaultMaps] Move FaultMapParser to Object/"
This reverts commit r240364 (git c49542e5bb).  The issue r240364 was
trying to fix was fixed independently in r240362.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240448 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23 20:09:03 +00:00
Alexander Kornienko
cd52a7a381 Revert r240137 (Fixed/added namespace ending comments using clang-tidy. NFC)
Apparently, the style needs to be agreed upon first.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240390 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23 09:49:53 +00:00
Rafael Espindola
9e7539a79f Remove broken banner.
Thanks to Filipe Cabecinhas for noticing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240375 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23 03:45:23 +00:00
Rafael Espindola
344dd6519e Extract an utility for computing symbol sizes on MachO and COFF.
I will add a second user in the next commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240366 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23 02:08:48 +00:00
Sanjoy Das
c49542e5bb [FaultMaps] Move FaultMapParser to Object/
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240364 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23 01:05:26 +00:00
Frederic Riss
11fcb49922 [Object] Search for architecures by name in 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240339 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-22 21:33:24 +00:00
Rui Ueyama
87ae2e8ab0 Object: Add load configuration structure for 64 bit PE/COFF.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240230 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-21 01:12:32 +00:00