Commit Graph

1956 Commits

Author SHA1 Message Date
Rui Ueyama d62d131e49 Fix format.
llvm-svn: 210172
2014-06-04 08:39:56 +00:00
Nick Kledzik a2d602560b [mach-o] Make anonymous atom out of section content before any symbol
In sections that are broken into atoms at symbols, if the first symbol in the
section is not at the start of the section, then make an anonymous atom for
the section content that is before the first symbol.

llvm-svn: 210142
2014-06-04 00:34:27 +00:00
Nick Kledzik cb9f890b77 [mach-o] Refactor sections -> atoms to be table driven.
Previously each section kind had its own code to loop over the section and
parse it into atoms.  This refactoring has two tables.  The first maps sections
to ContentType.  The second maps ContentType to information on how to find 
the atom boundaries.  

A few bugs in test cases were discovered as part of the refactoring.  
No change in functionality intended.

llvm-svn: 210138
2014-06-03 23:36:50 +00:00
Rafael Espindola e3986f3e04 Remove dead code.
New code should probably use shared_ptr anyway.

llvm-svn: 210110
2014-06-03 15:36:31 +00:00
Simon Atanasyan fd5b2346cc [Mips] Make la25-stub.test self contained.
No functional changes.

llvm-svn: 210094
2014-06-03 09:59:42 +00:00
Rui Ueyama eafa806b72 Improve error message.
Previously the parser always printed out an error message followed
by "Invalid file type" even if the file type is correct.

llvm-svn: 210093
2014-06-03 08:40:49 +00:00
Rui Ueyama 009f91a9ee Rename FileToMutable -> SimpleFileWrapper.
FileToMutable is what this class does, but this class (or, to be precise,
an instance of this class) is a wrapper of the other SimpleFile. It's odd
that the class was named like a function.

llvm-svn: 210089
2014-06-03 08:12:33 +00:00
Rui Ueyama 6668b5a8b8 Fix build breakage.
llvm-svn: 210087
2014-06-03 07:53:37 +00:00
Rui Ueyama 6848f96c7a Inline short member function.
llvm-svn: 210086
2014-06-03 07:52:42 +00:00
Rui Ueyama 95be0d014a Use auto for obvious types.
llvm-svn: 210085
2014-06-03 07:43:15 +00:00
Rui Ueyama 9ef8a9c94b No need to compute valBit until mask bit is 1.
llvm-svn: 210084
2014-06-03 07:39:32 +00:00
Rui Ueyama 076caf7897 Use range-based for loop.
llvm-svn: 210082
2014-06-03 07:27:49 +00:00
Rui Ueyama 9939b5ab5e Remove unusual use of using.
llvm-svn: 210081
2014-06-03 07:24:46 +00:00
Rui Ueyama 04ade04e98 Reference::target() doesn't and shouldn't return a nullptr.
llvm-svn: 210074
2014-06-03 05:04:07 +00:00
Rafael Espindola 1d364c18e2 This lambda returns a boolean, update the return statements.
llvm-svn: 210071
2014-06-03 04:41:30 +00:00
Rui Ueyama 9aee050a0c Remove group-parent references.
Previously section groups are doubly linked to their children.
That is, an atom representing a group has group-child references
to its group contents, and content atoms also have group-parent
references to the group atom. That relationship was invariant;
if X has a group-child edge to Y, Y must have a group-parent
edge to X.

However we were not using group-parent references at all. The
resolver only needs group-child edges.

This patch simplifies the section group by removing the unused
reverse edge. No functionality change intended.

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

llvm-svn: 210066
2014-06-03 03:07:49 +00:00
Rui Ueyama 23487e878b Make dead-striping to handle reverse edges.
Layout-before edges are no longer used for layout, but they are
still there for dead-stripping. If we would just remove them
from code, LLD would wrongly remove live atoms that were
referenced by layout-befores.

This patch fixes the issue. Before dead-stripping, it scans all
atoms to construct a reverse map for layout-after edges. Dead-
stripping pass uses the map to traverse the graph.

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

llvm-svn: 210057
2014-06-03 01:59:02 +00:00
Rui Ueyama 02162b9cfa Run clang-format.
llvm-svn: 210015
2014-06-02 11:13:11 +00:00
Rui Ueyama d3159ce8d6 s/vector/std::vector/
llvm-svn: 210014
2014-06-02 10:58:47 +00:00
Rui Ueyama 6ffe42eee5 Simplify markLive().
Reference::target() never returns a nullptr, so NULL check
is not needed and is more harmful than doing nothing.
No functionality change.

llvm-svn: 210008
2014-06-02 08:06:57 +00:00
Simon Atanasyan 2c2486446c [Mips] Reduce number of input files used my Mips tests.
No functional changes.

llvm-svn: 210004
2014-06-02 04:20:01 +00:00
Simon Atanasyan b635d04589 [Mips] Implement .{ctors,dtors}.<priority> sections ordering.
Arrange .ctors/.dtors sections in the following order:
  .ctors from crtbegin.o or crtbegin?.o
  .ctors from regular object files
  .ctors.* (sorted) from regular object files
  .ctors from crtend.o or crtend?.o

This order is specific for MIPS traget. For example, on X86
the .ctors.* sections are merged into the .init_array section.

llvm-svn: 209987
2014-06-01 06:28:42 +00:00
Rafael Espindola a72f21d195 There is no std::errc:success, remove the llvm one.
llvm-svn: 209958
2014-05-31 03:20:37 +00:00
Rafael Espindola 63ed1a3519 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: 209948
2014-05-31 01:22:21 +00:00
Nick Kledzik acfad80250 [mach-o] Add support for custom sections
llvm-svn: 209928
2014-05-30 22:51:04 +00:00
Simon Atanasyan 2aae2b4609 [ELF] Fix incorrect sorting of .init_array / .fini_array sections.
The main problem is in the predicate passed to the `std::stable_sort()`.
This predicate always returns false if **both** section's names do not
start with `.init_array` or `.fini_array` prefixes. In short, it does not
define a strict weak orderng. Suppose we have the following sections:

  .A .init_array.1 .init_array.2

The predicate states that:

  not .init_array.1 < .A
  not .A < .init_array.2
  but .init_array.1 < .init_array.2 !!!

