Commit Graph

299 Commits

Author SHA1 Message Date
Rafael Espindola 555099207b Find the symbol table on archives created on OS X.
llvm-svn: 186041
2013-07-10 22:07:59 +00:00
Rafael Espindola fbcafc0793 Don't crash in 'llvm -s' when an archive has no symtab.
llvm-svn: 186029
2013-07-10 20:14:22 +00:00
Rafael Espindola 8115e1da91 Add missing getters. They will be used in llvm-ar.
llvm-svn: 185937
2013-07-09 12:49:24 +00:00
Rafael Espindola 8e9385ec63 Archive members cannot be larger than 4GB. Return a uint32_t.
llvm-svn: 185936
2013-07-09 12:45:11 +00:00
Rafael Espindola 97ee9de652 Add getHeader helper and move ToHeader to the cpp file.
llvm-svn: 185933
2013-07-09 12:22:05 +00:00
Rafael Espindola 0f3de64ddf Compute the size of an archive member in the constructor.
It is always computed the same way (by parsing the header). Doing it in the
constructor simplifies the callers a bit.

llvm-svn: 185905
2013-07-09 05:26:25 +00:00
Rafael Espindola 747bc07bc3 Move some code out of line. No functionality change.
llvm-svn: 185901
2013-07-09 03:39:35 +00:00
Sean Silva 2f672d610e Make BinaryRef output correctly in case of empty data.
Previously, it would simply output nothing, but it should output an
empty string `""`.

llvm-svn: 185894
2013-07-09 00:54:46 +00:00
Sylvestre Ledru 751447a3ac Remove a useless declarations (found by scan-build)
llvm-svn: 185709
2013-07-05 15:58:12 +00:00
Rafael Espindola 6cc2dc713e Use the raw member names in Archive::Archive.
This a bit more efficient and avoids having a function that uses the string
table being called by a function that searches for it.

llvm-svn: 185680
2013-07-05 03:35:15 +00:00
Rafael Espindola 1cbed22836 Add support for archives with no symbol table or string table.
llvm-svn: 185664
2013-07-04 19:40:23 +00:00
Rafael Espindola 88ae7dd230 Add support for gnu archives with a string table and no symtab.
While there, use early returns to reduce nesting.

llvm-svn: 185547
2013-07-03 15:57:14 +00:00
Alexey Samsonov 64188f9f2b Make a switch in createBinary fully-covered. Add forgotten macho_dsym_companion case.
llvm-svn: 185139
2013-06-28 09:44:05 +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 aff5125f88 [yaml2obj][ELF] Don't explicitly set `Binding` with STB_*
Instead, just have 3 sub-lists, one for each of
{STB_LOCAL,STB_GLOBAL,STB_WEAK}.

This allows us to be a lot more explicit w.r.t. the symbol ordering in
the object file, because if we allowed explicitly setting the STB_*
`Binding` key for the symbol, then we might have ended up having to
shuffle STB_LOCAL symbols to the front of the list, which is likely to
cause confusion and potential for error.

Also, this new approach is simpler ;)

llvm-svn: 184506
2013-06-21 00:27:50 +00:00
Sean Silva 05001b9f38 [yaml2obj][ELF] Add support for st_value and st_size.
After this patch, the ELF file produced by
`yaml2obj-elf-symbol-basic.yaml`, when linked and executed on x86_64
(under SysV ABI, obviously; I tested on Linux), produces a working
executable that goes into an infinite loop!

llvm-svn: 184469
2013-06-20 20:59:47 +00:00
Sean Silva 98186220be [yaml2obj][ELF] Allow symbols to reference sections.
llvm-svn: 184468
2013-06-20 20:59:41 +00:00
NAKAMURA Takumi db1bf3fd2d MachOUniversal.cpp: Fix abuse of Twine. It would be sufficient to use std::string instead.
llvm-svn: 184291
2013-06-19 09:55:05 +00:00
Sean Silva 8432251a9f [yaml2obj][ELF] Support ELFOSABI_* enum.
llvm-svn: 184268
2013-06-19 00:55:28 +00:00
Sean Silva bba8559767 [yaml2obj][ELF] Support st_info through `Binding` and `Type` YAML keys.
llvm-svn: 184263
2013-06-19 00:11:59 +00:00
Sean Silva 6b08388940 [yaml2obj][ELF] Rudimentary symbol table support.
Currently, we only output the name.

