Commit Graph

95 Commits

Author SHA1 Message Date
Benjamin Kramer f044d3f93b Make helper functions static.
Found by -Wmissing-prototypes. NFC.

llvm-svn: 231664
2015-03-09 16:23:46 +00:00
Shankar Easwaran 6fbbe20176 [obj2yaml/yaml2obj] Add SHT_GROUP support.
This adds section group support to the tools obj2yaml and yaml2obj.

llvm-svn: 230124
2015-02-21 04:28:26 +00:00
Simon Atanasyan 5d19c67a68 [ELFYAML] Support mips64 relocation record format in yaml2obj/obj2yaml
MIPS64 ELF file has a very specific relocation record format. Each
record might specify up to three relocation operations. So the `r_info`
field in fact consists of three relocation type sub-fields and optional
code of "special" symbols.

http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf
page 40

The patch implements support of the MIPS64 relocation record format in
yaml2obj/obj2yaml tools by introducing new optional Relocation fields:
Type2, Type3, and SpecSym. These fields are recognized only if the
object/YAML file relates to the MIPS64 target.

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

llvm-svn: 227044
2015-01-25 13:29:25 +00:00
Chandler Carruth d9903888d9 [cleanup] Re-sort all the #include lines in LLVM using
utils/sort_includes.py.

I clearly haven't done this in a while, so more changed than usual. This
even uncovered a missing include from the InstrProf library that I've
added. No functionality changed here, just mechanical cleanup of the
include order.

llvm-svn: 225974
2015-01-14 11:23:27 +00:00
David Blaikie 5106ce7897 Remove StringMap::GetOrCreateValue in favor of StringMap::insert
Having two ways to do this doesn't seem terribly helpful and
consistently using the insert version (which we already has) seems like
it'll make the code easier to understand to anyone working with standard
data structures. (I also updated many references to the Entry's
key and value to use first() and second instead of getKey{Data,Length,}
and get/setValue - for similar consistency)

Also removes the GetOrCreateValue functions so there's less surface area
to StringMap to fix/improve/change/accommodate move semantics, etc.

llvm-svn: 222319
2014-11-19 05:49:42 +00:00
David Majnemer 646f47f640 yaml2obj, COFF: Consider the DOS stub when laying out section headers
While this program worked correctly with small example programs, larger
ones tickled this bug.  I'm working on a reduction because my program is
quite large.

llvm-svn: 222078
2014-11-15 02:03:59 +00:00
David Majnemer 966064c949 yaml2obj, COFF: Correctly calculate SizeOfImage and SizeOfHeaders
SizeOfHeaders must be aligned to the FileAlignment.
SizeOfImage must be at least the SizeOfHeaders aligned to the
SectionAlignment.

llvm-svn: 222030
2014-11-14 19:35:59 +00:00
David Majnemer f69b0585c1 obj2yaml, yaml2obj: Add support for COFF executables
In support of serializing executables, obj2yaml now records the virtual address
and size of sections.  It also serializes whatever we strictly need from
the PE header, it expects that it can reconstitute everything else via
inference.

yaml2obj can reconstitute a fully linked executable.

In order to get executables correctly serialized/deserialized, other
bugs were fixed as a circumstance.  We now properly respect file and
section alignments.  We also avoid writing out string tables unless they
are strictly necessary.

llvm-svn: 221975
2014-11-14 08:15:42 +00:00
Simon Atanasyan 60e1a79242 [ELF][yaml2obj] Handle additional MIPS specific st_other field flags
The ELF symbol `st_other` field might contain additional flags besides
visibility ones. This patch implements support for some MIPS specific
flags.

llvm-svn: 221491
2014-11-06 22:46:24 +00:00
Aaron Ballman 4934e4b598 Fixing a -Wsign-compare warning; NFC.
I think it might make sense to make COFF::MaxNumberOfSections16 be a uint32_t, however, that may have wider-reaching implications in other projects, which is why I did not change that declaration.

llvm-svn: 220384
2014-10-22 13:09:43 +00:00
Hans Wennborg f26bfc1671 WinCOFFObjectWriter: optimize the string table for common suffices
This is a follow-up from r207670 which did the same for ELF.

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

llvm-svn: 218636
2014-09-29 22:43:20 +00:00
David Majnemer 2cbc13878f yaml2obj: Support bigobj
Teach yaml2obj how to make a bigobj COFF file.  Like the rest of LLVM,
we automatically decide whether or not to use regular COFF or bigobj
COFF on the fly depending on how many sections the resulting object
would have.

This ends the task of adding bigobj support to LLVM.

N.B. This was tested by forcing yaml2obj to be used in bigobj mode
regardless of the number of sections.  While a dedicated test was
written, the smallest I could make it was 36 MB (!) of yaml and it still
took a significant amount of time to execute on a powerful machine.

