Commit Graph

458 Commits

Author SHA1 Message Date
Rafael Espindola c3f9b5a534 Make ObjectFile and BitcodeReader always own the MemoryBuffer.
This allows us to just use a std::unique_ptr to store the pointer to the buffer.
The flip side is that they have to support releasing the buffer back to the
caller.

Overall this looks like a more efficient and less brittle api.

llvm-svn: 211542
2014-06-23 21:53:12 +00:00
Rafael Espindola 4f7932b2fe Convert a few methods to use ErrorOr.
It used to be inconvenient to mix ErrorOr and UniquePtr, but with c++11
they work OK together.

llvm-svn: 211532
2014-06-23 20:41:02 +00:00
Kevin Enderby 4eff6cdd2e Fix a warning about the use of const being ignored with a cast.
llvm-svn: 211383
2014-06-20 18:07:34 +00:00
Kevin Enderby 1983fcf86c Change the output of llvm-nm and llvm-size for Mach-O universal files (aka
fat files) to print “ (for architecture XYZ)” for fat files with more than
one architecture to be like what the darwin tools do for fat files.

Also clean up the Mach-O printing of archive membernames in llvm-nm to use
the darwin form of "libx.a(foo.o)".

llvm-svn: 211316
2014-06-19 22:03:18 +00:00
Kevin Enderby 4b8fc281d4 Teach llvm-size to know about Mach-O universal files (aka fat files) and
fat files containing archives.

Also fix a bug in MachOUniversalBinary::ObjectForArch::ObjectForArch()
where it needed a >= when comparing the Index with the number of
objects in a fat file.  As the index starts at 0.

llvm-svn: 211230
2014-06-18 22:04:40 +00:00
Rafael Espindola 8af5cb2c28 Change IRObjectFile to parse the bitcode lazily.
The main point of this class is to provide a cheap object interface to a bitcode
file, so it has to be as lazy as possible.

llvm-svn: 211207
2014-06-18 19:05:24 +00:00
Rafael Espindola 24d8b84838 Fix a memory leak in the error path.
llvm-svn: 211184
2014-06-18 17:07:15 +00:00
Rafael Espindola 95cf2f25fe Fix pr17056.
This makes llvm-nm ignore members that are not sufficiently aligned for
lib/Object to handle.

These archives are invalid. GNU AR is able to handle this, but in general
just warns about broken archive members.

We should probably start warning too, but for now just make sure llvm-nm
exits with an 0.

llvm-svn: 211036
2014-06-16 16:41:00 +00:00
Rafael Espindola ae460027a4 Convert the Archive API to use ErrorOr.
Now that we have c++11, even things like ErrorOr<std::unique_ptr<...>> are
easy to use.

No intended functionality change.

llvm-svn: 211033
2014-06-16 16:08:36 +00:00
Artyom Skrobov c7b4253cfb Replacing the private implementations of SwapValue with calls to sys::swapByteOrder()
llvm-svn: 210980
2014-06-14 13:49:57 +00:00
Artyom Skrobov ef5e867f16 Renaming SwapByteOrder() to getSwappedBytes()
The next commit will add swapByteOrder(), acting in-place

llvm-svn: 210973
2014-06-14 11:36:01 +00:00
Rafael Espindola 54f1997979 Remove unused and odd code.
This code was never being used and any use of it would look fairly strange.
For example, it would try to map a object_error::parse_failed to
std::errc::invalid_argument.

llvm-svn: 210912
2014-06-13 15:36:17 +00:00
Rafael Espindola db4ed0bdab Remove 'using std::errro_code' from lib.
llvm-svn: 210871
2014-06-13 02:24:39 +00:00
Rafael Espindola 3acea39853 Don't use 'using std::error_code' in include/llvm.
This should make sure that most new uses use the std prefix.

llvm-svn: 210835
2014-06-12 21:46:39 +00:00
Rafael Espindola a6e9c3e43a Remove system_error.h.
This is a minimal change to remove the header. I will remove the occurrences
of "using std::error_code" in a followup patch.

llvm-svn: 210803
2014-06-12 17:38:55 +00:00
Rafael Espindola 25188c95de Don't import error_category into the llvm namespace.
llvm-svn: 210733
2014-06-12 01:45:43 +00:00
Rafael Espindola acc5d7c911 Don't import error_condition into the llvm namespace.
llvm-svn: 210731
2014-06-12 01:29:42 +00:00
Rafael Espindola 5c4f829424 Use std::error_code instead of llvm::error_code.
The idea of this patch is to turn llvm/Support/system_error.h into a
transitional header that just brings in the erorr_code api to the llvm
namespace. I will remove it shortly afterwards.