llvm-svn: 184255
2013-06-18 23:14:03 +00:00
Alexey Samsonov e6388e622e Basic support for parsing Mach-O universal binaries in LLVMObject library
llvm-svn: 184191
2013-06-18 15:03:28 +00:00
Rafael Espindola e107ade3f9 Don't convert object_error's enum to and from int.
This allows the compiler to see the enum and warn about it. While in here,
fix a switch to not use a default and fix style violations.

llvm-svn: 184186
2013-06-18 13:30:31 +00:00
Sean Silva a6423eb8be [yaml2obj] Add support for sh_link via `Link` key.
llvm-svn: 184022
2013-06-15 00:25:26 +00:00
Rafael Espindola 668c642830 Remove the LLVM specific archive index.
Archive files (.a) can have a symbol table indicating which object
files in them define which symbols. The purpose of this symbol table
is to speed up linking by allowing the linker the read only the .o
files it is actually going to use instead of having to parse every
object's symbol table.

LLVM's archive library currently supports a LLVM specific format for
such table. It is hard to see any value in that now that llvm-ld is
gone:

* System linkers don't use it: GNU ar uses the same plugin as the
linker to create archive files with a regular index. The OS X ar
creates no symbol table for IL files, I assume the linker just parses
all IL files.

* It doesn't interact well with archives having both IL and native objects.

* We probably don't want to be responsible for yet another archive
format variant.

This patch then:

* Removes support for creating and reading such index from lib/Archive.
* Remove llvm-ranlib, since there is nothing left for it to do.

We should in the future add support for regular indexes to llvm-ar for
both native and IL objects. When we do that, llvm-ranlib should be
reimplemented as a symlink to llvm-ar, as it is equivalent to "ar s".

llvm-svn: 184019
2013-06-14 23:25:53 +00:00
Sean Silva 0a409cf04a [yaml2obj] Add support for sh_addralign via `AddressAlign` key.
For consistency, change the address in the test case from 0xDEADBEEF to
0xCAFEBABE since 0xCAFEBABE that actually has a 2-byte alignment.

llvm-svn: 183962
2013-06-14 00:38:02 +00:00
Sean Silva 46dffffb39 [yaml2obj] Add support for specifying raw section content.
llvm-svn: 183955
2013-06-13 22:20:01 +00:00
Sean Silva f4bfcedfe5 [yaml2obj] Add sh_addr via `Address` key.
llvm-svn: 183954
2013-06-13 22:19:54 +00:00
Sean Silva 3820593160 [yaml2obj] Initial ELF section support.
The current functionality is extremely basic and a bit rough around the
edges, but it will flesh out in future commits.

llvm-svn: 183953
2013-06-13 22:19:48 +00:00
Rui Ueyama 82ebd8e36d readobj: Dump PE/COFF optional records.
These records are mandatory for executables and are used by the loader.

Reviewers: rafael

CC: llvm-commits

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

llvm-svn: 183852
2013-06-12 19:10:33 +00:00
Sean Silva 31836f3bd7 80-cols
This slipped in during a hasty renaming.

llvm-svn: 183810
2013-06-12 00:01:22 +00:00
Rafael Espindola 447d2d12f0 Fix variable name style. Don't cast to and from int.
This enables the compiler to see the enum and produce warnings about a switch
not being fully covered. Fix one of these warnings.

llvm-svn: 183749
2013-06-11 15:29:10 +00:00
Rafael Espindola cd81b90913 Convert another use of sys::identifyFileType.
No functionality change.

llvm-svn: 183747
2013-06-11 15:19:04 +00:00
Rafael Espindola 110801addc Convert a use of sys::identifyFileType to sys::fs::identify_magic.
No functionality change.