The second problem is that `.init_array` section without number should
go last in the list. Not it has the lowest priority '0' and goes first.

The patch fixes both of the problems.

llvm-svn: 209875
2014-05-30 05:29:46 +00:00
Nick Kledzik cc28bc1816 [mach-o] Wire up mach-o binary reader to reader registry
llvm-svn: 209868
2014-05-30 01:13:49 +00:00
Nick Kledzik f317d66c31 [mach-0] Add support for parsing compact unwind info section
llvm-svn: 209865
2014-05-29 23:50:48 +00:00
Nick Kledzik b367c25f28 [mach-o] Add support for parsing __eh_frame section. Generalize support for whether symbols in a section are ignored or illegal
llvm-svn: 209858
2014-05-29 23:07:20 +00:00
Nick Kledzik 9ede702bc4 [mach-o] Add support for parsing CFString sections
llvm-svn: 209844
2014-05-29 20:44:21 +00:00
Simon Atanasyan 7b3dd1789c [Mips] Do not mix _gp and _gp_disp symbols in relocation handling.
No functional changes.

llvm-svn: 209709
2014-05-28 04:10:01 +00:00
Nick Kledzik cda69a279d [mach-o] Add support for parsing of weak-def symbols
llvm-svn: 209707
2014-05-28 02:04:45 +00:00
Nick Kledzik 8399d69cb2 [mach-o] rename test case
llvm-svn: 209705
2014-05-28 01:31:04 +00:00
Nick Kledzik 388f3d02de [mach-o] Support parsing of non-lazy-pointer sections
llvm-svn: 209704
2014-05-28 01:16:35 +00:00
Nick Kledzik a4a08d31cf [mach-o] Add support for initializers and terminators in object files
llvm-svn: 209700
2014-05-27 23:20:52 +00:00
Nick Kledzik 81e105e8d6 [mach-o] Add checks that string literals in object files are zero terminated
llvm-svn: 209685
2014-05-27 20:37:08 +00:00
Nick Kledzik 3e90e5f187 [mach-o] Add support for reading utf16 string literal sections
llvm-svn: 209684
2014-05-27 20:25:06 +00:00
Nick Kledzik 181ce5ee03 Add make_dynamic_error_code().
This is a short-term fix to allow lld Readers to return error messages
with dynamic content.  

The long term fix will be to enhance ErrorOr<> to work with errors other
than error_code.  Or to change the interface to Readers to pass down a
diagnostics object through which all error messages are written.

llvm-svn: 209681
2014-05-27 19:35:41 +00:00
Simon Atanasyan 1c04babce3 [Mips] Handle relocations against __gnu_local_gp symbol.
llvm-svn: 209644
2014-05-27 05:23:16 +00:00
Simon Atanasyan e145a7da87 [Mips] Do not count global GOT entries using the separate variable. Use
size of global GOT entries map for that.

llvm-svn: 209616
2014-05-26 08:32:38 +00:00
Simon Atanasyan bacee46924 [Mips] Reduce code duplication. Join relocation handling functions which
perform calculations for R_MIPS_GOT16 and R_MIPS_CALL16 relocations.

llvm-svn: 209594
2014-05-25 10:07:04 +00:00
Simon Atanasyan 6c68ffe3ef [Mips] Factor out the code assign a value to the absolute atom into the
separate function.

llvm-svn: 209593
2014-05-25 09:05:06 +00:00
Simon Atanasyan 23fe15a62d [Mips] Factor out the code create Mips specific runtime file into
the MipsELFWriters member function.

llvm-svn: 209592
2014-05-25 09:04:57 +00:00
Simon Atanasyan f7534383f5 [Mips] Remove unused class member declaration.
llvm-svn: 209591
2014-05-25 09:04:45 +00:00
Simon Atanasyan 6d1a09f39f [Mips] Reduce code duplication. Join relocation handling functions which
perform similar calculations.

llvm-svn: 209590
2014-05-25 09:04:15 +00:00
Simon Atanasyan 2ffbb19335 [Mips] Handle R_MIPS_TLS_TPREL_HI16 / R_MIPS_TLS_TPREL_LO16 relocations.
llvm-svn: 209582
2014-05-24 16:45:31 +00:00
Rui Ueyama 0e57b91f9c Use short identifier.
llvm-svn: 209497
2014-05-23 03:08:05 +00:00
Rui Ueyama f713cced0e [PECOFF] Make a separate pass for /alternatename symbols.
/alternatename is a command line option to define a weak alias. You
can use it as /alternatename:foo=bar to define "foo" as a weak alias
for "bar".

Because it's a command line option, the weak alias mapping is in the
LinkingContext object, and not in a object file being read.

Previously, we looked up the mapping each time we read a new symbol
from a file, to check if there is a weak alias defined for the symbol.
That's not wrong, but had made function signature's a bit complicated --
we had to pass the mapping object to many functions. Now their
parameter lists are much cleaner.

This also has another (unrealized) benefit. parseFile() now read a
file and then add alias symbols to the file. In the first pass a
LinkingContext object is not used at all. That should make it easy
to read files from archive files speculatively, as the first pass
is free from side effect.

llvm-svn: 209486
2014-05-23 00:02:42 +00:00
Rui Ueyama ba46cdb21f Move alias symbols from ELFLinkingContext to LinkingContext.
Alias symbols are SimpleDefinedAtoms and are platform neutral. They
don't have to belong ELF. This patch is to make it available to all
platforms. No functionality change intended.

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