The cases where the general idea needed some tweaking:

* std::errc is a namespace in msvc, so we cannot use "using std::errc". I could
add an #ifdef, but there were not that many uses, so I just added std:: to
them in this patch.

* Template specialization had to be moved to the std namespace in this
patch set already.

* The msvc implementation of default_error_condition doesn't seem to
provide the same transformations as we need. Not too surprising since
the standard doesn't actually say what "equivalent" means. I fixed the
problem by keeping our old mapping and using it at error_code
construction time.

Despite these shortcomings I think this is still a good thing. Some reasons:

* The different implementations of system_error might improve over time.
* It removes 925 lines of code from llvm already.
* It removes 6313 bytes from the text segment of the clang binary when
it is built with gcc and 2816 bytes when building with clang and
libstdc++.

llvm-svn: 210687
2014-06-11 19:05:50 +00:00
Rafael Espindola f5d07fa586 Mark a few functions noexcept.
This reduces the difference between std::error_code and llvm::error_code.

llvm-svn: 210591
2014-06-10 21:26:47 +00:00
Simon Atanasyan 65e6467e69 [yaml2obj][obj2yaml] Support ELF symbol's visibility flags (default/hidden/protected).
llvm-svn: 210316
2014-06-06 07:41:57 +00:00
Kevin Enderby 980b25840f Add "-format darwin" to llvm-nm to be like darwin's nm(1) -m output.
This is a first step in seeing if it is possible to make llvm-nm produce
the same output as darwin's nm(1).  Darwin's default format is bsd but its
-m output prints the longer Mach-O specific details.  For now I added the
"-format darwin" to do this (whos name may need to change in the future).
As there are other Mach-O specific flags to nm(1) which I'm hoping to add some
how in the future.  But I wanted to see if I could get the correct output for
-m flag using llvm-nm and the libObject interfaces.

I got this working but would love to hear what others think about this approach
to getting object/format specific details printed with llvm-nm.

llvm-svn: 210285
2014-06-05 21:21:57 +00:00
Rafael Espindola e00fec8fe4 Use an enum class.
llvm-svn: 210078
2014-06-03 05:26:12 +00:00
Rafael Espindola a3f2e3f01e There is no std::errc::success, remove the llvm one.
llvm-svn: 209960
2014-05-31 03:21:04 +00:00
Rafael Espindola 03bddfee47 Use error_code() instead of error_code::succes()
There is no std::error_code::success, so this removes much of the noise
in transitioning to std::error_code.

llvm-svn: 209952
2014-05-31 01:37:45 +00:00
Tim Northover eaef074d45 MachO: support N_INDR aliases in assembly files.
This makes LLVM create N_INDR aliases (to be resolved by the linker) when
appropriate.

rdar://problem/15125513

llvm-svn: 209894
2014-05-30 13:22:59 +00:00
Simon Atanasyan 8745993ec4 [elf2yaml][ELF] Move Info field to the RelocationSection structure. This
field represents ELF section header sh_info field and does not have any
sense for regular sections. Its interpretation depends on section type.

llvm-svn: 209801
2014-05-29 11:05:31 +00:00
Simon Atanasyan 84242dc774 [YAML] Add an optional argument `EnumMask` to the `yaml::IO::bitSetCase()`.
Some bit-set fields used in ELF file headers in fact contain two parts.
The first one is a regular bit-field. The second one is an enumeraion.
For example ELF header `e_flags` for MIPS target might contain the
following values:

Bit-set values:

  EF_MIPS_NOREORDER = 0x00000001
  EF_MIPS_PIC       = 0x00000002
  EF_MIPS_CPIC      = 0x00000004
  EF_MIPS_ABI2      = 0x00000020

Enumeration:

  EF_MIPS_ARCH_32   = 0x50000000
  EF_MIPS_ARCH_64   = 0x60000000
  EF_MIPS_ARCH_32R2 = 0x70000000
  EF_MIPS_ARCH_64R2 = 0x80000000

For printing bit-sets we use the `yaml::IO::bitSetCase()`. It does not
support bit-set/enumeration combinations and prints too many flags from
an enumeration part. This patch fixes this problem. New method
`yaml::IO::maskedBitSetCase()` handle "enumeration" part of bitset
defined by provided mask.