llvm-svn: 183745
2013-06-11 14:39:59 +00:00
Sean Silva 864dd75093 Fix dubious type name similar to member name.
Should bring bots back to life.

llvm-svn: 183715
2013-06-11 00:13:52 +00:00
Sean Silva f99309cb08 [yaml2obj] Initial ELF support.
Currently, only emitting the ELF header is supported (no sections or
segments).

The ELFYAML code organization is broadly similar to the COFFYAML code.

llvm-svn: 183711
2013-06-10 23:44:15 +00:00
Rafael Espindola 1dc43065a7 Pass a StringRef to sys::identifyFileType.
llvm-svn: 183669
2013-06-10 15:27:39 +00:00
Sean Silva 4bf5c4b746 Don't artifically restrict input object size.
sys::IdentifyFileType is already conscious of the length, and
object_error::invalid_file_type is returned below anyway if
sys::IdentifyFileType doesn't recognize the file.

llvm-svn: 183605
2013-06-08 04:32:59 +00:00
Rafael Espindola 8d477dc08f Use isxdigit.
Thanks to Benjamin Kramer for the suggestion.

llvm-svn: 183540
2013-06-07 18:05:03 +00:00
Kevin Enderby 273ae01b03 Teach llvm-objdump with the -macho parser how to use the data in code table
from the LC_DATA_IN_CODE load command.  And when disassembling print
the data in code formatted for the kind of data it and not disassemble those
bytes.

I added the format specific functionality to the derived class MachOObjectFile
since these tables only appears in Mach-O object files. This is my first
attempt to modify the libObject stuff so if folks have better suggestions
how to fit this in or suggestions on the implementation please let me know.

rdar://11791371

llvm-svn: 183424
2013-06-06 17:20:50 +00:00
Rafael Espindola e2e741ecdd Print symbol names in relocations when dumping COFF as YAML.
llvm-svn: 183403
2013-06-06 13:06:17 +00:00
Sean Silva 42fa38f55b Add writeAsHex(raw_ostream &) method to BinaryRef.
This hides the implementation. A future commit will remove the
error-prone getHex() and getBinary() methods.

llvm-svn: 183352
2013-06-05 23:47:23 +00:00
Sean Silva b7e82adb72 Rename BinaryRef::isBinary to more descriptive DataIsHexString.
And add a doxygen comment.

llvm-svn: 183350
2013-06-05 23:32:31 +00:00
Sean Silva 23f3b82790 Add writeAsBinary(raw_ostream &) method to BinaryRef.
Previously, yaml2coff.cpp had a writeHexData static helper function to
do this, but it is generally useful functionality.

Also, validate hex strings up-front to avoid running having to handle
errors "deep inside" the yaml2obj code (it also gives better diagnostics
than it used to).

llvm-svn: 183345
2013-06-05 22:59:00 +00:00
Rafael Espindola 0fd21ca699 Don't print default values for NumberOfAuxSymbols and AuxiliaryData.
llvm-svn: 183293
2013-06-05 03:20:13 +00:00
Rafael Espindola 8e71301637 Move BinaryRef to a new include/llvm/Object/YAML.h file.
It will be used for ELF dumping too.

llvm-svn: 183287
2013-06-05 02:32:26 +00:00
Rafael Espindola 806f006490 Handle relocations that don't point to symbols.
In ELF (as in MachO), not all relocations point to symbols. Represent this
properly by using a symbol_iterator instead of a SymbolRef. Update llvm-readobj
ELF's dumper to handle relocatios without symbols.

llvm-svn: 183284
2013-06-05 01:33:53 +00:00
Rui Ueyama f4d0a8c13f [Object/COFF] Fix Windows .lib name handling.
llvm-svn: 183091
2013-06-03 00:27:03 +00:00
Rafael Espindola 3f1c99a67c Rename COFFYaml.h to COFFYAML.h for consistency.
llvm-svn: 183042
2013-05-31 20:38:27 +00:00
Rafael Espindola a3310e0b9e Don't allocate temporary string for section data.
llvm-svn: 183040
2013-05-31 20:26:44 +00:00