llvm-svn: 209475
2014-05-22 21:37:56 +00:00
Nick Kledzik 8a0bc44b71 [mach-o] Fix so that mach-o semantic errors return an error rather than assert
llvm-svn: 209469
2014-05-22 20:05:43 +00:00
Nick Kledzik d48cb047e4 [mach-o] Remove MachOFormat.hpp, everything now uses llvm/Support/MachO.h
llvm-svn: 209385
2014-05-22 01:56:40 +00:00
Nick Kledzik e39685964b [mach-o] Use lit.local.cfg to enable mach-o test cases to be run
llvm-svn: 209383
2014-05-22 01:47:17 +00:00
Nick Kledzik a0c13a2420 [mach-o] parse literal sections into atoms
llvm-svn: 209379
2014-05-22 01:42:06 +00:00
Rui Ueyama 328da5527e Simplify nullptr check.
llvm-svn: 209357
2014-05-22 00:36:36 +00:00
Rui Ueyama 8f2394d456 Fix comment.
llvm-svn: 209334
2014-05-21 23:07:16 +00:00
Rui Ueyama 339d12ff12 [PECOFF] Fix unsafe memory access.
llvm-svn: 209323
2014-05-21 21:51:11 +00:00
Rui Ueyama 9f4674c828 [PECOFF] Check for a Characteristics field of a .debug section.
llvm-svn: 209317
2014-05-21 19:44:08 +00:00
Simon Atanasyan 37fe06711f [Mips] Simplify handling of R_MIPS_LO16 / R_MIPS_HI16 relocations
against _gp_disp symbol.

llvm-svn: 209315
2014-05-21 18:23:46 +00:00
Rafael Espindola 38eed1b86d Update for llvm's r209253.
llvm-svn: 209293
2014-05-21 13:07:41 +00:00
Rui Ueyama 85a0321b15 [PECOFF] Discard .debug sections.
llvm-svn: 209274
2014-05-21 05:56:31 +00:00
Rui Ueyama 5c35c8c9ab [PECOFF] Make COFFObjectReader thread-safe.
llvm-svn: 209271
2014-05-21 04:17:05 +00:00
Rui Ueyama 9b0a69d6dc [PECOFF] Acquire mutex before accessing shared objects.
addResolvableSymbols() queues input files, and readAllSymbols() reads
from them. In practice it's currently safe because they are called from
a single thread. But it's not guaranteed.

Also, acquiring the same mutex is needed not to see inconsistent memory
contents that is allowed in the C++ memory model.

llvm-svn: 209254
2014-05-20 23:05:09 +00:00
Rui Ueyama 1255496271 [PECOFF] Do not use anonymous namespace in a header.
llvm-svn: 209243
2014-05-20 21:58:34 +00:00
Alp Toker 2e62f7220f Fix typos
llvm-svn: 209213
2014-05-20 16:17:53 +00:00
Simon Atanasyan c2ec8c5281 [Mips] Show warning if the linker cannot find a pair for a R_MIPS_HI16
relocation. In fact this case violates ABI but sometimes compilers might
produce such code.

llvm-svn: 209153
2014-05-19 18:48:57 +00:00
Simon Atanasyan 9ab2cd0301 [Mips] Fix calculation of initial GOT entry value when this entry is
referenced by a local symbol.

llvm-svn: 209063
2014-05-17 04:58:26 +00:00
Nick Kledzik e09cfc5f8a [mach-o] Add support for zero-fill sections.
llvm-svn: 208928
2014-05-15 23:03:50 +00:00
Nick Kledzik 61fdef6086 [mach-o] Add support and test cases for parsing tentative definitions
llvm-svn: 208919
2014-05-15 20:59:23 +00:00
Rui Ueyama 5def41ee40 [PECOFF] Read files lazily.
ExportedSymbolRenameFile is not always used. In most cases we don't
need to read given files at all. So lazy load would help. This doesn't
change the meaining of the program.

llvm-svn: 208818
2014-05-14 22:35:47 +00:00
Rui Ueyama 50c337a47c Remove trailing whitespaces.
llvm-svn: 208815
2014-05-14 21:49:38 +00:00
Nick Kledzik dba52ad488 [mach-o] Add test case for parsing nlist -> Scope
llvm-svn: 208814
2014-05-14 21:37:14 +00:00
Nick Kledzik 0224e3475d Add -print_atoms options to DarwinLdDriver which dumps final state of all atoms in yaml
llvm-svn: 208813
2014-05-14 21:32:21 +00:00
Rui Ueyama 2a52251153 Fix regression introduced in r205566.
In r205566, I made a change to Resolver so that Resolver revisit
only archive files in --start-group and --end-group pair. That's
not correct, as it also has to revisit DSO files.

This patch is to fix the issue.

Added a test to demonstrate the fix. I confirmed that it succeeded
before r205566, failed after r205566, and is ok with this patch.

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

llvm-svn: 208797
2014-05-14 17:29:27 +00:00
Rui Ueyama b18489c8bf [PECOFF] Find symbols with @number suffix for dllexported symbols
As written in the comment in this patch, symbol names specified with
/export option is resolved in a special way; for /export:foo, linker
finds a foo@<number> symbol if such symbols exists.

On Windows, a function in stdcall calling convention is mangled with
a leading underscore and following "@" and numbers. This name
mangling is kind of automatic, so you can sometimes omit _ and @number
when specifying a symbol. /export option is that case.

Previously, if a file in an archive file foo.lib provides a symbol
_fn@8, and /export:fn is specified, LLD failed to resolve the symbol.
It only tried to find _fn, and failed to find _fn@8. With this patch,
_fn@8 will be searched on the second iteration.

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

llvm-svn: 208754
2014-05-14 06:29:32 +00:00
Rui Ueyama 551aacd6bc Add observers to Input Graph
Make it possible to add observers to an Input Graph, so that files
returned from an Input Graph can be examined before they are
passed to Resolver.

To implement some PE/COFF features we need to know all the symbols
that *can* be solved, including ones in archive files that are not
yet to be read.

Currently, Resolver only maintains a set of symbols that are
already read. It has no knowledge on symbols in skipped files in
an archive file.

There are many ways to implement that. I chose to apply the
observer pattern here because it seems most non-intrusive. We don't
want to mess up Resolver with architecture specific features.
Even in PE/COFF, the feature that needs this mechanism is minor.
So I chose not to modify Resolver, but add a hook to Input Graph.

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

llvm-svn: 208753
2014-05-14 05:31:54 +00:00
Simon Atanasyan 35687a2fd3 [ELF] Emit DT_TEXTREL dynamic table flag.
If one or more dynamic relocation might modify a read-only section,
dynamic table should contain DT_TEXTREL tag.

The patch introduces new `RelocationTable::canModifyReadonlySection()`
method. This method checks through the relocations to see if any modifies
a read-only section. The DynamicTable class calls this method and emits
the DT_TEXTREL tag if necessary.

The patch reviewed by Rui Ueyama and Shankar Easwaran.