llvm-svn: 217858
2014-09-16 03:52:46 +00:00
David Majnemer 4d57159c09 MC: Add support for BigObj
Teach WinCOFFObjectWriter how to write -mbig-obj style object files;
these object files allow for more sections inside an object file.

Our support for BigObj is notably different from binutils and cl: we
implicitly upgrade object files to BigObj instead of asking the user to
compile the same file *again* but with another flag.  This matches up
with how LLVM treats ELF variants.

This was tested by forcing LLVM to always emit BigObj files and running
the entire test suite.  A specific test has also been added.

I've lowered the maximum number of sections in a normal COFF file,
VS "14" CTP 3 supports no more than 65279 sections.  This is important
otherwise we might not switch to BigObj quickly enough, leaving us with
a COFF file that we couldn't link.

yaml2obj support is all that remains to implement.

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

llvm-svn: 217812
2014-09-15 19:42:42 +00:00
Rafael Espindola 3fd1e9933f Modernize raw_fd_ostream's constructor a bit.
Take a StringRef instead of a "const char *".
Take a "std::error_code &" instead of a "std::string &" for error.

A create static method would be even better, but this patch is already a bit too
big.

llvm-svn: 216393
2014-08-25 18:16:47 +00:00
Benjamin Kramer a7c40ef022 Canonicalize header guards into a common format.
Add header guards to files that were missing guards. Remove #endif comments
as they don't seem common in LLVM (we can easily add them back if we decide
they're useful)

Changes made by clang-tidy with minor tweaks.

llvm-svn: 215558
2014-08-13 16:26:38 +00:00
Simon Atanasyan b5adb21240 Install the `obj2yaml` and `yaml2obj` utilities together with other LLVM tools.
llvm-svn: 214191
2014-07-29 18:28:16 +00:00
NAKAMURA Takumi 23b702c8de [CMake] Update libdeps.
llvm-svn: 212920
2014-07-14 05:01:53 +00:00
Rafael Espindola adf21f2a56 Update the MemoryBuffer API to use ErrorOr.
llvm-svn: 212405
2014-07-06 17:43:13 +00:00
Rafael Espindola 97de474a36 Invert the MC -> Object dependency.
Now that we have a lib/MC/MCAnalysis, the dependency was there just because
of two helper classes. Move the two over to MC.

This will allow IRObjectFile to parse inline assembly.

llvm-svn: 212248
2014-07-03 02:01: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
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
Simon Atanasyan f97af8a084 [yaml2obj] Add new command line option `-docnum`.
Input YAML file might contain multiple object file definitions.
New option `-docnum` allows to specify an ordinal number (starting from 1)
of definition used for an object file generation.

Patch reviewed by Sean Silva.

llvm-svn: 209967
2014-05-31 04:51:07 +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 73e047e54c [yaml2obj] Add "-o" command line option to specify an output file name.
llvm-svn: 208900
2014-05-15 16:14:02 +00:00
Hans Wennborg 59f0cba30f Use the new StringTableBuilder in yaml2elf
http://reviews.llvm.org/D3574

llvm-svn: 207694
2014-04-30 19:38:09 +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
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
Simon Atanasyan 35babf9c66 [yaml2obj][ELF] Rename class SectionNameToIdxMap => NameToIdxMap. It can
be used for indexing not only section's names.

No functional changes.

llvm-svn: 205687
2014-04-06 09:02:55 +00:00
Simon Atanasyan 3ee21b014b [yaml2obj][ELF] Convert some static functions into class members to
reduce number of arguments.

No functional changes.

llvm-svn: 205434
2014-04-02 16:34:54 +00:00
Simon Atanasyan ee7776d681 [yaml2obj][ELF] Remove unused typedef.
No functional changes.

llvm-svn: 205433
2014-04-02 16:34:48 +00:00
Simon Atanasyan 220c54a0e3 [yaml2obj][ELF] Move section index to the ELFState class.
No functional changes.

llvm-svn: 205432
2014-04-02 16:34:40 +00:00
Simon Atanasyan ee882239cb [yaml2obj][ELF] Remove relationship between ELFState
and ContiguousBlobAccumulator classes. Pass ContiguousBlobAccumulator to
the handleSymtabSectionHeader function directly.

No functional changes.

llvm-svn: 205431
2014-04-02 16:34:34 +00:00
Daniel Sanders 9cf3d3b764 [yaml2obj] Add support for ELF e_flags.
Summary:
The FileHeader mapping now accepts an optional Flags sequence that accepts
the EF_<arch>_<flag> constants. When not given, Flags defaults to zero.

Reviewers: atanasyan

Reviewed By: atanasyan

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3213