Patch reviewed by Nick Kledzik and Sean Silva.

llvm-svn: 209504
2014-05-23 08:07:09 +00:00
Kevin Enderby 1b985af0ba Update MachOObjectFile::getSymbolAddress so it returns UnknownAddressOrSize
for undefined symbols, so it matches what COFFObjectFile::getSymbolAddress
does.  This allows llvm-nm to print spaces instead of 0’s for the value
of undefined symbols in Mach-O files.

To make this change other uses of MachOObjectFile::getSymbolAddress
are updated to handle when the Value is returned as UnknownAddressOrSize.
Which is needed to keep two of the ExecutionEngine tests working for example.

llvm-svn: 209253
2014-05-20 23:04:47 +00:00
Kevin Enderby fcbed5af67 Revert r209235 as it broke two tests:
Failing Tests (2):
	    LLVM :: ExecutionEngine/MCJIT/stubs-sm-pic.ll
	    LLVM :: ExecutionEngine/MCJIT/stubs.ll

llvm-svn: 209236
2014-05-20 21:10:15 +00:00
Kevin Enderby 1126d02c0c Update MachOObjectFile::getSymbolAddress so it returns UnknownAddressOrSize
for undefined symbols.  Allowing llvm-nm to print spaces instead of 0’s for
the value of undefined symbols in Mach-O files.

llvm-svn: 209235
2014-05-20 20:32:18 +00:00
Simon Atanasyan 9cb4090867 [Mips] Add more relocation types and MIPS specific e_flags constants.
llvm-svn: 209201
2014-05-20 09:27:49 +00:00
Kevin Enderby 403258f5a3 Implement MachOObjectFile::isSectionData() and MachOObjectFile::isSectionBSS
so that llvm-size will total up all the sections in the Berkeley format.  This
allows for rough categorizations for Mach-O sections.  And allows the total of
llvm-size’s Berkeley and System V formats to be the same.

llvm-svn: 209158
2014-05-19 20:36:02 +00:00
Craig Topper b816593cf0 Remove last uses of OwningPtr from llvm. As far as I can tell these method versions are not used by lldb, lld, or clang.
llvm-svn: 209103
2014-05-18 21:55:38 +00:00
Simon Atanasyan b83f380ae4 [yaml2obj][ELF] Add an optional `Size` field to the YAML section declaration.
Now the only method to configure ELF section's content and size is to assign
a hexadecimal string to the `Content` field. Unfortunately this way is
completely useless when you need to declare a really large section.

To solve this problem this patch adds one more optional field `Size`
to the `RawContentSection` structure. When yaml2obj generates an ELF file
it uses the following algorithm:
1. If both `Content` and `Size` fields are missed create an empty section.
2. If only `Content` field is missed take section length from the `Size`
   field and fill the section by zero.
3. If only `Size` field is missed create a section using data from
   the `Content` field.
4. If both `Content` and `Size` fields are provided validate that the `Size`
   value is not less than size of `Content` data. Than take section length
   from the `Size`, fill beginning of the section by `Content` and the rest
   by zero.

Examples
--------
* Create a section 0x10000 bytes long filled by zero
  Name: .data
  Type: SHT_PROGBITS
  Flags: [ SHF_ALLOC ]
  Size: 0x10000

* Create a section 0x10000 bytes long starting from 'CA' 'FE' 'BA' 'BE'
  Name: .data
  Type: SHT_PROGBITS
  Flags: [ SHF_ALLOC ]
  Content: CAFEBABE
  Size: 0x10000

The patch reviewed by Michael Spencer.

llvm-svn: 208995
2014-05-16 16:01:00 +00:00
Simon Atanasyan 8d59c8da41 [obj2yaml][ELF] Do not print empty Link and Info fields for ELF sections.
llvm-svn: 208905
2014-05-15 18:04:02 +00:00
Kevin Enderby e858a65323 Teach llvm-nm to know about fat archives (aka MachOUniversal files
containing archives).  First step as other tools will be updated next.

llvm-svn: 208812
2014-05-14 21:18:50 +00:00
Simon Atanasyan ae6bb33ac2 [obj2yaml] Support ELF input format in the obj2yaml tool.
The ELF header e_flags field in the MIPS related test cases handled
incorrectly. The obj2yaml prints too many flags. I will fix that in the
next patches.

The patch reviewed by Michael Spencer and Sean Silva.