llvm-svn: 208670
2014-05-13 07:37:09 +00:00
Rui Ueyama a131bdb77e Indent continuation lines
llvm-svn: 208630
2014-05-12 20:51:21 +00:00
Simon Atanasyan 20b043b24c [Mips] Update test case expectations to reflect changes in the
llvm-readobj output format.

llvm-svn: 208490
2014-05-11 08:54:30 +00:00
Rui Ueyama 629d201c97 [PECOFF] Resolve dllexported symbols.
We did not actively try to resolve dllexported symbols specified
by /export or by a module definition file. So if exported symbols
would be resolved for other reasons, like other symbols refer to
them, that was fine, but if (unreferenced) exported symbols were
in an archive file, and no one refers to that file in the archive,
they remained unresolved.

That would obviously cause the issue that dllexported symbols are
not in a resultant DLL.

In this patch, we create an undefined symbol for each dllexported
symbol, to let the core linker to resolve it.

llvm-svn: 208452
2014-05-09 22:19:49 +00:00
Rui Ueyama 457aa3bbdd [PECOFF] Fix dllexported name.
Previously the handling of exported symbol was wrong if it's
specified in a module definition file in the form of
<externalname>=<internalname>. Export the correct symbol.

llvm-svn: 208446
2014-05-09 21:37:43 +00:00
Rui Ueyama c7c47681f6 Revert "temporary commit."
This reverts accidental commit r208427.

llvm-svn: 208433
2014-05-09 16:47:20 +00:00
Rui Ueyama 1127fe4704 [PECOFF] DLL extension can be omitted in .def file.
llvm-svn: 208428
2014-05-09 16:35:26 +00:00
Rui Ueyama 4e0b17dd3c temporary commit.
llvm-svn: 208427
2014-05-09 16:35:23 +00:00
Rui Ueyama 89637c8098 [PECOFF] Split LocallyImportedSymbolFile into two classes.
I have a plan to use VirtualArchiveFile in this file in the near future.
This change should improve the readability by itself, too.

llvm-svn: 208365
2014-05-08 22:30:43 +00:00
Rui Ueyama b13cda8f3e Call normalize() in the common driver.
Previously only GNU driver calls InputGraph::normalize, but its
functionality is not and should not be limited to GNU ld. Other
driver should be able to use it.

Currently only linker scripts use the feature, so this change
won't change the existing behavior.

llvm-svn: 208266
2014-05-07 23:33:48 +00:00
Rui Ueyama 9967f49a3c Simplify InputGraph::getNextFile. No functionality change.
llvm-svn: 208256
2014-05-07 22:27:12 +00:00
Rui Ueyama d6a0604180 Trivial simplification
llvm-svn: 208145
2014-05-07 00:04:48 +00:00
Rui Ueyama 3608609339 Expand nested input elements.
Previously only the toplevel elements were expanded by expandElements().
Now we recursively call getReplacements() to expand input elements even
if they are in, say, in a group.

llvm-svn: 208144
2014-05-06 23:52:19 +00:00
Rui Ueyama 0d85dbfce0 Tests no longer uses getNextInputElement, so make it private.
llvm-svn: 208124
2014-05-06 19:32:54 +00:00
Rui Ueyama 2fa41d1817 Add a test for notifyProgress().
llvm-svn: 208123
2014-05-06 19:26:21 +00:00
Rui Ueyama aa30ccffa8 Remove unused variable.
llvm-svn: 208121
2014-05-06 19:11:39 +00:00
Rui Ueyama b51711b356 Fix copypaste error.
llvm-svn: 208120
2014-05-06 19:05:14 +00:00
Rui Ueyama b12dcb6095 s/My/Test/ as these classes are for tests.
llvm-svn: 208119
2014-05-06 19:01:56 +00:00
Rui Ueyama fd5c70d0ec Make the test even more readable.
llvm-svn: 208118
2014-05-06 18:58:24 +00:00
Rui Ueyama 48a1727e6f Simplify unit test code.
llvm-svn: 208116
2014-05-06 18:41:12 +00:00
Rui Ueyama d976941704 Remove meaningless return value in test.
llvm-svn: 208112
2014-05-06 18:27:37 +00:00
Rui Ueyama 27169ce309 Replace copypasta with function calls to make tests intelligible.
llvm-svn: 208111
2014-05-06 18:24:27 +00:00
Rui Ueyama 1fe682cf37 Don't return value rather than always returning true.
addInputElement() never fails, and no one checks its return value
except tests. Let's simplify the signature.

llvm-svn: 208109
2014-05-06 17:33:14 +00:00
Rui Ueyama b340f0117c Remove a method that no one is using.
llvm-svn: 208101
2014-05-06 16:22:04 +00:00
Rui Ueyama 91dd26b9a0 Remove repeated access specifier.
llvm-svn: 208028
2014-05-06 01:10:01 +00:00
Rui Ueyama f129f72e43 Remove unused field.
llvm-svn: 208024
2014-05-06 01:00:43 +00:00
Rui Ueyama 1b1ec8bfe2 Fix spelling.
llvm-svn: 208022
2014-05-06 00:51:52 +00:00
Rui Ueyama 8620d933f4 Remove operator[] that was used only in tests.
llvm-svn: 208020
2014-05-06 00:50:46 +00:00
Rui Ueyama beacd25780 Re-submit r207884: Remove dead code
Differential Revision: http://reviews.llvm.org/D3599

llvm-svn: 207989
2014-05-05 18:56:04 +00:00
Simon Atanasyan b9b9e36187 [ELF] Use a range based access to the ELFFile's sections collection.
No functional changes.

llvm-svn: 207953
2014-05-05 07:17:40 +00:00
Simon Atanasyan e22ca46681 [Mips] R_MIPS_GPREL32 relocation support.
llvm-svn: 207949
2014-05-05 05:56:06 +00:00
Rui Ueyama 82d62c4420 Revert "Remove dead code."
This reverts commit r207884 which was prematurely committed by accident.

llvm-svn: 207886
2014-05-02 23:45:28 +00:00
Rui Ueyama 3872d0ae26 Remove "virtual" and add "override".
llvm-svn: 207885
2014-05-02 23:44:02 +00:00
Rui Ueyama d50ed14d92 Remove dead code.
isAlias always returns false and no one is using it. It was
originally added Atom to query if an atom is an alias for another
atom, assuming that alias atoms are different from normal atoms.