llvm-svn: 205173
2014-03-31 09:44:05 +00:00
David Majnemer ddf28f2b79 Object: Provide a richer means of describing auxiliary symbols
The current state of affairs has auxiliary symbols described as a big
bag of bytes. This is less than satisfying, it detracts from the YAML
file as being human readable.

Instead, allow for symbols to optionally contain their auxiliary data.
This allows us to have a much higher level way of describing things like
weak symbols, function definitions and section definitions.

This depends on D3105.

Differential Revision: http://llvm-reviews.chandlerc.com/D3092

llvm-svn: 204214
2014-03-19 04:47:47 +00:00
Simon Atanasyan 048baca082 [yaml2obj][ELF] Use range-based for loops.
llvm-svn: 203900
2014-03-14 06:53:30 +00:00
Simon Atanasyan 4d70d2a54a [yaml2obj][ELF] Refer to a section in the error message by its name not
index.

llvm-svn: 203899
2014-03-14 06:53:25 +00:00
Simon Atanasyan 64dadc8981 [yaml2obj][ELF] Remove unused ELFState class field.
llvm-svn: 203898
2014-03-14 06:53:21 +00:00
Simon Atanasyan a3130a4bad [yaml2obj][ELF] Assign name (.shstrtab) to the section holds sections names.
llvm-svn: 203897
2014-03-14 06:53:16 +00:00
Ahmed Charles 56440fd820 Replace OwningPtr<T> with std::unique_ptr<T>.
This compiles with no changes to clang/lld/lldb with MSVC and includes
overloads to various functions which are used by those projects and llvm
which have OwningPtr's as parameters. This should allow out of tree
projects some time to move. There are also no changes to libs/Target,
which should help out of tree targets have time to move, if necessary.

llvm-svn: 203083
2014-03-06 05:51:42 +00:00
NAKAMURA Takumi bee5c53819 llvm/tools: Prune redundant target_link_libraries.
llvm-svn: 200559
2014-01-31 17:40:06 +00:00
NAKAMURA Takumi b5c4b87690 [CMake] Update LLVM_LINK_COMPONENTS for each CMakeLists.txt.
llvm-svn: 196908
2013-12-10 11:13:32 +00:00
Will Dietz 0b48c738e6 yaml2coff/elf: Touchup for compatibility.
* std::string::append(int, int) can be ambiguous.
* std::vector<>::data() is a C++11 feature, use ArrayRef abstraction.

llvm-svn: 192542
2013-10-12 21:29:16 +00:00
Michael J. Spencer 126973ba93 [Object] Split the ELF interface into 3 parts.
* ELFTypes.h contains template magic for defining types based on endianess, size, and alignment.
* ELFFile.h defines the ELFFile class which provides low level ELF specific access.
* ELFObjectFile.h contains ELFObjectFile which uses ELFFile to implement the ObjectFile interface.

llvm-svn: 188022
2013-08-08 22:27:13 +00:00
Sean Silva 8217757379 [yaml2obj][ELF] Make symbol table top-level key.
Although in reality the symbol table in ELF resides in a section, the
standard requires that there be no more than one SHT_SYMTAB. To enforce
this constraint, it is cleaner to group all the symbols under a
top-level `Symbols` key on the object file.

llvm-svn: 184627
2013-06-22 01:38:00 +00:00
Sean Silva 7a0c3a6fc4 [yaml2obj][ELF] Narrow parameter.
The full ELFYAML::Section isn't needed.

llvm-svn: 184626
2013-06-22 01:37:55 +00:00
Sean Silva 7d61722259 [yaml2obj][ELF] Don't special case writing these.
Just add them to the vector of section headers like the rest of the
section headers.

llvm-svn: 184624
2013-06-22 01:06:12 +00:00
Sean Silva 11caebaa32 [yaml2obj][ELF] Make this "type switch" actually readable.
llvm-svn: 184623
2013-06-22 01:03:35 +00:00
Sean Silva d93323f51d [yaml2obj][ELF] Align section contents in the output.
The improperly aligned section content in the output was causing
buildbot failures. This should fix them.

Incidentally, this results in a simpler and more robust API for
ContiguousBlobAccumulator.

llvm-svn: 184621
2013-06-22 00:47:43 +00:00
Sean Silva c4afa6d7ae [yaml2obj][ELF] Allow expressing undefined symbols.
Previously we unconditionally enforced that section references in
symbols in the YAML had a name that was a section name present in the
object, and linked the references to that section. Now, permit empty
section names (already the default, if the `Section` key is not
provided) to indicate SHN_UNDEF.

llvm-svn: 184513
2013-06-21 01:11:48 +00:00
Sean Silva 37e817c8fc Unbreak bots. Didn't realize this was a C++11 feature.
llvm-svn: 184508
2013-06-21 00:33:01 +00:00