llvm-svn: 208752
2014-05-14 05:07:47 +00:00
Lang Hames 36072da3d9 [RuntimeDyld] Add support for MachO __jump_table and __pointers sections, and
SECTDIFF relocations on 32-bit x86.

This fixes several of the MCJIT regression test failures that show up on 32-bit
builds.

<rdar://problem/16886294>

llvm-svn: 208635
2014-05-12 21:39:59 +00:00
Simon Atanasyan 68f6150156 [yaml2obj] Support ELF x86 relocations.
llvm-svn: 208228
2014-05-07 17:06:38 +00:00
Simon Atanasyan 1e3edf98cb [ELFYAML] Group ELF header falgs to target specific blocks. Handle flags
which are corresponding to the current target read from the ELF file.

This fix cannot be tested until obj2yaml does not support ELF format.

llvm-svn: 207905
2014-05-03 11:39:50 +00:00
Simon Atanasyan 9a922c4ffd [ELFYAML] Add more SHT_xxx flags to the YAML section type mapping.
llvm-svn: 207904
2014-05-03 11:39:44 +00:00
Hans Wennborg 83e6e1e926 ELFObjectWriter: deduplicate suffices in strtab
We already do this for shstrtab, so might as well do it for strtab. This
extracts the string table building code into a separate class. The idea
is to use it for other object formats too.

I mostly wanted to do this for the general principle, but it does save a
little bit on object file size. I tried this on a clang bootstrap and
saved 0.54% on the sum of object file sizes (1.14 MB out of 212 MB for
a release build).

Differential Revision: http://reviews.llvm.org/D3533

llvm-svn: 207670
2014-04-30 16:25:02 +00:00
Benjamin Kramer d59664f4f7 raw_ostream: Forward declare OpenFlags and include FileSystem.h only where necessary.
llvm-svn: 207593
2014-04-29 23:26:49 +00:00
Simon Atanasyan eb08c4f038 [yaml2obj][ELF] Remove unnecessary space between namespace name and
colons.

llvm-svn: 207003
2014-04-23 17:30:29 +00:00
Simon Atanasyan 62fce0a975 [yaml2obj][ELF] Add a virtual destructor to the ELFYAML::Section class
to prevent memory leaks.

llvm-svn: 206969
2014-04-23 11:10:55 +00:00
Rafael Espindola 6956b1a517 Convert getFileOffset to getOffset and move it to its only user.
We normally don't drop functions from the C API's, but in this case I think we
can:

* The old implementation of getFileOffset was fairly broken
* The introduction of LLVMGetSymbolFileOffset was itself a C api breaking
  change as it removed LLVMGetSymbolOffset.
* It is an incredibly specialized use case. The only reason MCJIT needs it is
  because of its odd position of being a dynamic linker of .o files.

llvm-svn: 206750
2014-04-21 13:45:32 +00:00
Craig Topper 2617dccea2 [C++11] More 'nullptr' conversion. In some cases just using a boolean check instead of comparing to nullptr.
llvm-svn: 206252
2014-04-15 06:32:26 +00:00
Simon Atanasyan 42ac0dd3c3 [yaml2obj][ELF] ELF Relocations Support.
The patch implements support for both relocation record formats: Elf_Rel
and Elf_Rela. It is possible to define relocation against symbol only.
Relocations against sections will be implemented later. Now yaml2obj
recognizes X86_64, MIPS and Hexagon relocation types.

Example of relocation section specification:
Sections:
- Name: .text
  Type: SHT_PROGBITS
  Content: "0000000000000000"
  AddressAlign: 16
  Flags: [SHF_ALLOC]

- Name: .rel.text
  Type: SHT_REL
  Info: .text
  AddressAlign: 4
  Relocations:
    - Offset: 0x1
      Symbol: glob1
      Type: R_MIPS_32
    - Offset: 0x2
      Symbol: glob2
      Type: R_MIPS_CALL16

The patch reviewed by Michael Spencer, Sean Silva, Shankar Easwaran.

llvm-svn: 206017
2014-04-11 04:13:39 +00:00
NAKAMURA Takumi 554c287262 LLVMBuild.txt: Add missing dependencies.
llvm-svn: 205962
2014-04-10 11:16:47 +00:00
NAKAMURA Takumi 98905d3f85 LLVMBuild.txt: Reformat.
llvm-svn: 205961
2014-04-10 11:16:17 +00:00