We now support atom aliasing, but the way that's implemented is
in a different way than what isAlias assumed. An alias atom is
just a regular defined atom with no content, and it has a layout-
before edge to alias-to atom so that they are layed out at the
same location in the result. So this is dead code, and it doesn't
make much sense to keep it.

llvm-svn: 207884
2014-05-02 23:43:59 +00:00
Rui Ueyama 20822d924e Return the expression result directly.
llvm-svn: 207878
2014-05-02 22:32:01 +00:00
Rui Ueyama 19173a39d3 Don't use "auto" where the actual type is not obvious.
llvm-svn: 207875
2014-05-02 21:48:01 +00:00
Rui Ueyama 0e363b75a4 [PECOFF] Support =internalName syntax in .def file.
Export definitions in a module definition file is as follows:

  exportedname[=internalname] [@ordinal [NONAME]] [PRIVATE] [DATA]

Previously we did not support =internalname, so users couldn't export
symbols from a DLL with a different name.

llvm-svn: 207827
2014-05-02 03:43:51 +00:00
Rui Ueyama db2fc6d756 Make the variable scope narrower. No functionality change.
llvm-svn: 207821
2014-05-02 01:17:40 +00:00
Rui Ueyama efa8076c29 [PECOFF] Drop stdcall's atsign suffix only.
You can omit @number suffix when specifying /export option,
but you can do that only for stdcall functions.

llvm-svn: 207809
2014-05-01 22:44:42 +00:00
Rui Ueyama a665de8f38 Fix FreeBSD buildbots.
llvm-svn: 207802
2014-05-01 22:13:39 +00:00
Joerg Sonnenberger c8f36d2d55 Sort.
llvm-svn: 207798
2014-05-01 21:40:22 +00:00
Rui Ueyama da808c39e6 [PECOFF] Do not call addDllExport to mutate export descriptors.
This is more efficient than before.

llvm-svn: 207791
2014-05-01 20:40:30 +00:00
Simon Atanasyan ffc1c6af49 [ELF] Fix the file look up algorithm used in the linker script GROUP command.
In general the linker scripts's GROUP command works like a pair
of command line options --start-group/--end-group. But there is
a difference in the files look up algorithm.

The --start-group/--end-group commands use a trivial approach:
a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so'
   suffix and search the path through library search directories.
b) Otherwise, use the path 'as-is'.

The GROUP command implements more compicated approach:
a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so'
   suffix and search the path through library search directories.
b) If the path does not have '-l' prefix, and sysroot is configured,
   and the path starts with the / character, and the script being
   processed is located inside the sysroot, search the path under
   the sysroot. Otherwise, try to open the path in the current
   directory. If it is not found, search through library search
   directories.

https://www.sourceware.org/binutils/docs-2.24/ld/File-Commands.html

The patch reviewed by Shankar Easwaran, Rui Ueyama.

llvm-svn: 207769
2014-05-01 16:22:08 +00:00
Simon Atanasyan 4e480de0cc [Mips] Follow-up to the r207744. Replace numerical e_flags constants by their names.
llvm-svn: 207745
2014-05-01 11:10:47 +00:00
Simon Atanasyan f01ce1990c [Mips] Follow-up to the r207687. Add the test to check MIPS specific
arguments of the -m command line option.

llvm-svn: 207738
2014-05-01 05:12:32 +00:00
Rui Ueyama e1452c22e5 [PECOFF] Fix exported symbol name.
When creating a .lib file, we should strip the leading underscore,
but should not strip stdcall atsign suffix. Otherwise produced .lib
files cannot be linked.

llvm-svn: 207729
2014-05-01 00:23:07 +00:00
Rui Ueyama e18ed4e16b [PECOFF] Add a test for lib.exe subcommand.
Previously the input file for the lib.exe command would be removed
as soon as the command exits, so we couldn't write a test to check
the file contents are correct.

This patch adds /lldmoduledeffile: option to retain a copy of the
temporary file at the given file path, so that you can see the file
if you want.

llvm-svn: 207727
2014-05-01 00:06:56 +00:00
Simon Atanasyan a64f34b759 [Driver] Check type of InputElement before request a error message. If the
element is a FileNode, request error description. If the element is Group,
print hard coded error message. We need to implement a better diagnostics
here but even current solution is better than a segmentation fault output.

llvm-svn: 207691
2014-04-30 19:04:01 +00:00
Simon Atanasyan db8a4a8578 [ELF] Return result from the function ASAP.
No functional changes.

llvm-svn: 207690
2014-04-30 19:03:56 +00:00
Simon Atanasyan a54d34d4ad [ELF] Factor out the code builds a library search directory path
into the separate function.

No functional changes.

llvm-svn: 207689
2014-04-30 19:03:51 +00:00
Simon Atanasyan 76d8d36c3c [Driver] Remove the redundant cast.
No functional changes.

llvm-svn: 207688
2014-04-30 19:03:45 +00:00
Simon Atanasyan e33f2add5d [Mips] Recognize MIPS emulation name 'elf32ltsmip'.
llvm-svn: 207687
2014-04-30 19:03:40 +00:00
Rui Ueyama 680210fe7d [PECOFF] Fix priority of locally imported symbols.
Linker should create _imp_ symbols for local use only when such
symbols cannot be resolved in any other way. If it overrides real
imported symbols, such symbols remain virtually unresolved without
error, causing odd issues. I observed that a program linked with
LLD entered an infinite loop before reaching main() because of
this issue.

This patch moves the virtual file creating _imp_ symbols to the
very end of the input file list. Previously, the file is at the end
of the library file group. Linker might revisit the group many times,
so it was not really at the end of the input file list.

llvm-svn: 207605
2014-04-30 03:31:46 +00:00
Simon Atanasyan 105d6abe50 [Mips] Re-order include headers.
llvm-svn: 207495
2014-04-29 05:46:02 +00:00
Simon Atanasyan 8de2b8fb81 [Mips] Implement emitting of R_MIPS_REL32 relocations:
1. Re-implement PLT entries and dynamic relocations emitting to keep PLT
and relocations table in a consistent state.

2. Initialize st_value and st_other fields for dynamic symbols table
entry if this entry corresponds to an external function which address is
taken in a non-PIC executable. In that case the st_value field holds an
address of the function's PLT entry. Also set STO_MIPS_PLT bit in the
st_other field.

llvm-svn: 207494
2014-04-29 05:21:54 +00:00
Simon Atanasyan f293b3e52c [Mips] 80 column.
llvm-svn: 207493
2014-04-29 05:21:36 +00:00
Rui Ueyama 7f4162bd06 [PECOFF] /export accepts non-decorated symbols.
You usually have to specify the exact name of a symbol to export it,
but for stdcall functions you can omit the @numbers suffix.

llvm-svn: 207491
2014-04-29 02:50:35 +00:00
Rui Ueyama 72d57ab32e [PECOFF] Fix _imp_ implicit symbols.
Implicit symbol for local use implemented in r207141 was not fully
compatible with MSVC link.exe. In r207141, I implemented the feature
in such way that implicit symbols are defined only when they are
exported with /EXPORT option.

After that I found that implicit symbols are defined not only for
dllexported symbols but for all defined symbols. Actually _imp_
implicit symbols have no relationship with the dllexport feature. You
could add _imp_ to any symbol to get a pointer to the symbol, whether
the symbol is dllexported or not.  It looks pretty weird to me but
that's what we want if link.exe behaves that way.

Here is a bit about the implementation: Creating all implicit symbols
beforehand is going to be a huge waste of resource. This feature is
rarely used, and MSVC link.exe even prints out a warning message when
it finds this feature is being used. So we create implicit symbols
on demand. There is an archive file that creates implicit symbols when
they are needed.

llvm-svn: 207476
2014-04-29 00:32:00 +00:00
Simon Atanasyan 0804610e9f [Mips] Rename the test case.
llvm-svn: 207437
2014-04-28 19:34:46 +00:00
Simon Atanasyan 9b5e5d7942 [Mips] Rewrite the R_MIPS_COPY relocation test using yaml2obj tool.
llvm-svn: 207436
2014-04-28 19:34:39 +00:00
Simon Atanasyan 15dce7a8f3 [Mips] Convert MipsDynamicSymbolTable to the class template.
llvm-svn: 207435
2014-04-28 19:34:34 +00:00
Simon Atanasyan 0053796a08 [Mips] Add the 'const' qualifier to the couple RelocationPass class
member functions.

llvm-svn: 207434
2014-04-28 19:34:27 +00:00
Reid Kleckner 64e7a03f24 lld: Silence CMake warning about a target that doesn't exist
lld-test.deps doesn't exist in a non-standalone build.

llvm-svn: 207431
2014-04-28 18:34:11 +00:00
Rui Ueyama f33946d51d [PECOFF] Allow multiple directives in one module-definition file.
I'm a bit surprised that I have not implemented this yet. This is
definitely needed to handle real-world module definition files.
This patch contains a unit test for r207294.

llvm-svn: 207297
2014-04-26 00:25:02 +00:00
Rui Ueyama 637300ea4e [PECOFF] Fix off-by-one error in .def file parser.
I'm fixing another bug in the parser, and I wanted to submit this
fix as a separate change as it's logically independent from the other.
I'll add a test for this shortly.

llvm-svn: 207294
2014-04-25 23:59:27 +00:00
Rui Ueyama 409ac186bb [PECOFF] Add /IMPLIB command line option.
This option is to override the default import file path.

llvm-svn: 207175
2014-04-25 03:35:13 +00:00
Rui Ueyama 51d7efdb57 [PECOFF] Assign unique ordinals to __imp_ symbols.
llvm-svn: 207168
2014-04-25 01:18:40 +00:00
Rui Ueyama ae13a45d4d [PECOFF] Do not copy-construct ExportDesc.
llvm-svn: 207154
2014-04-24 22:57:17 +00:00
Rui Ueyama f550eba39c [PECOFF] Define implicit symbols for exported ones.
This patch is to fix a compatibility issue with MSVC link.exe as to
use of dllexported symbols inside DLL.

A DLL exports two symbols for a function. One is non-decorated one,
and the other is with __imp_ prefix. The former is a function that
you can directly call, and the latter is a pointer to the function.
These dllexported symbols are created by linker for programs that
link against the DLL. So, I naturally believed that __imp_ symbols
become available when you once create a DLL and link against it, but
they don't exist until then. And that's not true.

MSVC link.exe is smart enough to allow users to use __imp_ symbols
locally. That is, if a symbol is specified with /export option, it
implicitly creates a new symbol with __imp_ prefix as a pointer to
the exported symbol. This feature allows the following program to
be linked and run, although _imp__hello is not defined in this code.

  #include <stdio.h>

  __declspec(dllexport)
  void hello(void) { printf("Hello\n"); }

  extern void (*_imp__hello)(void);

  int main() {
    _imp__hello();
    return 0;
  }

MSVC link.exe prints out the following warning when linking it.

  LNK4217: locally defined symbol _hello imported in function _main

Using __imp_ symbols locally is I think not a good coding style. One
should just take an address using "&" operator rather than appending
__imp_ prefix. However, there are programs in the wild that depends
on this link.exe's behavior, so we need this feature.

llvm-svn: 207141
2014-04-24 20:12:01 +00:00
Rui Ueyama 11f3f1f7d5 [PECOFF] Allow symbols not starting with '_' in x86
Not all symbols are decorated with an underscore in x86. You can
write undecorated symbols in assembly, for example. Thus this
assertion is too strong.

llvm-svn: 207125
2014-04-24 17:04:19 +00:00
Filipe Cabecinhas cd8c610cb0 XFAIL the Mips tests when we don't have the target.
These tests shouldn't even try to use the Mips target, but let's make
them not fail when we don't have it while they don't get fixed.

llvm-svn: 206947
2014-04-23 05:35:26 +00:00
Filipe Cabecinhas 47f07f8c9a winlib should be lib.exe, not just lib.
This avoids setting the winlib feature on machines with a lib dir in a
$PATH dir.

llvm-svn: 206940
2014-04-23 04:38:13 +00:00
Rui Ueyama 7ad715d871 [PECOFF] Skip IMAGE_SYM_DEBUG sections correctly.
We don't use sections with IMAGE_SYM_DEBUG attribute so we basically
want to the symbols for them when reading symbol table. When we skip
them, we need to skip auxiliary symbols too. Otherwise weird error
would happen because aux symbols would be interpreted as regular ones.

llvm-svn: 206931
2014-04-22 23:48:42 +00:00
Rui Ueyama 0e32610fb5 [PECOFF] Better handling of /OPT option.
Previously LLD would fail if /OPT:icf, /OPT:lbr or such are specified,
because these command line flags would be handled as unknown ones. We
rather want LLD to ignore these known but yet-to-be-implemented options
for now.

Added tests for the driver as well.

llvm-svn: 206863
2014-04-22 03:57:07 +00:00
Chandler Carruth 9afe32d11d [Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
definition below all of the header #include lines, LLD edition.

IF you want to know more details about this, you can see the recent
commits to Debug.h in LLVM. This is just the LLD segment of a cleanup
I'm doing globally for this macro.

llvm-svn: 206851
2014-04-22 03:21:31 +00:00
Rui Ueyama f171ace07d [PECOFF] Handle line comment in module-definition file.
In .def files, ';' is the start of line comment.

llvm-svn: 206831
2014-04-22 00:11:52 +00:00
Reid Kleckner f00daf15f0 Add support for building Sphinx documentation when being built inside LLVM source tree and using CMake.
Patch by Dan Liew <daniel.liew@imperial.ac.uk>!

llvm-svn: 206662
2014-04-18 21:59:05 +00:00
Rui Ueyama e5097d0ed4 Fix broken test.
llvm-svn: 206651
2014-04-18 21:19:22 +00:00
Rui Ueyama 311a162f26 [PECOFF] Win64 DLL entry function name is _DllMainCRTStartup.
Unlike Win32/x86, it has no "@12" suffix.

llvm-svn: 206648
2014-04-18 21:05:59 +00:00
Rui Ueyama 83743ccca4 [PECOFF] Support LIBRARY directive.
LIBRARY directive in a module definition file specifies the output
DLL file name. It also takes an optional value for the base address.

llvm-svn: 206647
2014-04-18 20:48:20 +00:00
Rui Ueyama 4aaea17dc9 [PECOFF] Add one more test for r206633.
llvm-svn: 206645
2014-04-18 20:44:05 +00:00
Rui Ueyama be0a7ac5e8 Remove redundant "explicit" keywords.
llvm-svn: 206639
2014-04-18 20:06:00 +00:00
Rui Ueyama a2b0334e93 Use switch for readability.
llvm-svn: 206638
2014-04-18 19:59:33 +00:00
Rui Ueyama 28da676709 [PECOFF] Ignore /ignore option.
/ignore:<number> is a linker option to disable warning specified by
the number. We ignore the option because it does not make sense for
LLD.

llvm-svn: 206636
2014-04-18 19:49:24 +00:00
Rui Ueyama 38cf6ddc30 [PECOFF] Support /manifestuac:NO.
If the value for /manifestuac is "NO", LLD will create a manifest XM
file but won't emit <trustinfo> element.

llvm-svn: 206633
2014-04-18 19:43:07 +00:00
Rui Ueyama d48665b1fd [ELF] Fix GNU_RELRO section name.
llvm-svn: 206560
2014-04-18 06:01:43 +00:00
Rui Ueyama 3511b02a85 [ELF] Fix typo that caused a test to fail on FreeBSD.
llvm-svn: 206538
2014-04-17 23:38:01 +00:00
Simon Atanasyan d874ea281f [Mips] Fix typo in the test.
llvm-svn: 206484
2014-04-17 18:18:51 +00:00
Rui Ueyama 08587f8ccd Silence the test failure on FreeBSD for now.
It's hard to debug this failure on remote machine only with lit logs.
I'm trying to reproduce it locally on a FreeBSD machine.

llvm-svn: 206432
2014-04-17 00:55:54 +00:00
Rui Ueyama d0848a6fa8 Second attempt to unbreak the buildbot.
llvm-svn: 206428
2014-04-16 23:35:12 +00:00
Rui Ueyama a4d93b5062 Attempt to unbreak FreeBSD/AMD64 buildbot.
llvm-svn: 206419
2014-04-16 21:19:35 +00:00
Rui Ueyama 327db80dd5 [ELF] Support --defsym=<symbol>=<symbol>.
Currently LLD supports --defsym only in the form of
--defsym=<symbol>=<integer>, where the integer is interpreted as the
absolute address of the symbol. This patch extends it to allow other
symbol name to be given as an RHS value. If a RHS value is a symbol
name, the LHS symbol will be defined as an alias for the RHS symbol.

Internally, a LHS symbol is represented as a zero-size defined atom
who has an LayoutAfter reference to an undefined atom, whose name is
the RHS value. Everything else is already implemented -- Resolver
will resolve the undefined symbol, and the layout pass will layout
the two atoms at the same location. Looks like it's working fine.

Note that GNU LD supports --defsym=<symbol>=<symbol>+<addend>. That
feature is out of scope of this patch.

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

llvm-svn: 206417
2014-04-16 20:58:57 +00:00
Simon Atanasyan 60536ee625 [Mips] Emit PLT entries for more static relocations.
llvm-svn: 206358
2014-04-16 06:16:32 +00:00
Benjamin Kramer afa371debb Add missing includes.
llvm-svn: 206113
2014-04-12 16:32:42 +00:00
Simon Atanasyan e3e8a0a913 [ELF] Regroup code creates ELF relocations references ELFReference into
a couple of new virtual functions.

Follow-up to the rL203408. Two virtual functions `createRelocationReference()`
responsible for creation of `ELFReference` have been replaced by a couple of
new virtual functions `createRelocationReferences()` (plural). Each former
function creates a //single// ELFReference for a specified `Elf_Rela`
or `Elf_Rel` relocation records. The new functions responsible for creation
of //all// relocation references for provided symbol.

For all targets except MIPS there are no functional changes.

MIPS ABI has a notion of //paired// relocations. An effective addend of such
relocations are calculated using addends of both pair's members.
Each `R_MIPS_HI16` and `R_MIPS_GOT16` (for local symbols) relocations must have
an associated `R_MIPS_LO16` entry immediately following it in the list
of relocations. Immediately does not mean "next record" in relocations section
but "next record referenced the same symbol". Moreover a single `R_MIPS_LO16`
relocation can be paired with multiple preceding `R_MIPS_HI16/R_MIPS_GOT16`
relocations.

The paired relocation can have offsets belong to the different symbols.
That is why we need to have access to list of all relocations during
construction of `ELFReference` for MIPS target.

The patch reviewed by Shankar Easwaran.

llvm-svn: 206102
2014-04-12 03:59:46 +00:00
Simon Atanasyan dca4162aa5 [Mips] Factor out MIPS relocation addend reading to the separate
function.

No functional changes.

llvm-svn: 206023
2014-04-11 07:25:35 +00:00
Simon Atanasyan e5b156810a [ELF] Remove redundant conversion of section content from ArrayRef to
StringRef before calling the createSectionAtom() method and reverse
conversion inside the method.

No functional changes.

llvm-svn: 206022
2014-04-11 07:25:29 +00:00
Simon Atanasyan 5eb139fc7c [Mips] Rewrite R_MIPS_26 handling test using the yaml2obj tool.
llvm-svn: 206020
2014-04-11 04:44:05 +00:00
Simon Atanasyan b65826124c [Mips] Rewrite R_MIPS_32 handling test using the yaml2obj tool.
llvm-svn: 206019
2014-04-11 04:43:59 +00:00
Simon Atanasyan 62377c6875 [Mips] R_MIPS_PC32 relocation support.
llvm-svn: 206018
2014-04-11 04:33:21 +00:00
David Majnemer 678088148c Update to match changes made in r205955
llvm-svn: 205956
2014-04-10 07:49:18 +00:00
Rui Ueyama 20b075e526 [PECOFF] Fix common symbol alignment.
Differential Revision: http://reviews.llvm.org/D3322

llvm-svn: 205826
2014-04-09 01:01:51 +00:00
Rui Ueyama e6c499acd7 Early continue to reduce nesting.
llvm-svn: 205737
2014-04-07 21:13:33 +00:00
Rui Ueyama 5de951d8c1 No else after return.
llvm-svn: 205736
2014-04-07 21:01:11 +00:00
Rui Ueyama feab78785b [ELF] Unit tests for -o and --noinhibit-exec.
llvm-svn: 205735
2014-04-07 20:52:48 +00:00
Rui Ueyama 3017efb710 Update Phabricator server.
llvm-svn: 205698
2014-04-07 04:52:24 +00:00
Rui Ueyama 595026e071 [ELF] Accept "-rpath=<foo>" as well as "-rpath <foo>".
llvm-svn: 205694
2014-04-06 21:23:24 +00:00
Rui Ueyama c141c8c59a [ELF] Fix driver bug.
GNU LD-comptaible driver wrongly requires a space after '=' for a few
options such as "-init=<symbol>" or "-entry=<symbol>". This patch is
to fix that bug and add a few tests for it.

llvm-svn: 205693
2014-04-06 21:15:05 +00:00
Simon Atanasyan 2f5d6ae73f [ELF] Use typedefs to make class field declarations shorter.
No functional changes.

llvm-svn: 205692
2014-04-06 19:44:50 +00:00
Rui Ueyama 7088e3470c [ELF] Add a test for -rpath.
llvm-svn: 205663
2014-04-05 02:15:23 +00:00
Rui Ueyama ac0f7ca3a8 [ELF] Fix --soname option.
Currently LLD accepts only "-soname <string>", but all the following
options are actually valid.

  --soname=foo
  --soname foo
  -soname=foo
  -soname foo
  -h foo

This patch fixes that issue.

llvm-svn: 205662
2014-04-05 02:07:04 +00:00
Rui Ueyama e36fbea175 [ELF] Diagnose malformed --dynsym option.
llvm-svn: 205654
2014-04-04 22:36:30 +00:00
Michael J. Spencer ead3b1a544 [X86-64] Add missing relocation.
llvm-svn: 205645
2014-04-04 19:22:14 +00:00
Rui Ueyama 60ea496448 This is yet another case clang-modernize failed to add "override".
llvm-svn: 205644
2014-04-04 19:17:59 +00:00
Rui Ueyama 331f482cf6 Split a utility function not to use goto statement.
llvm-svn: 205643
2014-04-04 18:34:40 +00:00
Rui Ueyama e8af3e48fd useNew is set to false in all branches, so set it to false outside the if-else.
llvm-svn: 205642
2014-04-04 18:21:53 +00:00
Rui Ueyama 01cc718375 Replace dyn_cast<T>s immediately followed by asserts with cast<T>s.
llvm-svn: 205641
2014-04-04 18:21:51 +00:00
Rui Ueyama fb7936d07c Fix indentation.
llvm-svn: 205639
2014-04-04 18:12:27 +00:00
Rui Ueyama fbd6c44e6a Revert "temporary commit."
This reverts commit r205635 that was submitted by mistake.

llvm-svn: 205637
2014-04-04 18:06:56 +00:00
Rui Ueyama 770305804f temporary commit.
llvm-svn: 205635
2014-04-04 18:01:52 +00:00
Rui Ueyama 992fdc0785 SymbolTable::size() returns an unsigned int.
It's better to use the same type rather than a fixed width integer type
that may be different from the return type.

llvm-svn: 205597
2014-04-04 01:22:51 +00:00
Rui Ueyama 7cac0f784c Use range-based for loop. No functionality change.
llvm-svn: 205594
2014-04-04 00:59:50 +00:00
Rui Ueyama 0b8e053ebd Do not use temporary variables to pass them to forEachUndefines.
So that it's obvious that we pass these callbacks only to forEachUndefines.

llvm-svn: 205593
2014-04-04 00:39:37 +00:00
Rui Ueyama 8dc9f0a371 Return a vector rather than mutating a given one.
This is cleaner and as efficient as before.

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

llvm-svn: 205590
2014-04-04 00:15:52 +00:00
Rui Ueyama 8bd093b1e5 Rename getInputGraph() and getNextFile().
Seems getSomething() is more common naming scheme than just a noun
to get something, so renaming these members.

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

llvm-svn: 205589
2014-04-04 00:14:04 +00:00